Skip to content

Commit

Permalink
Doc Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
markekraus committed Mar 19, 2022
1 parent d596506 commit 33672c3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/genstack.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Package genstack provides a generic FILO/LIFO stack.
package genstack

// Element is a element from the stack
// Element is a element from the Stack[T] with a value of type T.
type Element[T any] struct {
next, prev *Element[T]
stack *Stack[T]
Value T
}

// Stack is a FILO/LIFO stack of Element[T]s with values of type T.
type Stack[T any] struct {
root Element[T]
len int
Expand All @@ -31,7 +32,7 @@ func (s *Stack[T]) insert(e, at *Element[T]) *Element[T] {
return e
}

// insertValue is a convenience wrapper for insert(&Element{Value: v}, at).
// insertValue is a convenience wrapper for insert(&Element[T]{Value: v}, at).
func (s *Stack[T]) insertValue(v T, at *Element[T]) *Element[T] {
return s.insert(&Element[T]{Value: v}, at)
}
Expand All @@ -46,7 +47,7 @@ func (s *Stack[T]) remove(e *Element[T]) {
s.len--
}

// Push adds a new Element[T] e with value v at the top of Stack[T] s and returns e.
// Push adds a new Element[T] e with value v of type T at the top of Stack[T] s and returns e.
func (s *Stack[T]) Push(v T) *Element[T] {
s.lazyInit()
return s.insertValue(v, s.root.prev)
Expand All @@ -66,15 +67,15 @@ func (s *Stack[T]) Pop() *Element[T] {
// The complexity is O(1).
func (s *Stack[T]) Len() int { return s.len }

// Init initializes or clears stack s.
// Init initializes or clears Stack[T] s.
func (s *Stack[T]) Init() *Stack[T] {
s.root.next = &s.root
s.root.prev = &s.root
s.len = 0
return s
}

// New returns an initialized stack.
// New returns an initialized Stack[T].
func New[T any]() *Stack[T] {
return new(Stack[T]).Init()
}

0 comments on commit 33672c3

Please sign in to comment.