Documentation
¶
Index ¶
- Constants
- type Btree
- func (btree *Btree[TK, TV]) Add(key TK, value TV) (bool, error)
- func (btree *Btree[TK, TV]) AddIfNotExist(key TK, value TV) (bool, error)
- func (btree *Btree[TK, TV]) FindOne(key TK, firstItemWithKey bool) (bool, error)
- func (btree *Btree[TK, TV]) GetCurrentItem() Item[TK, TV]
- func (btree *Btree[TK, TV]) GetCurrentKey() TK
- func (btree *Btree[TK, TV]) GetCurrentValue() (TV, error)
- func (btree *Btree[TK, TV]) IsUnique() bool
- func (btree *Btree[TK, TV]) IsValueDataInNodeSegment() bool
- func (btree *Btree[TK, TV]) MoveToFirst() (bool, error)
- func (btree *Btree[TK, TV]) MoveToLast() (bool, error)
- func (btree *Btree[TK, TV]) MoveToNext() (bool, error)
- func (btree *Btree[TK, TV]) MoveToPrevious() (bool, error)
- func (btree *Btree[TK, TV]) Remove(key TK) (bool, error)
- func (btree *Btree[TK, TV]) RemoveCurrentItem() (bool, error)
- func (btree *Btree[TK, TV]) Update(key TK, value TV) (bool, error)
- func (btree *Btree[TK, TV]) UpdateCurrentItem(newValue TV) (bool, error)
- type BtreeInterface
- type Comparable
- type Comparer
- type EntityType
- type Handle
- type Item
- type Node
- type NodeDataBlocks
- type NodeRepository
- type Recyclable
- type RecyclerRepository
- type SlotValue
- type SlotValueDataBlocks
- type Store
- type StoreInterface
- type StoreRepository
- type Transaction
- type TransactionActionType
- type TransactionEntry
- type TransactionRepository
- type UUID
- type VirtualIdRepository
Constants ¶
const ( Get = iota Add Update Remove )
const ( // BTreeNode is the entity type of the B-Tree Node. BTreeNode = iota // ValuePart is the entity type of the value part in the key/value pair // that a B-Tree supports persistence & access. ValuePart )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Btree ¶
type Btree[TK Comparable, TV any] struct { Store Store // contains filtered or unexported fields }
Btree manages items using B-tree data structure and algorithm.
func NewBtree ¶
func NewBtree[TK Comparable, TV any](store Store, si *StoreInterface[TK, TV]) *Btree[TK, TV]
NewBtree creates a new B-Tree instance.
func (*Btree[TK, TV]) AddIfNotExist ¶
AddIfNotExist will add an item if its key is not yet in the B-Tree.
func (*Btree[TK, TV]) GetCurrentItem ¶
GetCurrentItem returns the current item containing key/value pair.
func (*Btree[TK, TV]) GetCurrentKey ¶
func (btree *Btree[TK, TV]) GetCurrentKey() TK
GetCurrentKey returns the current item's key part.
func (*Btree[TK, TV]) GetCurrentValue ¶
GetCurrentValue returns the current item's value part.
func (*Btree[TK, TV]) IsUnique ¶
IsUnique returns true if B-Tree is specified to store items with Unique keys, otherwise false.
func (*Btree[TK, TV]) IsValueDataInNodeSegment ¶
IsValueDataInNodeSegment is true if Item's Values are stored in the Node segment together with the Items' Keys. Always true in in-memory B-Tree.
func (*Btree[TK, TV]) MoveToFirst ¶
MoveToFirst will traverse the tree and find the first item, first according to the key ordering sequence.
func (*Btree[TK, TV]) MoveToLast ¶
func (*Btree[TK, TV]) MoveToNext ¶
func (*Btree[TK, TV]) MoveToPrevious ¶
func (*Btree[TK, TV]) RemoveCurrentItem ¶
RemoveCurrentItem will remove the current item, i.e. - referenced by CurrentItemRef.
func (*Btree[TK, TV]) Update ¶
Update will find the item with matching key as the key parameter & update its value with the provided value parameter.
func (*Btree[TK, TV]) UpdateCurrentItem ¶
type BtreeInterface ¶
type BtreeInterface[TK Comparable, TV any] interface { // Add adds an item to the b-tree and does not check for duplicates. Add(key TK, value TV) (bool, error) // 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, error) // 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, error) // GetCurrentKey returns the current item's key. GetCurrentKey() TK // GetCurrentValue returns the current item's value. GetCurrentValue() (TV, error) // Update finds the item with key and update its value to the value argument. Update(key TK, value TV) (bool, error) // UpdateCurrentItem will update the Value of the current item. // Key is read-only, thus, no argument for the key. UpdateCurrentItem(newValue TV) (bool, error) // Remove will find the item with a given key then remove that item. Remove(key TK) (bool, error) // RemoveCurrentItem will remove the current key/value pair from the store. RemoveCurrentItem() (bool, error) // Cursor like "move" functions. Use the CurrentKey/CurrentValue to retrieve the // "current item" details(key &/or value). MoveToFirst() (bool, error) MoveToLast() (bool, error) MoveToNext() (bool, error) MoveToPrevious() (bool, error) // IsValueDataInNodeSegment is true if "Value" data is stored in the B-Tree node's segment. // Otherwise is false. IsValueDataInNodeSegment() 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.
type Comparable ¶
Comparable interface is used as a B-Tree store (generics) constraint for Key types.
type Comparer ¶
type Comparer interface {
// Implement Compare to compare this object with the 'other' object.
// Returns -1 (this object < other), 0 (this object == other), 1 (this object > other)
Compare(other interface{}) int
}
Comparer interface specifies the Compare function.
type EntityType ¶
type EntityType uint
type Handle ¶
type Handle struct {
LogicalId UUID
PhysicalIdA UUID
PhysicalIdB UUID
IsActiveIdB bool
Version int
IsDeleted bool
}
Handle is a structure that holds Logical Id and the underlying current Physical Id it maps to. E.g. - Node, Slot Value, etc... It also contains other fields useful for allowing transaction manager to effectively manage & allow seamless switching of data "objects", e.g. a modified Node or Value Data in a transaction can get switched to be the "active" one upon commit, and thus, start to get seen by succeeding SOP I/O.
func (Handle) GetActiveId ¶
GetActiveId returns the currently active (if there is) UUID of a given Handle.
type Item ¶
type Item[TK Comparable, TV any] struct { // Key is the key part in key/value pair. Key TK // Value is saved nil if data is to be persisted in the "data segment"(& ValueId set to a valid UUID), // otherwise it should point to the actual data and persisted in B-Tree Node segment together with the Key. Value *TV // ValueLogicalId should be a valid (logical) Id of the data if it is saved in the "data segment", // otherwise this should be nil(unused). ValueLogicalId UUID Version int // contains filtered or unexported fields }
Item contains key & value pair, plus the version number.
type Node ¶
type Node[TK Comparable, TV any] struct { Id UUID ParentId UUID Slots []*Item[TK, TV] Count int Version int IsDeleted bool // contains filtered or unexported fields }
Node contains a B-Tree node's data.
type NodeDataBlocks ¶
type NodeRepository ¶
type NodeRepository[TK Comparable, TV any] interface { Get(nodeId UUID) (*Node[TK, TV], error) Upsert(*Node[TK, TV]) error Remove(nodeId UUID) error }
NodeRepository interface specifies the node repository.
type Recyclable ¶
type RecyclerRepository ¶
type RecyclerRepository interface {
Get(itemCount int, objectType int) []Recyclable
Add(recyclables []Recyclable) error
Remove(items []Recyclable) error
}
RecyclerRepository provides capability to recycle storage areas for storing data such as Node, etc... There are backends where this is not needed at all, e.g. Cassandra backend will not need this.
type SlotValueDataBlocks ¶
type Store ¶
type Store struct {
// Name of this (B-Tree store).
Name string
// Count of items that can be stored on a given node.
SlotLength int
// IsUnique tells whether key/value pair (items) of this tree should be unique on key.
IsUnique bool
KeyInfo string
ValueInfo string
// RootNodeId is the root node's Id.
RootNodeId UUID
// Total count of items stored.
Count int64
// Version number.
Version int
// Is marked deleted or not.
IsDeleted bool
// IsValueDataInNodeSegment is true if "Value" data is stored in the B-Tree node's data segment.
// Otherwise is false.
IsValueDataInNodeSegment bool
}
Store contains a given (B-Tree) store details.
type StoreInterface ¶
type StoreInterface[TK Comparable, TV any] struct { // StoreRepository is used to manage/access stores. StoreRepository StoreRepository // NodeRepository is used to manage/access B-Tree nodes. NodeRepository NodeRepository[TK, TV] // VirtualIdRepository is used to manage/access all objects keyed off of their virtual Ids (UUIDs). VirtualIdRepository VirtualIdRepository // RecyclerRepository is used to manage/access all deleted objects' "data blocks". RecyclerRepository RecyclerRepository // TransactionRepository is used to manage a transaction. TransactionRepository TransactionRepository // Transaction object if there is one. Transaction Transaction }
StoreInterface contains different repositories needed/used by B-Tree to manage/access its data/objects.
type StoreRepository ¶
type StoreRepository interface {
Get(name string) (Store, error)
Add(Store) error
Remove(name string) error
}
StoreRepository interface specifies the store repository.
type Transaction ¶
Transaction interface defines the "enduser facing" transaction methods.
type TransactionActionType ¶
type TransactionActionType uint
type TransactionEntry ¶
type TransactionEntry struct {
EntityLogicalId UUID
EntityType EntityType
Sequence int
Action TransactionActionType
IsDeleted bool
}
TransactionEntry contain info about each Store Item modified within a Transaction. NOTE: newly created Stores themselves don't get tracked within the Transaction Entry table. Their items do. New Stores are cached in-memory and get saved (conflict resolved) during Transaction Commit.
type TransactionRepository ¶
type TransactionRepository interface {
Get(transactionId UUID) ([]TransactionEntry, error)
GetByStore(transactionId UUID, storeName string) ([]TransactionEntry, error)
Add([]TransactionEntry) error
MarkDone([]TransactionEntry) error
}