Very simple, idiomatic and thread-safe implementation of Hashtables for Golang using Seperate chaining.
❯ go get -u github.com/HotPotatoC/hashtable
Set a value
ht := hashtable.New()
ht.Set("user", "John")
Get a value
ht.Get("user") // John
Remove a value
ht.Remove("user") // 1
Iterate through the table using Iter()
for entry := range ht.Iter() {
fmt.Printf("key: %s | value: %v\n", entry.Key, entry.Value)
}
See more examples here
// Set inserts a new key-value pair item into the hash table
Set(k string, v interface{})
// Get returns the value of the given key
// and a boolean which returns false if the
// lookup result is nil otherwise true
Get(k string) (interface{}, bool)
// Remove deletes an item by the given key
// and returns the deleted count
Remove(k string) int
// Iter returns an iterator for the hashtable
Iter() <-chan *Entry
// Exist returns true if an item with the given key exists in the table
// otherwise returns false
Exist(k string) bool
// Len represents the size of the hash table
Len() int
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.