hash

package
v0.0.0-...-8a2c9d0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BUCKETSIZE int64 = (PAGESIZE-BUCKET_HEADER_SIZE)/ENTRYSIZE - 1 // num entries
View Source
var BUCKET_HEADER_SIZE int64 = DEPTH_SIZE + NUM_KEYS_SIZE
View Source
var DEPTH_OFFSET int64 = 0
View Source
var DIRECTORY_HEADER_SIZE int64 = binary.MaxVarintLen64 * 2 // Must store global depth and next pointer
View Source
var ENTRYSIZE int64 = binary.MaxVarintLen64 * 2 // int64 key, int64 value
View Source
var NUM_KEYS_OFFSET int64 = DEPTH_OFFSET + DEPTH_SIZE
View Source
var NUM_KEYS_SIZE int64 = binary.MaxVarintLen64
View Source
var PAGESIZE int64 = pager.PAGESIZE
View Source
var ROOT_PN int64 = 0

Hash table variables

Functions

func Hasher

func Hasher(key int64, depth int64) int64

Hasher returns the hash of a key, modded by 2^depth.

func IsHash

func IsHash(index *HashIndex) (bool, error)

func MurmurHasher

func MurmurHasher(key int64, size int64) uint

MurmurHasher returns the MurmurHash3 hash of the given key, bounded by size.

func WriteHashTable

func WriteHashTable(bucketPager *pager.Pager, table *HashTable) error

Write hash table out to memory.

func XxHasher

func XxHasher(key int64, size int64) uint

XxHasher returns the xxHash hash of the given key, bounded by size.

Types

type BucketLockType

type BucketLockType int

Lock Types

const (
	NO_LOCK    BucketLockType = 0
	WRITE_LOCK BucketLockType = 1
	READ_LOCK  BucketLockType = 2
)

type HashBucket

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

HashBucket.

func NewHashBucket

func NewHashBucket(pager *pager.Pager, depth int64) (*HashBucket, error)

Construct a new HashBucket.

func (*HashBucket) Delete

func (bucket *HashBucket) Delete(key int64) error

Delete the given key-value pair, does not coalesce.

func (*HashBucket) Find

func (bucket *HashBucket) Find(key int64) (utils.Entry, bool)

Finds the entry with the given key.

func (*HashBucket) GetDepth

func (bucket *HashBucket) GetDepth() int64

Get local depth.

func (*HashBucket) GetPage

func (bucket *HashBucket) GetPage() *pager.Page

Get a bucket's page.

func (*HashBucket) Insert

func (bucket *HashBucket) Insert(key int64, value int64) (bool, error)

Inserts the given key-value pair, splits if necessary.

func (*HashBucket) Print

func (bucket *HashBucket) Print(w io.Writer)

Pretty-print this bucket.

func (*HashBucket) RLock

func (bucket *HashBucket) RLock()

[CONCURRENCY] Grab a read lock on the hash table index

func (*HashBucket) RUnlock

func (bucket *HashBucket) RUnlock()

[CONCURRENCY] Release a read lock on the hash table index

func (*HashBucket) Select

func (bucket *HashBucket) Select() (entries []utils.Entry, err error)

Select all entries in this bucket.

func (*HashBucket) Update

func (bucket *HashBucket) Update(key int64, value int64) error

Update the given key-value pair, should never split. Find the bucket we want based on key, then update the entry using updateValueAt.

func (*HashBucket) WLock

func (bucket *HashBucket) WLock()

[CONCURRENCY] Grab a write lock on the hash table index

func (*HashBucket) WUnlock

func (bucket *HashBucket) WUnlock()

[CONCURRENCY] Release a write lock on the hash table index

type HashCursor

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

HashCursor points to a spot in the hash table.

func (*HashCursor) GetEntry

func (cursor *HashCursor) GetEntry() (utils.Entry, error)

GetEntry returns the entry currently pointed to by the cursor.

func (*HashCursor) IsEnd

func (cursor *HashCursor) IsEnd() bool

IsEnd returns true if at end.

func (*HashCursor) StepForward

func (cursor *HashCursor) StepForward() bool

StepForward moves the cursor ahead by one entry.

type HashEntry

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

HashEntry is a single entry in a hashtable. Implements utils.Entry.

func (HashEntry) GetKey

func (entry HashEntry) GetKey() int64

Get key.

func (HashEntry) GetValue

func (entry HashEntry) GetValue() int64

Get value.

func (HashEntry) Marshal

func (entry HashEntry) Marshal() []byte

marshal serializes a given entry into a byte array.

func (HashEntry) Print

func (entry HashEntry) Print(w io.Writer)

Print this entry.

func (*HashEntry) SetKey

func (entry *HashEntry) SetKey(key int64)

Set key.

func (*HashEntry) SetValue

func (entry *HashEntry) SetValue(value int64)

Set value.

type HashIndex

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

HashIndex is an index that uses a HashTable as its datastructure. Implements db.Index.

func OpenTable

func OpenTable(filename string) (*HashIndex, error)

Opens the pager with the given table name.

func (*HashIndex) Close

func (index *HashIndex) Close() error

Closes the table by closing the pager.

func (*HashIndex) Delete

func (index *HashIndex) Delete(key int64) error

Delete given element.

func (*HashIndex) Find

func (index *HashIndex) Find(key int64) (utils.Entry, error)

Find element by key.

func (*HashIndex) GetName

func (table *HashIndex) GetName() string

Get name.

func (*HashIndex) GetPager

func (table *HashIndex) GetPager() *pager.Pager

Get pager.

func (*HashIndex) GetTable

func (index *HashIndex) GetTable() *HashTable

Get table.

func (*HashIndex) Insert

func (index *HashIndex) Insert(key int64, value int64) error

Insert given element.

func (*HashIndex) Print

func (index *HashIndex) Print(w io.Writer)

Print all elements.

func (*HashIndex) PrintPN

func (index *HashIndex) PrintPN(pn int, w io.Writer)

Print a page of elements.

func (*HashIndex) Select

func (index *HashIndex) Select() ([]utils.Entry, error)

Select all elements.

func (*HashIndex) TableStart

func (table *HashIndex) TableStart() (utils.Cursor, error)

TableStart returns a cursor to the first entry in the hash table.

func (*HashIndex) Update

func (index *HashIndex) Update(key int64, value int64) error

Update given element.

type HashTable

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

HashTable definitions.

func NewHashTable

func NewHashTable(pager *pager.Pager) (*HashTable, error)

Returns a new HashTable.

func ReadHashTable

func ReadHashTable(bucketPager *pager.Pager) (*HashTable, error)

Read hash table in from memory.

func (*HashTable) Delete

func (table *HashTable) Delete(key int64) error

Delete the given key-value pair, does not coalesce.

func (*HashTable) ExtendTable

func (table *HashTable) ExtendTable()

ExtendTable increases the global depth of the table by 1.

func (*HashTable) Find

func (table *HashTable) Find(key int64) (utils.Entry, error)

Finds the entry with the given key.

func (*HashTable) GetAndLockBucket

func (table *HashTable) GetAndLockBucket(hash int64, lock BucketLockType) (*HashBucket, error)

Returns the bucket in the hash table, and increments the bucket ref count.

func (*HashTable) GetAndLockBucketByPN

func (table *HashTable) GetAndLockBucketByPN(pn int64, lock BucketLockType) (*HashBucket, error)

Returns the bucket in the hash table using its page number, and increments the bucket ref count.

func (*HashTable) GetBucket

func (table *HashTable) GetBucket(hash int64) (*HashBucket, error)

Returns the bucket in the hash table, and increments the bucket ref count.

func (*HashTable) GetBucketByPN

func (table *HashTable) GetBucketByPN(pn int64) (*HashBucket, error)

Returns the bucket in the hash table using its page number, and increments the bucket ref count.

func (*HashTable) GetBuckets

func (table *HashTable) GetBuckets() []int64

Get bucket page numbers.

func (*HashTable) GetDepth

func (table *HashTable) GetDepth() int64

Get depth.

func (*HashTable) GetPager

func (table *HashTable) GetPager() *pager.Pager

Get pager.

func (*HashTable) Insert

func (table *HashTable) Insert(key int64, value int64) error

Inserts the given key-value pair, splits if necessary.

func (*HashTable) Print

func (table *HashTable) Print(w io.Writer)

Print out each bucket.

func (*HashTable) PrintPN

func (table *HashTable) PrintPN(pn int, w io.Writer)

Print out a specific bucket.

func (*HashTable) RLock

func (table *HashTable) RLock()

[CONCURRENCY] Grab a read lock on the hash table index

func (*HashTable) RUnlock

func (table *HashTable) RUnlock()

[CONCURRENCY] Release a read lock on the hash table index

func (*HashTable) Select

func (table *HashTable) Select() ([]utils.Entry, error)

Select all entries in this table.

func (*HashTable) Split

func (table *HashTable) Split(bucket *HashBucket, hash int64) error

Split the given bucket into two, extending the table if necessary.

func (*HashTable) Update

func (table *HashTable) Update(key int64, value int64) error

Update the given key-value pair.

func (*HashTable) WLock

func (table *HashTable) WLock()

[CONCURRENCY] Grab a write lock on the hash table index

func (*HashTable) WUnlock

func (table *HashTable) WUnlock()

[CONCURRENCY] Release a write lock on the hash table index

Jump to

Keyboard shortcuts

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