Documentation
¶
Overview ¶
Package inmemory provides in-memory implementations of selected SOP backends, primarily for tests and lightweight scenarios.
Index ¶
- type BtreeInterface
- func (b3 BtreeInterface[TK, TV]) Add(key TK, value TV) bool
- func (b3 BtreeInterface[TK, TV]) AddIfNotExist(key TK, value TV) bool
- func (b3 BtreeInterface[TK, TV]) All() iter.Seq2[TK, TV]
- func (b3 BtreeInterface[TK, TV]) AllDesc() iter.Seq2[TK, TV]
- func (b3 BtreeInterface[TK, TV]) Count() int
- func (b3 BtreeInterface[TK, TV]) Find(key TK, firstItemWithKey bool) bool
- func (b3 BtreeInterface[TK, TV]) FindInDescendingOrder(key TK) bool
- func (b3 BtreeInterface[TK, TV]) First() bool
- func (b3 BtreeInterface[TK, TV]) GetCurrentKey() TK
- func (b3 BtreeInterface[TK, TV]) GetCurrentValue() TV
- func (b3 BtreeInterface[TK, TV]) Last() bool
- func (b3 BtreeInterface[TK, TV]) Next() bool
- func (b3 BtreeInterface[TK, TV]) Previous() bool
- func (b3 BtreeInterface[TK, TV]) Range(from, to TK) iter.Seq2[TK, TV]
- func (b3 BtreeInterface[TK, TV]) RangeDesc(from, to TK) iter.Seq2[TK, TV]
- func (b3 BtreeInterface[TK, TV]) Remove(key TK) bool
- func (b3 BtreeInterface[TK, TV]) RemoveCurrentItem() bool
- func (b3 BtreeInterface[TK, TV]) Update(key TK, value TV) bool
- func (b3 BtreeInterface[TK, TV]) UpdateCurrentKey(key TK) bool
- func (b3 BtreeInterface[TK, TV]) UpdateCurrentValue(newValue TV) bool
- func (b3 BtreeInterface[TK, TV]) Upsert(key TK, value TV) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BtreeInterface ¶
type BtreeInterface[TK btree.Ordered, TV any] struct { // Inherit from Btree. *btree.Btree[TK, TV] }
BtreeInterface struct defines publicly callable methods of Btree in-memory. NOTE: this is synonymous to the btree.BtreeInterface but with methods removed of error in return. Because in-memory will not produce any error during access, thus, it can be simplified so code will not need to bother with the 2nd (error) return.
func NewBtree ¶
func NewBtree[TK btree.Ordered, TV any](isUnique bool) BtreeInterface[TK, TV]
NewBtree will create an in-memory B-Tree & its required data stores. You can use it to store and access key/value pairs similar to a map but which, sorts items & allows "range queries".
func (BtreeInterface[TK, TV]) Add ¶
func (b3 BtreeInterface[TK, TV]) Add(key TK, value TV) bool
Add adds an item to the b-tree and does not check for duplicates.
func (BtreeInterface[TK, TV]) AddIfNotExist ¶
func (b3 BtreeInterface[TK, TV]) AddIfNotExist(key TK, value TV) bool
AddIfNotExist adds an item if there is no item matching the key yet. Otherwise, it will do nothing and return false, for not adding the item. This is useful for cases one wants to add an item without creating a duplicate entry.
func (BtreeInterface[TK, TV]) All ¶
func (b3 BtreeInterface[TK, TV]) All() iter.Seq2[TK, TV]
All returns an iterator over every key/value pair in ascending key order, usable with Go's range-over-func:
for k, v := range b3.All() {
...
}
It drives the B-Tree cursor, so avoid interleaving it with manual First/Next/Previous navigation on the same tree.
func (BtreeInterface[TK, TV]) AllDesc ¶
func (b3 BtreeInterface[TK, TV]) AllDesc() iter.Seq2[TK, TV]
AllDesc returns an iterator over every key/value pair in descending key order. Like All, it drives the B-Tree cursor, so avoid interleaving it with manual First/Next/Previous navigation on the same tree.
func (BtreeInterface[TK, TV]) Count ¶
func (b3 BtreeInterface[TK, TV]) Count() int
Returns the Count of items in the B-Tree.
func (BtreeInterface[TK, TV]) Find ¶
func (b3 BtreeInterface[TK, TV]) Find(key TK, firstItemWithKey bool) bool
FindOne will search Btree for an item with a given key. Return true if found, otherwise false. firstItemWithKey is useful when there are items with same key. true will position pointer to the first item with the given key, according to key ordering sequence.
func (BtreeInterface[TK, TV]) FindInDescendingOrder ¶
func (b3 BtreeInterface[TK, TV]) FindInDescendingOrder(key TK) bool
FindInDescendingOrder is analogous to Find but is useful when doing search item and retrieval will be in descending order. Use Previous to navigate backwards.
func (BtreeInterface[TK, TV]) First ¶
func (b3 BtreeInterface[TK, TV]) First() bool
First positions the "cursor" to the first item as per key ordering.
func (BtreeInterface[TK, TV]) GetCurrentKey ¶
func (b3 BtreeInterface[TK, TV]) GetCurrentKey() TK
GetCurrentKey returns the current item's value.
func (BtreeInterface[TK, TV]) GetCurrentValue ¶
func (b3 BtreeInterface[TK, TV]) GetCurrentValue() TV
GetCurrentValue returns the current item's value.
func (BtreeInterface[TK, TV]) Last ¶
func (b3 BtreeInterface[TK, TV]) Last() bool
Last positionts the "cursor" to the last item as per key ordering.
func (BtreeInterface[TK, TV]) Next ¶
func (b3 BtreeInterface[TK, TV]) Next() bool
Next positions the "cursor" to the next item as per key ordering.
func (BtreeInterface[TK, TV]) Previous ¶
func (b3 BtreeInterface[TK, TV]) Previous() bool
Previous positions the "cursor" to the previous item as per key ordering.
func (BtreeInterface[TK, TV]) Range ¶
func (b3 BtreeInterface[TK, TV]) Range(from, to TK) iter.Seq2[TK, TV]
Range returns an iterator over pairs whose keys fall within from..to inclusive, in ascending key order. It seeks straight to the start of the range using the tree's search, so cost is proportional to the range size, not the tree size. Like All, it drives the B-Tree cursor.
func (BtreeInterface[TK, TV]) RangeDesc ¶
func (b3 BtreeInterface[TK, TV]) RangeDesc(from, to TK) iter.Seq2[TK, TV]
RangeDesc returns an iterator over pairs whose keys fall within to..from inclusive, in descending key order: from is the high bound where iteration starts, to is the low bound where it stops. It seeks straight to the start of the range, so cost is proportional to the range size, not the tree size. Like All, it drives the B-Tree cursor.
func (BtreeInterface[TK, TV]) Remove ¶
func (b3 BtreeInterface[TK, TV]) Remove(key TK) bool
Remove will find the item with a given key then remove that item.
func (BtreeInterface[TK, TV]) RemoveCurrentItem ¶
func (b3 BtreeInterface[TK, TV]) RemoveCurrentItem() bool
RemoveCurrentItem will remove the current key/value pair from the store.
func (BtreeInterface[TK, TV]) Update ¶
func (b3 BtreeInterface[TK, TV]) Update(key TK, value TV) bool
Update finds the item with key and update its value to the value argument.
func (BtreeInterface[TK, TV]) UpdateCurrentKey ¶
func (b3 BtreeInterface[TK, TV]) UpdateCurrentKey(key TK) bool
UpdateCurrentKey will update the current item's key.
func (BtreeInterface[TK, TV]) UpdateCurrentValue ¶
func (b3 BtreeInterface[TK, TV]) UpdateCurrentValue(newValue TV) bool
UpdateCurrentValue will update the Value of the current item. Key is read-only, thus, no argument for the key.
func (BtreeInterface[TK, TV]) Upsert ¶
func (b3 BtreeInterface[TK, TV]) Upsert(key TK, value TV) bool
Upsert will add the item if not found or update it if it exists.