in_memory

package
v1.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BtreeInterface

type BtreeInterface[TK btree.Comparable, TV any] struct {
	// contains filtered or unexported fields
}

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.Comparable, 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]) Count added in v1.7.4

func (b3 BtreeInterface[TK, TV]) Count() int

Returns the Count of items in the B-Tree.

func (BtreeInterface[TK, TV]) FindOne

func (b3 BtreeInterface[TK, TV]) FindOne(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]) First added in v1.5.1

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 key.

func (BtreeInterface[TK, TV]) GetCurrentValue

func (b3 BtreeInterface[TK, TV]) GetCurrentValue() TV

GetCurrentValue returns the current item's value.

func (BtreeInterface[TK, TV]) IsUnique

func (b3 BtreeInterface[TK, TV]) IsUnique() bool

IsUnique returns true if B-Tree is specified to store items with Unique keys, otherwise false. Specifying uniqueness base on key makes the B-Tree permanently set. If you want just a temporary unique check during Add of an item, then you can use AddIfNotExist method for that.

func (BtreeInterface[TK, TV]) Last added in v1.5.1

func (b3 BtreeInterface[TK, TV]) Last() bool

Last positionts the "cursor" to the last item as per key ordering.

func (BtreeInterface[TK, TV]) Next added in v1.5.1

func (b3 BtreeInterface[TK, TV]) Next() bool

Next positions the "cursor" to the next item as per key ordering.

func (BtreeInterface[TK, TV]) Previous added in v1.5.1

func (b3 BtreeInterface[TK, TV]) Previous() bool

Previous positions the "cursor" to the previous item as per key ordering.

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]) UpdateCurrentItem

func (b3 BtreeInterface[TK, TV]) UpdateCurrentItem(newValue TV) bool

UpdateCurrentItem will update the Value of the current item. Key is read-only, thus, no argument for the key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL