memorytable

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Max max

Max is a value that greater than all values except Max itself

View Source
var Min min

Min is a value that smaller than all values except Min itself

Functions

func ToOrdered

func ToOrdered(v any) any

ToOrdered convert v to Ordered value

func TypeMatch

func TypeMatch(v any, typ types.T) bool

TypeMatch reports whether v is typ typed

Types

type Atomic

type Atomic[T any] struct {
	// contains filtered or unexported fields
}

Atomic is type-safe wrapper of atomic.Value

func NewAtomic

func NewAtomic[T any](value T) *Atomic[T]

NewAtomic creates a new atomic variable with passed value

func (*Atomic[T]) Load

func (a *Atomic[T]) Load() T

Load loads the value

func (*Atomic[T]) Store

func (a *Atomic[T]) Store(value T)

Store stores a new value

type BTree added in v0.7.0

type BTree[
	K Ordered[K],
	V any,
] struct {
	// contains filtered or unexported fields
}

func NewBTree added in v0.7.0

func NewBTree[
	K Ordered[K],
	V any,
]() *BTree[K, V]

func (*BTree[K, V]) Copy added in v0.7.0

func (b *BTree[K, V]) Copy() Tree[K, V]

func (*BTree[K, V]) Delete added in v0.7.0

func (b *BTree[K, V]) Delete(pivot TreeNode[K, V])

func (*BTree[K, V]) Get added in v0.7.0

func (b *BTree[K, V]) Get(pivot TreeNode[K, V]) (TreeNode[K, V], bool)

func (*BTree[K, V]) Iter added in v0.7.0

func (b *BTree[K, V]) Iter() TreeIter[K, V]

func (*BTree[K, V]) Set added in v0.7.0

func (b *BTree[K, V]) Set(pair TreeNode[K, V]) (TreeNode[K, V], bool)

type BTreeLog added in v0.7.0

type BTreeLog[
	K Ordered[K],
	V any,
] struct {
	// contains filtered or unexported fields
}

func NewBTreeLog added in v0.7.0

func NewBTreeLog[
	K Ordered[K],
	V any,
]() *BTreeLog[K, V]

func (*BTreeLog[K, V]) Iter added in v0.7.0

func (b *BTreeLog[K, V]) Iter() LogIter[K, V]

func (*BTreeLog[K, V]) Set added in v0.7.0

func (b *BTreeLog[K, V]) Set(entry *logEntry[K, V])

type Batch added in v0.7.0

type Batch[
	K Ordered[K],
	V any,
	R Row[K, V],
] struct {
	// contains filtered or unexported fields
}

Batch represents a batch of operations that commit atomically

func (*Batch[K, V, R]) Commit added in v0.7.0

func (b *Batch[K, V, R]) Commit()

Commit commits the batch

func (*Batch[K, V, R]) Delete added in v0.7.0

func (b *Batch[K, V, R]) Delete(key K) (err error)

Delete deletes a row

func (*Batch[K, V, R]) Get added in v0.7.0

func (b *Batch[K, V, R]) Get(key K) (value V, err error)

Get gets the value of key

func (*Batch[K, V, R]) Insert added in v0.7.0

func (b *Batch[K, V, R]) Insert(row R) (err error)

Insert inserts a row

func (*Batch[K, V, R]) Update added in v0.7.0

func (b *Batch[K, V, R]) Update(row R) (err error)

Update updates a row

func (*Batch[K, V, R]) Upsert added in v0.7.0

func (b *Batch[K, V, R]) Upsert(row R) (err error)

Upsert update or insert a row

type BatchIter

type BatchIter func() (tuple []Nullable)

BatchIter iterates over a batch.Batch

func NewBatchIter

func NewBatchIter(b *batch.Batch) BatchIter

NewBatchIter create an iter over b

type Bool

type Bool bool

Bool represents a boolean value

func (Bool) Less

func (b Bool) Less(than Bool) bool

Less compares tow Bools

type BoundedIndexIter added in v0.7.0

type BoundedIndexIter[
	K Ordered[K],
	V any,
] struct {
	// contains filtered or unexported fields
}

BoundedIndexIter wraps another index iter within bounds

func NewBoundedIndexIter added in v0.7.0

func NewBoundedIndexIter[
	K Ordered[K],
	V any,
](iter TreeIter[K, V], min Tuple, max Tuple) *BoundedIndexIter[K, V]

func (*BoundedIndexIter[K, V]) Close added in v0.7.0

func (i *BoundedIndexIter[K, V]) Close() error

Close closes the iter

func (*BoundedIndexIter[K, V]) First added in v0.7.0

func (i *BoundedIndexIter[K, V]) First() bool

First sets the cursor to the first index entry

func (*BoundedIndexIter[K, V]) Next added in v0.7.0

