Skip to content

A simple and efficient hashmap package for Go. Open addressing, robin hood hashing, and xxh3 algorithm. Supports generics.

License

Notifications You must be signed in to change notification settings

tidwall/hashmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hashmap

GoDoc

An efficient hashmap implementation in Go.

Features

For ordered key-value data, check out the tidwall/btree package.

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, Scan, Keys, Values, and Copy.

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, Scan and Keys.

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.

About

A simple and efficient hashmap package for Go. Open addressing, robin hood hashing, and xxh3 algorithm. Supports generics.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages