hashmap
An efficient hashmap implementation in Go.
This is a rewrite of the tidwall/rhh package to include Go 1.18 features.
Features
- Support for Generics (Go 1.18+).
Map
andSet
types for unordered key-value maps and sets,- xxhash algorithm
- Open addressing
- Robin hood hashing
For ordered key-value data, check out the tidwall/btree package.
Using
To start using this package, install Go and run:
$ go get github.com/tidwall/hashmap
Getting Started
Installing
To start using hashmap
, install Go and run go get
:
$ go get github.com/tidwall/hashmap
This will retrieve the library.
Usage
The Map
type works similar to a standard Go map, and includes the methods:
Set
, Get
, Delete
, Len
, and Scan
.
var m hashmap.Map[string, string]
m.Set("Hello", "Dolly!")
val, _ := m.Get("Hello")
fmt.Printf("%v\n", val)
val, _ = m.Delete("Hello")
fmt.Printf("%v\n", val)
val, _ = m.Get("Hello")
fmt.Printf("%v\n", val)
// Output:
// Dolly!
// Dolly!
//
The Set
type is like Map
but only for keys.
It includes the methods: Insert
, Contains
, Delete
, Len
, and Scan
.
var m hashmap.Set[string]
m.Insert("Andy")
m.Insert("Kate")
m.Insert("Janet")
fmt.Printf("%v\n", m.Contains("Kate"))
fmt.Printf("%v\n", m.Contains("Bob"))
fmt.Printf("%v\n", m.Contains("Andy"))
// Output:
// true
// false
// true
Performance
See BENCH.md for more info.
Contact
Josh Baker @tidwall
License
Source code is available under the MIT License.
hashmap's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.