func (i *BoundedIndexIter[K, V]) Next() bool

Next reports whether next entry is valid

func (*BoundedIndexIter[K, V]) Read added in v0.7.0

func (i *BoundedIndexIter[K, V]) Read() (*IndexEntry[K, V], error)

Read returns the current entry

func (*BoundedIndexIter[K, V]) Seek added in v0.7.0

func (i *BoundedIndexIter[K, V]) Seek(pivot *IndexEntry[K, V]) bool

Seek seeks to the pivot

type Bytes

type Bytes []byte

Bytes represents a slice of bytes

func (Bytes) Less

func (b Bytes) Less(than Bytes) bool

Less compares two Bytes's

type Decimal added in v0.8.0

type Decimal types.Decimal128

Decimal represents a Decimal128 value

func (Decimal) Less added in v0.8.0

func (b Decimal) Less(than Decimal) bool

Less compares two Decimals

type Float

type Float float64

Float represents a floating-point value

func (Float) Less

func (f Float) Less(than Float) bool

Less compares two Floats

type ID

type ID = memoryengine.ID

ID represents a unique id

type IndexEntry

type IndexEntry[
	K Ordered[K],
	V any,
] struct {
	Index Tuple
	Key   K
}

IndexEntry represents an index entry

type Int

type Int int64

Int represents an integer value

func (Int) Less

func (i Int) Less(than Int) bool

Less compares tow Ints

type Iter

type Iter[T any] interface {
	First() bool
	Next() bool
	Read() (T, error)
	Close() error
}

Iter represents a generic iterator

type KVPair

type KVPair[
	K Ordered[K],
	V any,
] struct {
	Key K
	*KVValue[K, V]
}

KVPair represents a physical row in Table

func (*KVPair[K, V]) String

func (k *KVPair[K, V]) String() string

String returns text form of KVPair

type KVValue added in v0.7.0

type KVValue[
	K Ordered[K],
	V any,
] struct {
	ID      int64
	Value   V
	Indexes []Tuple
}

KVValue represents the value of a KVPair

type Log added in v0.7.0

type Log[
	K Ordered[K],
	V any,
] interface {
	Iter() LogIter[K, V]
	Set(*logEntry[K, V])
}

type LogIter added in v0.7.0

type LogIter[
	K Ordered[K],
	V any,
] interface {
	Iter[*logEntry[K, V]]
}

type Nullable

type Nullable struct {
	IsNull bool
	Value  any
}

Nullable represents a nullable value

func VectorAt

func VectorAt(vec *vector.Vector, i int) (value Nullable)

VectorAt returns a nullable value at specifed index

func (Nullable) AppendVector

func (n Nullable) AppendVector(
	vec *vector.Vector, mp *mpool.MPool) error

AppendVector append the value to a vector

func (Nullable) Equal

func (n Nullable) Equal(n2 Nullable) bool

Equal reports whether tow Nullable values are equal

type Ordered

type Ordered[To any] interface {
	Less(to To) bool
}

Ordered represents ordered value

type Row

type Row[K any, V any] interface {
	Key() K
	Value() V
	Indexes() []Tuple
	UniqueIndexes() []Tuple
}

Row represents a logical row in a table

type SeekIter added in v0.7.0

type SeekIter[T any] interface {
	Iter[T]
	Seek(T) bool
}

SeekIter represents a generic seekable iterator

type SliceLog added in v0.7.0

type SliceLog[
	K Ordered[K],
	V any,
] []*logEntry[K, V]

func NewSliceLog added in v0.7.0

func NewSliceLog[
	K Ordered[K],
	V any,
]() *SliceLog[K, V]

func (*SliceLog[K, V]) Iter added in v0.7.0

func (s *SliceLog[K, V]) Iter() LogIter[K, V]

func (*SliceLog[K, V]) Set added in v0.7.0

func (s *SliceLog[K, V]) Set(entry *logEntry[K, V])

type Table

type Table[
	K Ordered[K],
	V any,
	R Row[K, V],
] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Table represents a table

func NewTable

func NewTable[
	K Ordered[K],
	V any,
	R Row[K, V],
]() *Table[K, V, R]

NewTable creates new table

func (*Table[K, V, R]) Delete

func (t *Table[K, V, R]) Delete(
	tx *Transaction,
	key K,
) (
	err error,
)

Delete deletes a row from the table

func (*Table[K, V, R]) DisableHistory added in v0.7.0

func (t *Table[K, V, R]) DisableHistory()

func (*Table[K, V, R]) Dump added in v0.7.0

func (t *Table[K, V, R]) Dump(w io.Writer)

func (*Table[K, V, R]) EraseHistory

func (t *Table[K, V, R]) EraseHistory(before Time)

EraseHistory erases history before specified time

func (*Table[K, V, R]) Get

func (t *Table[K, V, R]) Get(
	tx *Transaction,
	key K,
) (
	value V,
	err error,
)

Get gets the value of a key

func (*Table[K, V, R]) Index

func (t *Table[K, V, R]) Index(tx *Transaction, index Tuple) (entries []*IndexEntry[K, V], err error)

Index finds entry in table

func (*Table[K, V, R]) Insert

func (t *Table[K, V, R]) Insert(
	tx *Transaction,
	row R,
) (
	err error,
)

Insert inserts a row to the table

func (*Table[K, V, R]) NewBatch added in v0.7.0

func (t *Table[K, V, R]) NewBatch(tx *Transaction) (*Batch[K, V, R], error)

NewBatch creates a new batch for tx

func (*Table[K, V, R]) NewIndexIter

func (t *Table[K, V, R]) NewIndexIter(tx *Transaction, min Tuple, max Tuple) (Iter[*IndexEntry[K, V]], error)

NewIndexIter creates new index iter

func (*Table[K, V, R]) NewIter

func (t *Table[K, V, R]) NewIter(tx *Transaction) (*TableIter[K, V], error)

NewIter creates a new iter

func (*Table[K, V, R]) Update

func (t *Table[K, V, R]) Update(
	tx *Transaction,
	row R,
) (
	err error,
)

Update updates a row in the table

func (*Table[K, V, R]) Upsert

func (t *Table[K, V, R]) Upsert(
	tx *Transaction,
	row R,
) (
	err error,
)

Upsert update a row in the table or insert the row to the table if not exists

type TableIter

type TableIter[
	K Ordered[K],
	V any,
] struct {
	// contains filtered or unexported fields
}

TableIter represents an iter over a table

func (*TableIter[K, V]) Close

func (t *TableIter[K, V]) Close() error

Close closes the iter

func (*TableIter[K, V]) First

func (t *TableIter[K, V]) First() bool

First moves the cursor to first entry

func (*TableIter[K, V]) Next

func (t *TableIter[K, V]) Next() bool

Next moves the cursor to next entry

func (*TableIter[K, V]) Read

func (t *TableIter[K, V]) Read() (key K, value V, err error)

Read reads current key and value

func (*TableIter[K, V]) Seek

func (t *TableIter[K, V]) Seek(key K) bool

Seek moves the cursor to or before the key

type Text

type Text string

Text represents a string value

func (Text) Less

func (t Text) Less(than Text) bool

Less compares tow Texts

type Time

type Time = timestamp.Timestamp

Time represents a time

func Now

func Now(clock clock.Clock) Time

Now gets the current time from a clock

type Transaction

type Transaction struct {
	State     *Atomic[TransactionState]
	BeginTime Time
	// contains filtered or unexported fields
}

Transaction represents a transaction a transaction may contains multiple operations on multiple tables a transaction commits atomically

func NewTransaction

func NewTransaction(
	beginTime Time,
) *Transaction

NewTransaction creates a new transaction using beginTime as snapshot time

func (*Transaction) Abort

func (t *Transaction) Abort() error

Abort aborts the transaction

func (*Transaction) Commit

func (t *Transaction) Commit(commitTime Time) error

Commit commits the transaction

type TransactionState

type TransactionState uint8

TransactionState represents state of a transaction

const (
	// Active is the default state of a newly created transaction
	Active TransactionState = iota
	// Committed is the state of a committed transaction
	Committed
	// Aborted is the state of a aborted transaction
	Aborted
)

func (TransactionState) String

func (t TransactionState) String() string

String returns the text form of a state

type Tree added in v0.7.0

type Tree[
	K Ordered[K],
	V any,
] interface {
	Copy() Tree[K, V]
	Get(TreeNode[K, V]) (TreeNode[K, V], bool)
	Set(TreeNode[K, V]) (TreeNode[K, V], bool)
	Delete(TreeNode[K, V])
	Iter() TreeIter[K, V]
}

type TreeIter added in v0.7.0

type TreeIter[
	K Ordered[K],
	V any,
] interface {
	SeekIter[TreeNode[K, V]]
}

type TreeNode added in v0.7.0

type TreeNode[
	K Ordered[K],
	V any,
] struct {
	IndexEntry *IndexEntry[K, V]
	KVPair     *KVPair[K, V]
}

type Tuple

type Tuple []any

Tuple represents multiple ordered values

func (Tuple) Less

func (t Tuple) Less(than Tuple) bool

Less compares two tuples

type Uint

type Uint int64

Unit represents an unsigned integer value

func (Uint) Less

func (i Uint) Less(than Uint) bool

Less compares tow Uints

Jump to

Keyboard shortcuts

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