hashtable

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultHashFunction

func DefaultHashFunction[K comparable](key K, size int) uint64

DefaultHashFunction is the default hash function (using xxhash).

Types

type ChainedHashTable

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

ChainedHashTable is a chained hash table.

func NewChainedHashTable

func NewChainedHashTable[K comparable, V any](cap int, hashFunc ...HashFunction[K]) *ChainedHashTable[K, V]

NewChainedHashTable returns a new chained hash table.

func (*ChainedHashTable[K, V]) Cap

func (cht *ChainedHashTable[K, V]) Cap() int

Cap returns the capacity of the hash table.

func (*ChainedHashTable[K, V]) Del

func (cht *ChainedHashTable[K, V]) Del(key K) bool

Del deletes the key.

func (*ChainedHashTable[K, V]) Exists

func (cht *ChainedHashTable[K, V]) Exists(key K) bool

Exists returns true if the key exists.

func (*ChainedHashTable[K, V]) Get

func (cht *ChainedHashTable[K, V]) Get(key K) (V, bool)

Get gets the value of the key.

func (*ChainedHashTable[K, V]) Set

func (cht *ChainedHashTable[K, V]) Set(key K, value V)

Set sets the value of the key.

func (*ChainedHashTable[K, V]) Size

func (cht *ChainedHashTable[K, V]) Size() int

Size returns the number of elements in the hash table.

type Entry

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

Entry is an entry in a hash table.

func NewEntry

func NewEntry[K comparable, V any](key K, value V) *Entry[K, V]

NewEntry returns a new entry.

func (*Entry[K, V]) Key

func (e *Entry[K, V]) Key() K

Key returns the key of the entry.

func (*Entry[K, V]) Next

func (e *Entry[K, V]) Next() *Entry[K, V]

Next returns the next entry in the list.

func (*Entry[K, V]) Prev

func (e *Entry[K, V]) Prev() *Entry[K, V]

Prev returns the previous entry in the list.

func (*Entry[K, V]) Value

func (e *Entry[K, V]) Value() V

Value returns the value of the entry.

type HashFunction

type HashFunction[K comparable] func(key K, size int) uint64

HashFunction is a hash function type.

type HashTable

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

HashTable is a hash table.

func NewHashTable

func NewHashTable[K comparable, V any](cap int, hashFunc ...HashFunction[K]) *HashTable[K, V]

NewHashTable returns a new hash table with linear probing.

func (*HashTable[K, V]) Cap

func (ht *HashTable[K, V]) Cap() int

Cap returns the capacity of the hash table.

func (*HashTable[K, V]) Del

func (ht *HashTable[K, V]) Del(key K) bool

Del deletes the key.

func (*HashTable[K, V]) Exists

func (ht *HashTable[K, V]) Exists(key K) bool

Exists returns true if the key exists.

func (*HashTable[K, V]) Get

func (ht *HashTable[K, V]) Get(key K) (V, bool)

Get gets the value of the key.

func (*HashTable[K, V]) Set

func (ht *HashTable[K, V]) Set(key K, value V)

Set sets the value of the key.

func (*HashTable[K, V]) Size

func (ht *HashTable[K, V]) Size() int

Size returns the number of elements in the hash table.

Jump to

Keyboard shortcuts

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