GithubHelp home page GithubHelp logo

hotpotatoc / hashtable Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 0.0 8 KB

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

License: MIT License

Go 100.00%
hashtables golang data-structures

hashtable's Introduction

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

hashtable's People

Contributors

hotpotatoc avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.