Skip to content

Latest commit

 

History

History
executable file
·
1844 lines (1225 loc) · 57.1 KB

generated_doc.md

File metadata and controls

executable file
·
1844 lines (1225 loc) · 57.1 KB

stl4go

import "github.com/chen3feng/stl4go"

Package stl4go is a generic container and algorithm library for go.

Index

func AllOf

func AllOf[T any](a []T, pred func(T) bool) bool

AllOf return true if pred(e) returns true for all emements e in a.

Complexity: O(len(a)).

func AnyOf

func AnyOf[T any](a []T, pred func(T) bool) bool

AnyOf return true if pred(e) returns true for any emements e in a.

Complexity: O(len(a)).

func Average

func Average[T Numeric](a []T) T

Average returns the average value of a.

func AverageAs[R, T Numeric](a []T) R

AverageAs returns the average value of a as type R.

func BinarySearch[T Ordered](a []T, value T) (index int, ok bool)

BinarySearch returns the (index, true) to the first element in the ascending ordered slice a such that element == value, or (-1, false) if no such element is found.

Complexity: O(log(len(a))).

func BinarySearchFunc[T any](a []T, value T, less LessFn[T]) (index int, ok bool)

BinarySearchFunc returns the (index, true) to the first element in the ordered slice a such that less(element, value) and less(value, element) are both false, or (-1, false) if no such element is found.

The elements in the slice a should sorted according with compare func less.

Complexity: O(log(len(a))).

func Compare

func Compare[E Ordered](a, b []E) int

Compare compares each elements in a and b.

return 0 if they are equals, return 1 if a > b, return -1 if a < b.

Complexity: O(min(len(a), len(b))).

func Copy

func Copy[T any](a []T) []T

Copy make a copy of slice a.

Complexity: O(len(a)).

func Count

func Count[T comparable](a []T, x T) int

Count returns the number of elements in the slice equals to x.

Complexity: O(len(a)).

func CountIf

func CountIf[T comparable](a []T, pred func(T) bool) int

CountIf returns the number of elements in the slice which pred returns true.

Complexity: O(len(a)).

func DescSort[T Ordered](a []T)

DescSort sorts data in descending order. The order of equal elements is not guaranteed to be preserved.

Complexity: O(N*log(N)), N=len(a).

func DescStableSort[T Ordered](a []T)

DescStableSort sorts data in descending order stably. The order of equivalent elements is guaranteed to be preserved.

Complexity: O(N*log(N)), N=len(a).

func Equal

func Equal[T comparable](a, b []T) bool

Equal returns whether two slices are equal. Return true if they are the same length and all elements are equal.

Complexity: O(min(len(a), len(b))).

func Find

func Find[T comparable](a []T, x T) (index int, ok bool)

Find find the first value x in the given slice a linearly. return (index, true) if found, return (_, false) if not found.

Complexity: O(len(a)).

func FindIf

func FindIf[T any](a []T, cond func(T) bool) (index int, ok bool)

FindIf find the first value x satisfying function cond in the given slice a linearly. return (index, true) if found, return (_, false) if not found.

Complexity: O(len(a)).

func Generate[T any](a []T, gen func() T)

