in_memory

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewBtreeWithNoWrapper

func NewBtreeWithNoWrapper[TK btree.Comparable, TV any](isUnique bool) btree.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". This will return btree instance that has no wrapper, thus, methods have error in return where appropriate. Handy for using in-memory b-tree for writing unit tests to mock the "Enterprise" V2 version.

Types

type BtreeInterface

type BtreeInterface[TK btree.Comparable, TV any] interface {
	// Add adds an item to the b-tree and does not check for duplicates.
	Add(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.
	AddIfNotExist(key TK, value TV) 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.
	FindOne(key TK, firstItemWithKey bool) bool
	// GetCurrentKey returns the current item's key.
	GetCurrentKey() TK
	// GetCurrentValue returns the current item's value.
	GetCurrentValue() TV
	// Update finds the item with key and update its value to the value argument.
	Update(key TK, value TV) bool
	// UpdateCurrentItem will update the Value of the current item.
	// Key is read-only, thus, no argument for the key.
	UpdateCurrentItem(newValue TV) bool
	// Remove will find the item with a given key then remove that item.
	Remove(key TK) bool
	// RemoveCurrentItem will remove the current key/value pair from the store.
	RemoveCurrentItem() bool

	// Cursor like "move" functions. Use the CurrentKey/CurrentValue to retrieve the
	// "current item" details(key &/or value).
	MoveToFirst() bool
	MoveToLast() bool
	MoveToNext() bool
	MoveToPrevious() 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.
	IsUnique() bool
}

BtreeInterface 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".

type Recyclable

type Recyclable struct {
	Year  int
	Month int
	Day   int
	Hour  int
	btree.Recyclable
}

Recycler is not used in in-memory store, 'below are just stubs.

func (Recyclable) Add

func (Recyclable) Add(recyclable []btree.Recyclable) error

func (Recyclable) Get

func (Recyclable) Get(batch int, objectType int) []btree.Recyclable

func (Recyclable) Remove

func (Recyclable) Remove(items []btree.Recyclable) error

Jump to

Keyboard shortcuts

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