Documentation ¶
Overview ¶
Package linear contains a series of data structures based on lists.
Stack - O(1) FILO based on linked lists, any values interface{} Queue - O(1) FIFO based on linked lists, any values interface{}
Scenario 1: Faster, but not safe for concurrency. var listNotSafe := lists.NewStack(false) //Stack,Queue
Scenario 2: If you use goroutines create one using var listSafe := lists.NewStack(true) //Stack,Queue Most common error is "stack was empty", check Stack.Empty() or ignore it in highly-concurrent funcs. Because the state may change between the HasElement() call and Pop/Peek.
Scenario 3: Manual lock the struct, 100% reability, prune to mistakes/bugs var listNotSafe := lists.NewStack(false) //Stack,Queue listNotSafe.Lock() //do stuff with the list listNotSafe.Unlock()
For more details see the README and *_test.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ListCommon ¶
ListCommon common methods for all list type based
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue FIFO list, uses Linked lists
func (*Queue) HasElement ¶
func (s *Queue) HasElement() bool
HasElement Returns true if the list is NOT empty. Use this before Pop or Peek. Opposite of IsEmpty()
func (*Queue) IsEmpty ¶
func (s *Queue) IsEmpty() bool
IsEmpty Returns true if the list is empty. Use this before Pop or Peek. Opposite of HasElement()
func (*Queue) Len ¶
func (s *Queue) Len() int
Len get the current length of the list. The complexity is O(1).
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack FILO list, uses Linked lists
func (*Stack) HasElement ¶
func (s *Stack) HasElement() bool
HasElement Returns true if the list is NOT empty. Use this before Pop or Peek. Opposite of IsEmpty()
func (*Stack) IsEmpty ¶
func (s *Stack) IsEmpty() bool
IsEmpty Returns true if the list is empty. Use this before Pop or Peek. Opposite of HasElement()
func (*Stack) Len ¶
func (s *Stack) Len() int
Len get the current length of the list. The complexity is O(1).