Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.

Commit

Permalink
internal/stack: New package.
Browse files Browse the repository at this point in the history
stack implements a growable uint64 stack
  • Loading branch information
vibhavp authored and sbinet committed Aug 9, 2017
1 parent 13e8846 commit 08b2344
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions internal/stack/stack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2017 The go-interpreter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// Package stack implements a growable uint64 stack
package stack

type Stack struct {
slice []uint64
}

func (s *Stack) Push(b uint64) {
s.slice = append(s.slice, b)
}

func (s *Stack) Pop() uint64 {
v := s.Top()
s.slice = s.slice[:len(s.slice)-1]
return v
}

func (s *Stack) SetTop(v uint64) {
s.slice[len(s.slice)-1] = v
}

func (s *Stack) Top() uint64 {
return s.slice[len(s.slice)-1]
}

func (s *Stack) Get(i int) uint64 {
return s.slice[i]
}

func (s *Stack) Set(i int, v uint64) {
s.slice[i] = v
}

func (s *Stack) Len() int {
return len(s.slice)
}

0 comments on commit 08b2344

Please sign in to comment.