Documentation ¶
Index ¶
- type ComparisonFunc
- type IterCallbackFunc
- type IterChCloser
- type IterChParams
- type Record
- type SortedMap
- func (sm *SortedMap[K, V]) BatchDelete(keys []K) []bool
- func (sm *SortedMap[K, V]) BatchGet(keys []K) ([]V, []bool)
- func (sm *SortedMap[K, V]) BatchHas(keys []K) []bool
- func (sm *SortedMap[K, V]) BatchInsert(recs []Record[K, V]) []bool
- func (sm *SortedMap[K, V]) BatchInsertMap(v map[K]V) error
- func (sm *SortedMap[K, V]) BatchReplace(recs []Record[K, V])
- func (sm *SortedMap[K, V]) BatchReplaceMap(v map[K]V) error
- func (sm *SortedMap[K, V]) BoundedDelete(lowerBound, upperBound V) error
- func (sm *SortedMap[K, V]) BoundedIterCh(reversed bool, lowerBound, upperBound V) (IterChCloser[K, V], error)
- func (sm *SortedMap[K, V]) BoundedIterFunc(reversed bool, lowerBound, upperBound V, f IterCallbackFunc[K, V]) error
- func (sm *SortedMap[K, V]) BoundedKeys(lowerBound, upperBound V) ([]K, error)
- func (sm *SortedMap[K, V]) CustomIterCh(params IterChParams[V]) (IterChCloser[K, V], error)
- func (sm *SortedMap[K, V]) Delete(key K) bool
- func (sm *SortedMap[K, V]) Get(key K) (V, bool)
- func (sm *SortedMap[K, V]) Has(key K) bool
- func (sm *SortedMap[K, V]) Insert(key K, val V) bool
- func (sm *SortedMap[K, V]) IterCh() (IterChCloser[K, V], error)
- func (sm *SortedMap[K, V]) IterFunc(reversed bool, f IterCallbackFunc[K, V])
- func (sm *SortedMap[K, V]) Keys() []K
- func (sm *SortedMap[K, V]) Len() int
- func (sm *SortedMap[K, V]) Map() map[K]V
- func (m *SortedMap[K, V]) MarshalJSON() ([]byte, error)
- func (sm *SortedMap[K, V]) Replace(key K, val V)
- func (m *SortedMap[K, V]) SetComparisonFunc(cmpFn ComparisonFunc[V])
- func (m *SortedMap[K, V]) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ComparisonFunc ¶
ComparisonFunc defines the type of the comparison function for the chosen value type.
type IterCallbackFunc ¶
type IterCallbackFunc[K comparable, V any] func(rec Record[K, V]) bool
IterCallbackFunc defines the type of function that is passed into an IterFunc method. The function is passed a record value argument.
type IterChCloser ¶
type IterChCloser[K comparable, V any] struct { // contains filtered or unexported fields }
IterChCloser allows records to be read through a channel that is returned by the Records method. IterChCloser values should be closed after use using the Close method.
func (*IterChCloser[K, V]) Close ¶
func (iterCh *IterChCloser[K, V]) Close() error
Close cancels a channel-based iteration and causes the sending goroutine to exit. Close should be used after an IterChCloser is finished being read from.
func (*IterChCloser[K, V]) Records ¶
func (iterCh *IterChCloser[K, V]) Records() <-chan Record[K, V]
Records returns a channel that records can be read from.
type IterChParams ¶
type IterChParams[V any] struct { Reversed bool SendTimeout time.Duration BufSize int LowerBound, UpperBound V }
IterChParams contains configurable settings for CustomIterCh. SendTimeout is disabled by default, though it should be set to allow channel send goroutines to time-out. BufSize is set to 1 if its field is set to a lower value. LowerBound and UpperBound default to regular iteration when left unset.
type Record ¶
type Record[K comparable, V any] struct { Key K Val V }
Record defines a type used in batching and iterations, where keys and values are used together.
type SortedMap ¶
type SortedMap[K comparable, V any] struct { // contains filtered or unexported fields }
SortedMap contains a map, a slice, and references to one or more comparison functions. SortedMap is not concurrency-safe, though it can be easily wrapped by a developer-defined type.
func New ¶
func New[K comparable, V any](n int, cmpFn ComparisonFunc[V]) *SortedMap[K, V]
New creates and initializes a new SortedMap structure and then returns a reference to it. New SortedMaps are created with a backing map/slice of length/capacity n.
func (*SortedMap[K, V]) BatchDelete ¶
BatchDelete removes values from the collection, using the given keys, returning a slice of the results.
func (*SortedMap[K, V]) BatchGet ¶
BatchGet retrieves values with their read statuses from the collection, using the given keys.
func (*SortedMap[K, V]) BatchHas ¶
BatchHas checks if the keys exist in the collection and returns a slice containing the results.
func (*SortedMap[K, V]) BatchInsert ¶
BatchInsert adds all given records to the collection and returns a slice containing each record's insert status. If a key already exists, the value will not be inserted. Use BatchReplace for the alternative functionality.
func (*SortedMap[K, V]) BatchInsertMap ¶
BatchInsertMap adds all map keys and values to the collection. If a key already exists, the value will not be inserted and an error will be returned. Use BatchReplaceMap for the alternative functionality.
func (*SortedMap[K, V]) BatchReplace ¶
BatchReplace adds all given records to the collection. Even if a key already exists, the value will be inserted. Use BatchInsert for the alternative functionality.
func (*SortedMap[K, V]) BatchReplaceMap ¶
BatchReplaceMap adds all map keys and values to the collection. Even if a key already exists, the value will be inserted. Use BatchInsertMap for the alternative functionality.
func (*SortedMap[K, V]) BoundedDelete ¶
BoundedDelete removes values that are between the given values from the collection. BoundedDelete returns true if the operation was successful, or false otherwise.
func (*SortedMap[K, V]) BoundedIterCh ¶
func (sm *SortedMap[K, V]) BoundedIterCh(reversed bool, lowerBound, upperBound V) (IterChCloser[K, V], error)
BoundedIterCh returns a channel that sorted records can be read from and processed. BoundedIterCh starts at the lower bound value and sends all values in the collection until reaching the upper bounds value. Sort order is reversed if the reversed argument is set to true. This method defaults to the expected behavior of blocking until a channel send completes, with no timeout.
func (*SortedMap[K, V]) BoundedIterFunc ¶
func (sm *SortedMap[K, V]) BoundedIterFunc(reversed bool, lowerBound, upperBound V, f IterCallbackFunc[K, V]) error
BoundedIterFunc starts at the lower bound value and passes all values in the collection to the callback function until reaching the upper bounds value. Sort order is reversed if the reversed argument is set to true.
func (*SortedMap[K, V]) BoundedKeys ¶
BoundedKeys returns a slice containing sorted keys equal to or between the given bounds. The returned slice is valid until the next modification to the SortedMap structure.
func (*SortedMap[K, V]) CustomIterCh ¶
func (sm *SortedMap[K, V]) CustomIterCh(params IterChParams[V]) (IterChCloser[K, V], error)
CustomIterCh returns a channel that sorted records can be read from and processed. CustomIterCh starts at the lower bound value and sends all values in the collection until reaching the upper bounds value. Sort order is reversed if the reversed argument is set to true. This method defaults to the expected behavior of blocking until a channel send completes, with no timeout.
func (*SortedMap[K, V]) Delete ¶
Delete removes a value from the collection, using the given key. Because the index position of each sorted key changes on each insert and a simpler structure was ideal, deletes can have a worse-case complexity of O(n), meaning the goroutine must loop through the sorted slice to find and delete the given key.
func (*SortedMap[K, V]) Insert ¶
Insert uses the provided 'less than' function to insert sort and add the value to the collection and returns a value containing the record's insert status. If the key already exists, the value will not be inserted. Use Replace for the alternative functionality.
func (*SortedMap[K, V]) IterCh ¶
func (sm *SortedMap[K, V]) IterCh() (IterChCloser[K, V], error)
IterCh returns a channel that sorted records can be read from and processed. This method defaults to the expected behavior of blocking until a read, with no timeout.
func (*SortedMap[K, V]) IterFunc ¶
func (sm *SortedMap[K, V]) IterFunc(reversed bool, f IterCallbackFunc[K, V])
IterFunc passes each record to the specified callback function. Sort order is reversed if the reversed argument is set to true.
func (*SortedMap[K, V]) Keys ¶
func (sm *SortedMap[K, V]) Keys() []K
Keys returns a slice containing sorted keys. The returned slice is valid until the next modification to the SortedMap structure.
func (*SortedMap[K, V]) Map ¶
func (sm *SortedMap[K, V]) Map() map[K]V
Map returns a map containing keys mapped to values. The returned map is valid until the next modification to the SortedMap structure. The map can be used with ether the Keys or BoundedKeys methods to select a range of items and iterate over them using a slice for-range loop, rather than a channel for-range loop.
func (*SortedMap[K, V]) MarshalJSON ¶ added in v1.0.1
func (*SortedMap[K, V]) Replace ¶
func (sm *SortedMap[K, V]) Replace(key K, val V)
Replace uses the provided 'less than' function to insert sort. Even if the key already exists, the value will be inserted. Use Insert for the alternative functionality.
func (*SortedMap[K, V]) SetComparisonFunc ¶ added in v1.0.1
func (m *SortedMap[K, V]) SetComparisonFunc(cmpFn ComparisonFunc[V])