From c30e7f5f99f9ad4d9552b645d7b89d7385972f99 Mon Sep 17 00:00:00 2001 From: stefan Date: Mon, 22 May 2023 20:08:09 -0400 Subject: stack --- node/stack.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 node/stack.go (limited to 'node/stack.go') diff --git a/node/stack.go b/node/stack.go new file mode 100644 index 0000000..a5460a7 --- /dev/null +++ b/node/stack.go @@ -0,0 +1,32 @@ +package main + +import ( + "log" + + "github.com/holiman/uint256" +) + +const STACK_CAP = (1 << 10) + +type Stack []uint256.Int + +func NewStack() *Stack { + return &Stack{} +} + +func (s *Stack) Push(x *uint256.Int) { + *s = append(*s, *x) + if len(*s) > STACK_CAP { + log.Fatal("stack overflow") + } +} + +func (s *Stack) Pop() *uint256.Int { + if len(*s) <= 0 { + log.Fatal("stack underflow") + } + + r := (*s)[len(*s)-1] + *s = (*s)[:len(*s)-1] + return &r +} -- cgit v1.2.3