Skip to content

Very simple, idiomatic, and thread-safe implementation of Hashtables for Golang

License

Notifications You must be signed in to change notification settings

HotPotatoC/hashtable

Repository files navigation

Hashtable in Go

Very simple, idiomatic and thread-safe implementation of Hashtables for Golang using Seperate chaining.

Installation

❯ go get -u github.com/HotPotatoC/hashtable

Usage

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

Methods

// 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

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

Support

Buy Me A Coffee

About

Very simple, idiomatic, and thread-safe implementation of Hashtables for Golang

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages