memorytable

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultMemoryTable

type DefaultMemoryTable struct {
	// contains filtered or unexported fields
}

func NewMemoryTable

func NewMemoryTable() *DefaultMemoryTable

func (*DefaultMemoryTable) Get

func (s *DefaultMemoryTable) Get(key string) []byte

Get retrieves the value associated with the provided key from the DefaultMemoryTable. If the key exists and is not marked as deleted, the corresponding value is returned. Otherwise, nil is returned. This method is designed to be thread-safe, allowing concurrent reads while write operations are in progress. Parameters: key (string): The key to look up in the table. Returns: []byte: The value associated with the key if found and not deleted, otherwise nil.

func (*DefaultMemoryTable) Scan

func (s *DefaultMemoryTable) Scan() bool

Scan advances the scanner to the next entry in the DefaultMemoryTable and reports whether there was a value to scan. It returns false when the scan ends, either by reaching the end of the table or due to an error. This method should be used in conjunction with ScanValue to retrieve the actual data.

func (*DefaultMemoryTable) ScanValue

func (s *DefaultMemoryTable) ScanValue() *common.Chunk

ScanValue returns the current chunk data at the scanner's position in the DefaultMemoryTable. This method should be used after Scan to obtain the value of the entry pointed by the scanner. Returns a pointer to common.Chunk which holds the key-value pair information.

func (*DefaultMemoryTable) Set

func (s *DefaultMemoryTable) Set(key string, value []byte, deleted bool)

Set adds or updates a key-value pair in the DefaultMemoryTable. It also handles deletion by setting the 'deleted' flag. It dynamically adjusts the skip list levels based on randomness up to the maxLevel defined for the table. The method is thread-safe and ensures concurrent access is properly managed. Parameters: key (string): The key for the entry. value ([]byte): The value associated with the key. deleted (bool): A flag indicating whether the entry is marked as deleted. It returns nothing.

func (*DefaultMemoryTable) Size

func (s *DefaultMemoryTable) Size() int64

Size returns the total size in bytes of all key-value pairs stored in the DefaultMemoryTable. This includes the combined lengths of keys and values, not accounting for internal structure overhead. The method is safe for concurrent use.

type MemoryTable

type MemoryTable interface {
	Set(key string, value []byte, deleted bool)
	Get(key string) []byte
	Size() int64
	common.Scanner
}

type Node

type Node struct {
	// contains filtered or unexported fields
}

func NewNode

func NewNode(level int32) *Node

NewNode creates and returns a new node with the specified level. The node's next slice is initialized to have the capacity equal to the level, and its chunk is initialized with default values. Parameters: level (int32): The level of the node to be created. Returns: *node: A pointer to the newly created node.

Jump to

Keyboard shortcuts

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