Documentation ¶
Overview ¶
Package doublylinkedlist implements the doubly-linked list.
Structure is not thread safe.
Reference: https://en.wikipedia.org/wiki/List_%28abstract_data_type%29
Package containers provides core interfaces and functions for data structures.
Container is the base interface for all data structures to implement.
Iterators provide stateful iterators.
Enumerable provides Ruby inspired (each, select, map, find, any?, etc.) container functions.
Serialization provides serializers (marshalers) and deserializers (unmarshalers).
Package lists provides an abstract List interface.
In computer science, a list or sequence is an abstract data type that represents an ordered sequence of values, where the same value may occur more than once. An instance of a list is a computer representation of the mathematical concept of a finite sequence; the (potentially) infinite analog of a list is a stream. Lists are a basic example of containers, as they contain other values. If the same value occurs multiple times, each occurrence is considered a distinct item.
Reference: https://en.wikipedia.org/wiki/List_%28abstract_data_type%29
Index ¶
- func ByteComparator(a, b interface{}) int
- func Float32Comparator(a, b interface{}) int
- func Float64Comparator(a, b interface{}) int
- func GetSortedValues(container Container, comparator Comparator) []*bytes.Buffer
- func Int16Comparator(a, b interface{}) int
- func Int32Comparator(a, b interface{}) int
- func Int64Comparator(a, b interface{}) int
- func Int8Comparator(a, b interface{}) int
- func IntComparator(a, b interface{}) int
- func RuneComparator(a, b interface{}) int
- func Sort(values []*bytes.Buffer, comparator Comparator)
- func StringComparator(a, b interface{}) int
- func TimeComparator(a, b interface{}) int
- func UInt16Comparator(a, b interface{}) int
- func UInt32Comparator(a, b interface{}) int
- func UInt64Comparator(a, b interface{}) int
- func UInt8Comparator(a, b interface{}) int
- func UIntComparator(a, b interface{}) int
- type BufferLinkedList
- func (list *BufferLinkedList) Add(values ...*bytes.Buffer)
- func (list *BufferLinkedList) Append(values ...*bytes.Buffer)
- func (list *BufferLinkedList) Clear()
- func (list *BufferLinkedList) Contains(values ...*bytes.Buffer) bool
- func (list *BufferLinkedList) Empty() bool
- func (list *BufferLinkedList) Get(index int) (*bytes.Buffer, bool)
- func (list *BufferLinkedList) Insert(index int, values ...*bytes.Buffer)
- func (list *BufferLinkedList) Prepend(values ...*bytes.Buffer)
- func (list *BufferLinkedList) Remove(index int)
- func (list *BufferLinkedList) Size() int
- func (list *BufferLinkedList) Sort(comparator Comparator)
- func (list *BufferLinkedList) String() string
- func (list *BufferLinkedList) Swap(i, j int)
- func (list *BufferLinkedList) Values() []*bytes.Buffer
- type Comparator
- type Container
- type List
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteComparator ¶
func ByteComparator(a, b interface{}) int
ByteComparator provides a basic comparison on byte
func Float32Comparator ¶
func Float32Comparator(a, b interface{}) int
Float32Comparator provides a basic comparison on float32
func Float64Comparator ¶
func Float64Comparator(a, b interface{}) int
Float64Comparator provides a basic comparison on float64
func GetSortedValues ¶
func GetSortedValues(container Container, comparator Comparator) []*bytes.Buffer
GetSortedValues returns sorted container's elements with respect to the passed comparator. Does not effect the ordering of elements within the container.
func Int16Comparator ¶
func Int16Comparator(a, b interface{}) int
Int16Comparator provides a basic comparison on int16
func Int32Comparator ¶
func Int32Comparator(a, b interface{}) int
Int32Comparator provides a basic comparison on int32
func Int64Comparator ¶
func Int64Comparator(a, b interface{}) int
Int64Comparator provides a basic comparison on int64
func Int8Comparator ¶
func Int8Comparator(a, b interface{}) int
Int8Comparator provides a basic comparison on int8
func IntComparator ¶
func IntComparator(a, b interface{}) int
IntComparator provides a basic comparison on int
func RuneComparator ¶
func RuneComparator(a, b interface{}) int
RuneComparator provides a basic comparison on rune
func Sort ¶
func Sort(values []*bytes.Buffer, comparator Comparator)
Sort sorts values (in-place) with respect to the given comparator.
Uses Go's sort (hybrid of quicksort for large and then insertion sort for smaller slices).
func StringComparator ¶
func StringComparator(a, b interface{}) int
StringComparator provides a fast comparison on strings
func TimeComparator ¶
func TimeComparator(a, b interface{}) int
TimeComparator provides a basic comparison on time.Time
func UInt16Comparator ¶
func UInt16Comparator(a, b interface{}) int
UInt16Comparator provides a basic comparison on uint16
func UInt32Comparator ¶
func UInt32Comparator(a, b interface{}) int
UInt32Comparator provides a basic comparison on uint32
func UInt64Comparator ¶
func UInt64Comparator(a, b interface{}) int
UInt64Comparator provides a basic comparison on uint64
Types ¶
type BufferLinkedList ¶
type BufferLinkedList struct {
// contains filtered or unexported fields
}
BufferLinkedList holds the elements, where each element points to the next and previous element
func NewBufferLinkedList ¶
func NewBufferLinkedList() *BufferLinkedList
New instantiates a new empty list
func (*BufferLinkedList) Add ¶
func (list *BufferLinkedList) Add(values ...*bytes.Buffer)
Add appends a value (one or more) at the end of the list (same as Append())
func (*BufferLinkedList) Append ¶
func (list *BufferLinkedList) Append(values ...*bytes.Buffer)
Append appends a value (one or more) at the end of the list (same as Add())
func (*BufferLinkedList) Clear ¶
func (list *BufferLinkedList) Clear()
Clear removes all elements from the list.
func (*BufferLinkedList) Contains ¶
func (list *BufferLinkedList) Contains(values ...*bytes.Buffer) bool
Contains check if values (one or more) are present in the set. All values have to be present in the set for the method to return true. Performance time complexity of n^2. Returns true if no arguments are passed at all, i.e. set is always super-set of empty set.
func (*BufferLinkedList) Empty ¶
func (list *BufferLinkedList) Empty() bool
Empty returns true if list does not contain any elements.
func (*BufferLinkedList) Get ¶
func (list *BufferLinkedList) Get(index int) (*bytes.Buffer, bool)
Get returns the element at index. Second return parameter is true if index is within bounds of the array and array is not empty, otherwise false.
func (*BufferLinkedList) Insert ¶
func (list *BufferLinkedList) Insert(index int, values ...*bytes.Buffer)
Insert inserts values at specified index position shifting the value at that position (if any) and any subsequent elements to the right. Does not do anything if position is negative or bigger than list's size Note: position equal to list's size is valid, i.e. append.
func (*BufferLinkedList) Prepend ¶
func (list *BufferLinkedList) Prepend(values ...*bytes.Buffer)
Prepend prepends a values (or more)
func (*BufferLinkedList) Remove ¶
func (list *BufferLinkedList) Remove(index int)
Remove removes one or more elements from the list with the supplied indices.
func (*BufferLinkedList) Size ¶
func (list *BufferLinkedList) Size() int
Size returns number of elements within the list.
func (*BufferLinkedList) Sort ¶
func (list *BufferLinkedList) Sort(comparator Comparator)
Sort sorts values (in-place) using.
func (*BufferLinkedList) String ¶
func (list *BufferLinkedList) String() string
String returns a string representation of container
func (*BufferLinkedList) Swap ¶
func (list *BufferLinkedList) Swap(i, j int)
Swap swaps values of two elements at the given indices.
func (*BufferLinkedList) Values ¶
func (list *BufferLinkedList) Values() []*bytes.Buffer
Values returns all elements in the list.
type Comparator ¶
type Comparator func(a, b interface{}) int
Comparator will make type assertion (see IntComparator for example), which will panic if a or b are not of the asserted type.
Should return a number:
negative , if a < b zero , if a == b positive , if a > b
type Container ¶
Container is base interface that all data structures implement.
type List ¶
type List interface { Get(index int) (*bytes.Buffer, bool) Remove(index int) Add(values ...*bytes.Buffer) Contains(values ...*bytes.Buffer) bool Sort(comparator Comparator) Swap(index1, index2 int) Insert(index int, values ...*bytes.Buffer) Container }
List interface that all lists implement