Documentation ¶
Overview ¶
Package hashtable implements a hash table data structure using separate chaining for collision resolution. uses my doublyLinkedList package for the buckets
Index ¶
- func Hash(key interface{}) int
- type Entry
- type HashTable
- func (h *HashTable[K, V]) Add(key K, value V) V
- func (h *HashTable[K, V]) Clear()
- func (h *HashTable[K, V]) ContainsKey(key K) bool
- func (h *HashTable[K, V]) Get(key K) *V
- func (h *HashTable[K, V]) Has(key K) bool
- func (h *HashTable[K, V]) Insert(key K, value V) V
- func (h *HashTable[K, V]) IsEmpty() bool
- func (h *HashTable[K, V]) Keys() []K
- func (h *HashTable[K, V]) Put(key K, value V) V
- func (h *HashTable[K, V]) Remove(key K) *V
- func (h *HashTable[K, V]) Size() int
- func (h *HashTable[K, V]) ToString() string
- func (h *HashTable[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
type Entry[K, V comparable] struct { Hash int // contains filtered or unexported fields }
Entry represents a key-value pair.
func NewEntry ¶
func NewEntry[K, V comparable](key K, value V) *Entry[K, V]
NewEntry creates a new key-value pair entry by hashing the key that is of type K comparable
type HashTable ¶
type HashTable[K, V comparable] struct { // contains filtered or unexported fields }
HashTable represents a hash table data structure
func NewHashTable ¶
func NewHashTable[K, V comparable](capacity int, maxLoadFactor float64) *HashTable[K, V]
NewHashTable creates a new hash table with the given capacity(optional) and load factor(optional) if no arguments are given, the default values of 0.75 and 16 are used
func (*HashTable[K, V]) Add ¶
func (h *HashTable[K, V]) Add(key K, value V) V
Add inserts the given key-value pair into the hash table
func (*HashTable[K, V]) Clear ¶
func (h *HashTable[K, V]) Clear()
Clear removes all elements from the hash table
func (*HashTable[K, V]) ContainsKey ¶
ContainsKey checks if the hash table contains the given key
func (*HashTable[K, V]) Get ¶
func (h *HashTable[K, V]) Get(key K) *V
Get returns the value associated with the given key return nil if the key is not found
func (*HashTable[K, V]) Insert ¶
func (h *HashTable[K, V]) Insert(key K, value V) V
Insert inserts the given key-value pair into the hash table
func (*HashTable[K, V]) Keys ¶
func (h *HashTable[K, V]) Keys() []K
Keys returns a slice of all the keys in the hash table
func (*HashTable[K, V]) Put ¶
func (h *HashTable[K, V]) Put(key K, value V) V
Put inserts the given key-value pair into the hash table
func (*HashTable[K, V]) Remove ¶
func (h *HashTable[K, V]) Remove(key K) *V
Remove removes the entry with the given key from the hash table