Generate fill each element of `a`` with `gen()`.

Complexity: O(len(a)).

func Greater

func Greater[T Ordered](a, b T) bool

Greater wraps the '>' operator for ordered types.

func Index

func Index[T comparable](a []T, x T) int

Index find the value x in the given slice a linearly.

Return index if found, -1 if not found.

Complexity: O(len(a)).

func IsDescSorted[T Ordered](a []T) bool

IsDescSorted returns whether the slice a is sorted in descending order.

Complexity: O(len(a)).

func IsHeapFunc[T any](array []T, less LessFn[T]) bool

IsHeapFunc checks whether the elements in slice array are a min heap (accord to less).

Complexity: O(len(array)).

func IsMinHeap[T Ordered](array []T) bool

IsMinHeap checks whether the elements in slice array are a min heap.

Complexity: O(len(array)).

func IsSorted[T Ordered](a []T) bool

IsSorted returns whether the slice a is sorted in ascending order.

Complexity: O(len(a)).

func Less

func Less[T Ordered](a, b T) bool

Less wraps the '<' operator for ordered types.

func LowerBound[T Ordered](a []T, value T) int

LowerBound returns an index to the first element in the ascending ordered slice a that does not satisfy element < value (i.e. greater or equal to), or len(a) if no such element is found.

Complexity: O(log(len(a))).

func LowerBoundFunc[T any](a []T, value T, less LessFn[T]) int

LowerBoundFunc returns an index to the first element in the ordered slice a that does not satisfy less(element, value)), or len(a) if no such element is found.

The elements in the slice a should sorted according with compare func less.

Complexity: O(log(len(a))).

func MakeHeapFunc[T any](array []T, less LessFn[T])

MakeHeapFunc build a min-heap on slice array with compare function less.

Complexity: O(len(array))

func MakeMinHeap[T Ordered](array []T)

MakeMinHeap build a min-heap on slice array.

Complexity: O(len(array))

func Max

func Max[T Ordered](a, b T) T

Max return the larger value between `a` and `b`.

Complexity: O(1).

func MaxN

func MaxN[T Ordered](a ...T) T

MaxN return the maximum value in the sequence `a`.

Complexity: O(len(a)).

func Min

func Min[T Ordered](a, b T) T

Min return the smaller value between `a` and `b`.

Complexity: O(1).

func MinMax

func MinMax[T Ordered](a, b T) (min, max T)

MinMax returns both min and max between a and b.

Complexity: O(1).

func MinMaxN

func MinMaxN[T Ordered](a ...T) (min, max T)

MinMaxN returns both min and max in slice a.

Complexity: O(len(a))

func MinN

func MinN[T Ordered](a ...T) T

MinN return the minimum value in the sequence `a`.

Complexity: O(len(a)).

func NoneOf

func NoneOf[T any](a []T, pred func(T) bool) bool

NoneOf return true pred(e) returns true for none emements e in a.

Complexity: O(len(a)).

func OrderedCompare[T Ordered](a, b T) int

OrderedCompare provide default CompareFn for ordered types.

func PopHeapFunc[T any](heap *[]T, less LessFn[T]) T

PopHeapFunc removes and returns the minimum (according to less) element from the heap.

Complexity: O(log n) where n = len(*heap).

func PopMinHeap[T Ordered](heap *[]T) T

PopMinHeap removes and returns the minimum element from the heap.

Complexity: O(log n) where n = len(*heap).

func PushHeapFunc[T any](heap *[]T, v T, less LessFn[T])

PushHeapFunc pushes a element v into the heap.

Complexity: O(log(len(*heap))).

func PushMinHeap[T Ordered](heap *[]T, v T)

PushMinHeap pushes a element v into the min heap.

Complexity: O(log(len(*heap))).

func Range

func Range[T Numeric](first, last T) []T

Range make a []T filled with values in the `[first, last)` sequence. NOTE: the last is not included in the result.

Complexity: O(last-first).

func Remove

func Remove[T comparable](a []T, x T) []T

Remove remove the elements which equals to x from the input slice. return the processed slice, and the content of the input slice is also changed.

Complexity: O(len(a)).

func RemoveCopy[T comparable](a []T, x T) []T

RemoveCopy remove all elements which equals to x from the input slice. return the processed slice, and the content of the input slice is also changed.

Complexity: O(len(a)).

func RemoveHeapFunc[T any](heap *[]T, i int, less LessFn[T]) T

RemoveHeapFunc removes and returns the element at index i from the heap.

Complexity: is O(log(n)) where n = len(*heap).

func RemoveIf[T any](a []T, cond func(T) bool) []T

RemoveIf remove each element which make cond(x) returns true from the input slice, copy other elements to a new slice and return it. The input slice is kept unchanged.

Complexity: O(len(a)).

func RemoveIfCopy[T any](a []T, cond func(T) bool) []T

RemoveIfCopy drops each element which make cond(x) returns true from the input slice, copy other elements to a new slice and return it. The input slice is kept unchanged.

Complexity: O(len(a)).

func RemoveMinHeap[T Ordered](heap *[]T, i int) T

RemoveMinHeap removes and returns the element at index i from the min heap.

Complexity: is O(log(n)) where n = len(*heap).

func Reverse

func Reverse[T any](a []T)

Reverse reverses the order of the elements in the slice a.

Complexity: O(len(a)).

func ReverseCopy[T any](a []T) []T

ReverseCopy returns a reversed copy of slice a.

Complexity: O(len(a)).

func Shuffle

func Shuffle[T any](a []T)

Shuffle pseudo-randomizes the order of elements.

Complexity: O(len(a)).

func Sort

func Sort[T Ordered](a []T)

Sort sorts data in ascending order. The order of equal elements is not guaranteed to be preserved.

Complexity: O(N*log(N)), where N=len(a).

func SortFunc[T any](a []T, less func(x, y T) bool)

SortFunc sorts data in ascending order with compare func less. The order of equal elements is not guaranteed to be preserved.

Complexity: O(N*log(N)), N=len(a).

func StableSort[T Ordered](a []T)

StableSort sorts data in ascending order stably. The order of equivalent elements is guaranteed to be preserved.

Complexity: O(N*log(N)^2), where N=len(a).

func StableSortFunc[T any](a []T, less func(x, y T) bool)

StableSortFunc sorts data in ascending order with compare func less stably. The order of equivalent elements is guaranteed to be preserved.

Complexity: O(N*log(N)), N=len(a).

func Sum

func Sum[T Numeric](a []T) T

Sum summarize all elements in a. returns the result as type R, you should use SumAs if T can't hold the result. Complexity: O(len(a)).

func SumAs

func SumAs[R, T Numeric](a []T) R

SumAs summarize all elements in a. returns the result as type R, this is useful when T is too small to hold the result. Complexity: O(len(a)).

func Transform[T any](a []T, op func(T) T)

Transform applies the function op to each element in slice a and set it back to the same place in a.

Complexity: O(len(a)).

func TransformCopy[R any, T any](a []T, op func(T) R) []R

TransformCopy applies the function op to each element in slice a and return all the result as a slice.

Complexity: O(len(a)).

func TransformTo[R any, T any](a []T, op func(T) R, b []R)

TransformTo applies the function op to each element in slice a and fill it to slice b.

The len(b) must not lesser than len(a).

Complexity: O(len(a)).

func Unique

func Unique[T comparable](a []T) []T

Unique remove adjacent repeated elements from the input slice. return the processed slice, and the content of the input slice is also changed.

Complexity: O(len(a)).

func UniqueCopy[T comparable](a []T) []T

UniqueCopy remove adjacent repeated elements from the input slice. return the result slice, and the input slice is kept unchanged.

Complexity: O(len(a)).

func UpperBound[T Ordered](a []T, value T) int

UpperBound returns an index to the first element in the ascending ordered slice a such that value < element (i.e. strictly greater), or len(a) if no such element is found.

Complexity: O(log(len(a))).

func UpperBoundFunc[T any](a []T, value T, less LessFn[T]) int

UpperBoundFunc returns an index to the first element in the ordered slice a such that less(value, element)) is true (i.e. strictly greater), or len(a) if no such element is found.

The elements in the slice a should sorted according with compare func less.

Complexity: O(log(len(a))).

BuiltinSet is an associative container that contains a unordered set of unique objects of type K.

type BuiltinSet[K comparable] map[K]struct{}
func MakeBuiltinSetOf[K comparable](ks ...K) BuiltinSet[K]

MakeBuiltinSetOf creates a new BuiltinSet object with the initial content from ks.

func (*BuiltinSet[K]) Clear

func (s *BuiltinSet[K]) Clear()

Clear implements the Container interface.

func (BuiltinSet[K]) ForEach

func (s BuiltinSet[K]) ForEach(cb func(k K))

ForEach implements the Set interface.

func (BuiltinSet[K]) ForEachIf

func (s BuiltinSet[K]) ForEachIf(cb func(k K) bool)

ForEachIf implements the Container interface.

func (BuiltinSet[K]) Has

func (s BuiltinSet[K]) Has(k K) bool

Has implements the Set interface.

func (BuiltinSet[K]) Insert

func (s BuiltinSet[K]) Insert(k K)

Insert implements the Set interface.

func (BuiltinSet[K]) InsertN

func (s BuiltinSet[K]) InsertN(ks ...K)

InsertN implements the Set interface.

func (BuiltinSet[K]) IsEmpty

func (s BuiltinSet[K]) IsEmpty() bool

IsEmpty implements the Container interface.

func (BuiltinSet[K]) Keys

func (s BuiltinSet[K]) Keys() []K

Keys return a copy of all keys as a slice.

func (BuiltinSet[K]) Len

func (s BuiltinSet[K]) Len() int

Len implements the Container interface.

func (BuiltinSet[K]) Remove

func (s BuiltinSet[K]) Remove(k K) bool

Remove implements the Set interface.

func (BuiltinSet[K]) RemoveN

func (s BuiltinSet[K]) RemoveN(ks ...K)

RemoveN implements the Set interface.

func (BuiltinSet[K]) String

func (s BuiltinSet[K]) String() string

String implements the fmt.Stringer interface

CompareFn is a 3 way compare function that returns 1 if a > b, returns 0 if a == b, returns -1 if a < b.

type CompareFn[T any] func(a, b T) int

Container is a holder object that stores a collection of other objects.

type Container interface {
    IsEmpty() bool // IsEmpty checks if the container has no elements.
    Len() int      // Len returns the number of elements in the container.
    Clear()        // Clear erases all elements from the container. After this call, Len() returns zero.
}

type DList

DList is a doubly linked list.

type DList[T any] struct {
    // contains filtered or unexported fields
}
func NewDList[T any]() *DList[T]

NewDList make a new DList object

func NewDListOf[T any](vs ...T) *DList[T]

NewDListOf make a new DList from a serial of values

func (*DList[T]) Clear

func (l *DList[T]) Clear()

Clear cleanup the list

func (*DList[T]) ForEach

func (l *DList[T]) ForEach(cb func(val T))

ForEach iterate the list, apply each element to the cb callback function.

func (*DList[T]) ForEachIf

func (l *DList[T]) ForEachIf(cb func(val T) bool)

ForEachIf iterate the list, apply each element to the cb callback function, stop if cb returns false.

func (*DList[T]) ForEachMutable

func (l *DList[T]) ForEachMutable(cb func(val *T))

ForEachMutable iterate the list, apply pointer of each element to the cb callback function.

func (*DList[T]) ForEachMutableIf

func (l *DList[T]) ForEachMutableIf(cb func(val *T) bool)

ForEachMutableIf iterate the list, apply pointer of each element to the cb callback function, stop if cb returns false.

func (*DList[T]) IsEmpty

func (l *DList[T]) IsEmpty() bool

IsEmpty return whether the list is empty

func (*DList[T]) Iterate

func (l *DList[T]) Iterate() MutableIterator[T]

Iterate returns an iterator to the first element in the list.

func (*DList[T]) Len

func (l *DList[T]) Len() int

Len return the length of the list

func (*DList[T]) PopBack

func (l *DList[T]) PopBack() (T, bool)

PopBack popups a element from the back of the list.

func (*DList[T]) PopFront

func (l *DList[T]) PopFront() (T, bool)

PopFront popups a element from the front of the list.

func (*DList[T]) PushBack

func (l *DList[T]) PushBack(val T)

PushBack pushes an element at the back of the list.

func (*DList[T]) PushFront

func (l *DList[T]) PushFront(val T)

PushFront pushes an element at the front of the list.

func (*DList[T]) String

func (l *DList[T]) String() string

String convert the list to string

type Float

Float is a constraint that permits any floating-point type. If future releases of Go add new predeclared floating-point types, this constraint will be modified to include them.

type Float interface {
    // contains filtered or unexported methods
}

type HashFn

HashFn is a function that returns the hash of 't'.

type HashFn[T any] func(t T) uint64

type Integer

Integer is a constraint that permits any integer type. If future releases of Go add new predeclared integer types, this constraint will be modified to include them.

type Integer interface {
    // contains filtered or unexported methods
}

Iterator is the interface for container's iterator.

type Iterator[T any] interface {
    IsNotEnd() bool // Whether it is point to the end of the range.
    MoveToNext()    // Let it point to the next element.
    Value() T       // Return the value of current element.
}

type LessFn

LessFn is a function that returns whether 'a' is less than 'b'.

type LessFn[T any] func(a, b T) bool

type Map

Map is a associative container that contains key-value pairs with unique keys.

type Map[K any, V any] interface {
    Container
    Has(K) bool                        // Checks whether the container contains element with specific key.
    Find(K) *V                         // Finds element with specific key.
    Insert(K, V)                       // Inserts a key-value pair in to the container or replace existing value.
    Remove(K) bool                     // Remove element with specific key.
    ForEach(func(K, V))                // Iterate the container.
    ForEachIf(func(K, V) bool)         // Iterate the container, stops when the callback returns false.
    ForEachMutable(func(K, *V))        // Iterate the container, *V is mutable.
    ForEachMutableIf(func(K, *V) bool) // Iterate the container, *V is mutable, stops when the callback returns false.
}

MapIterator is the interface for map's iterator.

type MapIterator[K any, V any] interface {
    Key() K // The key of the element
    // contains filtered or unexported methods
}

MutableIterator is the interface for container's mutable iterator.

type MutableIterator[T any] interface {
    Pointer() *T // Return the pointer to the value of current element.
    // contains filtered or unexported methods
}

MutableMapIterator is the interface for map's mutable iterator.

type MutableMapIterator[K any, V any] interface {
    Key() K // The key of the element
    // contains filtered or unexported methods
}

type Numeric

Numeric is a constraint that permits any numeric type.

type Numeric interface {
    // contains filtered or unexported methods
}

type Ordered

Ordered is a constraint that permits any ordered type: any type that supports the operators < <= >= >. If future releases of Go add new ordered types, this constraint will be modified to include them.

type Ordered interface {
    // contains filtered or unexported methods
}

PriorityQueue is an queue with priority. The elements of the priority queue are ordered according to their natural ordering, or by a less function provided at construction time, depending on which constructor is used.

type PriorityQueue[T any] struct {
    // contains filtered or unexported fields
}
Example

This example inserts several ints into an IntHeap, checks the minimum, and removes them in order of priority.

{
	h := NewPriorityQueue[int]()
	h.Push(3)
	h.Push(2)
	h.Push(1)
	h.Push(5)
	fmt.Printf("minimum: %d\n", h.Top())

	for h.Len() > 0 {
		fmt.Printf("%d ", h.Pop())
	}

}

Output

minimum: 1
1 2 3 5

func NewPriorityQueue[T Ordered]() *PriorityQueue[T]

NewPriorityQueue creates an empty priority object.

func NewPriorityQueueFunc[T any](less LessFn[T]) *PriorityQueue[T]

NewPriorityQueueFunc creates an empty priority object with specified compare function less.

func NewPriorityQueueOf[T Ordered](elements ...T) *PriorityQueue[T]

NewPriorityQueueOf creates a new priority object with specified initial elements.

func NewPriorityQueueOn[T Ordered](slice []T) *PriorityQueue[T]

NewPriorityQueueOn creates a new priority object on the specified slices. The slice become a heap after the call.

func (*PriorityQueue[T]) Clear

func (pq *PriorityQueue[T]) Clear()

Clear checks whether priority queue has no elements.

func (*PriorityQueue[T]) IsEmpty

func (pq *PriorityQueue[T]) IsEmpty() bool

IsEmpty checks whether priority queue has no elements.

func (*PriorityQueue[T]) Len

func (pq *PriorityQueue[T]) Len() int

Len returns the number of elements in the priority queue.

func (*PriorityQueue[T]) Pop

func (pq *PriorityQueue[T]) Pop() T

Pop removes the top element in the priority queue.

func (*PriorityQueue[T]) Push

func (pq *PriorityQueue[T]) Push(v T)

Push pushes the given element v to the priority queue.

func (*PriorityQueue[T]) Top

func (pq *PriorityQueue[T]) Top() T

Top returns the top element in the priority queue.

type Queue

Queue is a FIFO container

type Queue[T any] struct {
    // contains filtered or unexported fields
}
func NewQueue[T any]() *Queue[T]

NewQueue create a new Queue object.

func (*Queue[T]) Clear

func (q *Queue[T]) Clear()

Clear implements the Container interface.

func (*Queue[T]) IsEmpty

func (q *Queue[T]) IsEmpty() bool

IsEmpty implements the Container interface.

func (*Queue[T]) Len

func (q *Queue[T]) Len() int

Len implements the Container interface.

func (*Queue[T]) PopBack

func (q *Queue[T]) PopBack() (T, bool)

PopBack popups an element from the back of the queue.

func (*Queue[T]) PopFront

func (q *Queue[T]) PopFront() (T, bool)

PopFront popups an element from the front of the queue.

func (*Queue[T]) PushBack

func (q *Queue[T]) PushBack(val T)

PushBack pushed an element to the back of the queue.

func (*Queue[T]) PushFront

func (q *Queue[T]) PushFront(val T)

PushFront pushed an element to the front of the queue.

func (*Queue[T]) String

func (q *Queue[T]) String() string

Len implements the fmt.Stringer interface.

type Set

Set is a containers that store unique elements.

type Set[K any] interface {
    Container
    Has(K) bool             // Checks whether the container contains element with specific key.
    Insert(K)               // Inserts a key-value pair in to the container or replace existing value.
    InsertN(...K)           // Inserts multiple key-value pairs in to the container or replace existing value.
    Remove(K) bool          // Remove element with specific key.
    RemoveN(...K)           // Remove multiple elements with specific keys.
    ForEach(func(K))        // Iterate the container.
    ForEachIf(func(K) bool) // Iterate the container, stops when the callback returns false.
}

type Signed

Signed is a constraint that permits any signed integer type. If future releases of Go add new predeclared signed integer types, this constraint will be modified to include them.

type Signed interface {
    // contains filtered or unexported methods
}

SkipList is a probabilistic data structure that seem likely to supplant balanced trees as the implementation method of choice for many applications. Skip list algorithms have the same asymptotic expected time bounds as balanced trees and are simpler, faster and use less space.

See https://en.wikipedia.org/wiki/Skip_list for more details.

type SkipList[K any, V any] struct {
    // contains filtered or unexported fields
}
func NewSkipList[K Ordered, V any]() *SkipList[K, V]

NewSkipList creates a new SkipList for Ordered key type.

func NewSkipListFromMap[K Ordered, V any](m map[K]V) *SkipList[K, V]

NewSkipListFromMap creates a new SkipList from a map.

func NewSkipListFunc[K any, V any](keyCmp CompareFn[K]) *SkipList[K, V]

NewSkipListFunc creates a new SkipList with specified compare function keyCmp.

func (*SkipList[K, V]) Clear

func (sl *SkipList[K, V]) Clear()

Clear implements the Container interface.

func (*SkipList[K, V]) Find

func (sl *SkipList[K, V]) Find(key K) *V

Find returns the value associated with the passed key if the key is in the skiplist, otherwise returns nil.

func (*SkipList[K, V]) FindRange

func (sl *SkipList[K, V]) FindRange(first, last K) MutableMapIterator[K, V]

FindRange returns an iterator in range [first, last) (last is not included).

func (*SkipList[K, V]) ForEach

func (sl *SkipList[K, V]) ForEach(op func(K, V))

ForEach implements the Map interface.

func (*SkipList[K, V]) ForEachIf

func (sl *SkipList[K, V]) ForEachIf(op func(K, V) bool)

ForEachIf implements the Map interface.

func (*SkipList[K, V]) ForEachMutable

func (sl *SkipList[K, V]) ForEachMutable(op func(K, *V))

ForEachMutable implements the Map interface.

func (*SkipList[K, V]) ForEachMutableIf

func (sl *SkipList[K, V]) ForEachMutableIf(op func(K, *V) bool)

ForEachMutableIf implements the Map interface.

func (*SkipList[K, V]) Has

func (sl *SkipList[K, V]) Has(key K) bool

Has implement the Map interface.

func (*SkipList[K, V]) Insert

func (sl *SkipList[K, V]) Insert(key K, value V)

Insert inserts a key-value pair into the skiplist. If the key is already in the skip list, it's value will be updated.

func (*SkipList[K, V]) IsEmpty

func (sl *SkipList[K, V]) IsEmpty() bool

IsEmpty implements the Container interface.

func (*SkipList[K, V]) Iterate

func (sl *SkipList[K, V]) Iterate() MutableMapIterator[K, V]

Iterate return an iterator to the skiplist.

func (*SkipList[K, V]) Len

func (sl *SkipList[K, V]) Len() int

Len implements the Container interface.

func (*SkipList[K, V]) LowerBound

func (sl *SkipList[K, V]) LowerBound(key K) MutableMapIterator[K, V]

LowerBound returns an iterator to the first element in the skiplist that does not satisfy element < value (i.e. greater or equal to), or a end iterator if no such element is found.

func (*SkipList[K, V]) Remove

func (sl *SkipList[K, V]) Remove(key K) bool

Remove removes the key-value pair associated with the passed key and returns true if the key is in the skiplist, otherwise returns false.

func (*SkipList[K, V]) UpperBound

func (sl *SkipList[K, V]) UpperBound(key K) MutableMapIterator[K, V]

UpperBound returns an iterator to the first element in the skiplist that does not satisfy value < element (i.e. strictly greater), or a end iterator if no such element is found.

type Stack

Stack s is a container adaptor that provides the functionality of a stack, a LIFO (last-in, first-out) data structure.

type Stack[T any] struct {
    // contains filtered or unexported fields
}
func NewStack[T any]() *Stack[T]

NewStack creates a new Stack object.

func NewStackCap[T any](capicity int) *Stack[T]

NewStackCap creates a new Stack object with the specified capicity.

func (*Stack[T]) Cap

func (s *Stack[T]) Cap() int

Cap returns the capacity of the stack.

func (*Stack[T]) Clear

func (s *Stack[T]) Clear()

Clear implements the Container interface.

func (*Stack[T]) IsEmpty

func (s *Stack[T]) IsEmpty() bool

IsEmpty implements the Container interface.

func (*Stack[T]) Len

func (s *Stack[T]) Len() int

Len implements the Container interface.

func (*Stack[T]) MustPop

func (s *Stack[T]) MustPop() T

MustPop popups an element from the top of the stack. It must be called whtn IsEmpty() returned false, otherwise it will panic.

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (val T, ok bool)

Pop try popup an element from the top of the stack.

func (*Stack[T]) Push

func (s *Stack[T]) Push(t T)

Push pushes the element to the top of the stack.

Unsigned is a constraint that permits any unsigned integer type. If future releases of Go add new predeclared unsigned integer types, this constraint will be modified to include them.

type Unsigned interface {
    // contains filtered or unexported methods
}

type Vector

Vector is a sequence container representing array that can change in size.

type Vector[T any] []T
func MakeVector[T any]() Vector[T]

MakeVector creates an empty Vector object.

func MakeVectorCap[T any](c int) Vector[T]

MakeVectorCap creates an empty Vector object with specified capacity.

func MakeVectorOf[T any](v ...T) Vector[T]

MakeVectorOf creates an Vector object with initial values.

func (*Vector[T]) Append

func (v *Vector[T]) Append(x ...T)

Append appends the values x... to the tail of the vector.

func (*Vector[T]) At

func (v *Vector[T]) At(i int) T

At returns the element value at the index i. You can also use the [] operator, and it's better.

func (*Vector[T]) Cap

func (v *Vector[T]) Cap() int

Cap returns the capacity of the vector.

func (*Vector[T]) Clear

func (v *Vector[T]) Clear()

Clear erases all elements from the vector. After this call, Len() returns zero. Leaves the Cap() of the vector unchanged.

func (*Vector[T]) Insert

func (v *Vector[T]) Insert(i int, x ...T)

Insert inserts the values x... into the vector at index i. After the insertion, (*v)[i] == x[0]. Insert panics if i is out of range.

Complexity: O(len(s) + len(v)).

func (*Vector[T]) IsEmpty

func (v *Vector[T]) IsEmpty() bool

IsEmpty implements the Container interface.

func (Vector[T]) Iterate

func (v Vector[T]) Iterate() MutableIterator[T]

Iterate returns an iterator to the whole vector.

func (Vector[T]) IterateRange

func (v Vector[T]) IterateRange(i, j int) MutableIterator[T]

IterateRange returns an iterator to the range [i, j) of the vector.

func (*Vector[T]) Len

func (v *Vector[T]) Len() int

Len implements the Container interface.

func (*Vector[T]) PushBack

func (v *Vector[T]) PushBack(x T)

PushBack pushs an element to the end of the vector.

func (*Vector[T]) Remove

func (v *Vector[T]) Remove(i int)

Remove removes 1 element in the vector.

Complexity: O(len(s) - i).

func (*Vector[T]) RemoveLength

func (v *Vector[T]) RemoveLength(i int, len int)

RemoveLength removes the elements in the range[i, i+len) from the vector.

func (*Vector[T]) RemoveRange

func (v *Vector[T]) RemoveRange(i, j int)

RemoveRange removes the elements in the range[i, j) from the vector.

func (*Vector[T]) Reserve

func (v *Vector[T]) Reserve(l int)

Reserve increases the capacity of the vector (the total number of elements that the vector can hold without requiring reallocation)to a value that's greater or equal to l. If l is greater than the current Cap(), new storage is allocated, otherwise the function does nothing.

Reserve() does not change the size of the vector.

func (*Vector[T]) Set

func (v *Vector[T]) Set(i int, x T)

Set sets the value of the element at the index i. You can also use the [] operator, and it's better.

func (*Vector[T]) Shrink

func (v *Vector[T]) Shrink()

Shrink removes unused capacity from the vector.

Generated by gomarkdoc