Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Container ¶
type Container[T any] interface { fmt.Stringer // IsEmpty will return true when container has no element IsEmpty() bool // Size will return the number of elements in the container Size() int // Clear the elements inside the container Clear() // Values will return the collection of all element values in the container Values() []T }
Container is the base feature provided by all data structures
type Enumerator ¶
type Enumerator[T comparable, U any] interface { // Each calls the given function once for each element and passing that // element's index(or key) and value // // Enter the next loop when it returns true // Break loop when it returns false Each(func(T, U) bool) // Any calls the given function once for each element // // Return true if the given function returns true once // Return false if the given function always returns false for all elements Any(func(T, U) bool) bool // All calls the given function once for each element // // Return true if the given function always returns true for all elements // Return false if the given function returns false once All(func(T, U) bool) bool // First calls the given function once for each element // // Return [index(or key), value, true] when the given function return true // for the first time Find(func(T, U) bool) (T, U, bool) // Select calls the given function once for each element // // It will return all elements for which the given function returns true Select(func(T, U) bool) []U }
Enumerator provides enumerable functions for the containers
type Heap ¶
type Heap[T constraints.Ordered] interface { // Add an elemnt the to Heap Add(element T) // Get the top Element of the heap without removing it Peek() (T, error) // Pop out the top element of the heap Poll() (T, error) // Get the index of the parent of given node GetParentIndex(child int) int // Get the index of the left child of the given node GetLeftChildIndex(parent int) int // Get the index of the right child of the given node GetRightChildIndex(parent int) int // Get the left child of a node LeftChild(parent int) T // Get the right child of a node RightChild(parent int) T // Get the parent node of a node Parent(child int) T // Check if the given node has a left child HasLeftChild(parent int) bool // Check if the given node has a right child HasRightChild(parent int) bool // Check if the given node has a parent HasParent(child int) bool // Container is the base feature provided by all data structures Container[T] }
Heap is the base feature provided by all heap structures
In computer science, a heap is a specialized tree-based data structure which is essentially an almost complete binary tree that satisfies the heap property. in a max heap, for any given node C, if P is a parent node of C, then the key (the value) of P is greater than or equal to the key of C. In a min heap, the key of P is less than or equal to the key of C. The node at the "top" of the heap (with no parents) is called the root node.
Reference: https://en.wikipedia.org/wiki/Heap_(data_structure)
type List ¶
type List[T any] interface { // Get element value by index Get(index int) (T, bool) // Contains all the given values Contains(values ...T) bool // IndexOf the value IndexOf(value T) int // Remove element by index Remove(index int) // SortBy custom method SortBy(less func(i, j T) bool) // Append value to list Append(values ...T) // Insert values from index position Insert(index int, values ...T) // Set will override the value at the index position Set(index int, value T) // Container is the base feature provided by all data structures Container[T] // Enumerator provides enumerator functions for the containers Enumerator[int, T] }
List is the base feature provided by all list structures Reference: https://en.wikipedia.org/wiki/List_%28abstract_data_type%29
type Map ¶
type Map[K comparable, V any] interface { // Put the key and the value Put(k K, v V) // Get value by key Get(k K) (V, bool) // Delete value by ke Delete(k K) // Contains all given keys Contains(keys ...K) bool // Keys return all keys in the map Keys() []K // Container is the base feature provided by all data structures Container[V] // Enumerator provides enumerator functions for the containers Enumerator[K, V] }
Map is the base feature provided by all map structures
In computer science, an associative array, map, symbol table, or dictionary is an abstract data type composed of a collection of (key, value) pairs, such that each possible key appears just once in the collection.
Reference: https://en.wikipedia.org/wiki/Map_(higher-order_function)
type Set ¶
type Set[T comparable] interface { // Add all given elements into the set Add(elements ...T) // Remove all given elements from the set Remove(elements ...T) // Contains all given elements Contains(elements ...T) bool // Union returns the union of two sets. // All elements of the new set exist in the current set or exist in the target set. // Reference: https://en.wikipedia.org/wiki/Union_(set_theory) Union(target Set[T]) Set[T] // Intersection returns the intersection between two sets. // All elements of the new set exist in both current set and target set. // Reference: https://en.wikipedia.org/wiki/Intersection_(set_theory) Intersection(target Set[T]) Set[T] // Difference returns the difference between two sets. // All elements of the new set exist in the current set but not in the target set. // Reference: https://proofwiki.org/wiki/Definition:Set_Difference Difference(target Set[T]) Set[T] // Container is the base feature provided by all data structures Container[T] }
Set is the base feature provided by all set structures Reference: https://en.wikipedia.org/wiki/Set_%28abstract_data_type%29