Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dolthub/swiss
Golang port of Abseil's SwissTable
https://github.com/dolthub/swiss
abseil asm collection data-structures generics golang hashmap hashtable sse3 swisstable
Last synced: 1 day ago
JSON representation
Golang port of Abseil's SwissTable
- Host: GitHub
- URL: https://github.com/dolthub/swiss
- Owner: dolthub
- License: apache-2.0
- Created: 2023-02-23T19:28:25.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-04T11:15:38.000Z (6 months ago)
- Last Synced: 2025-01-03T16:00:28.357Z (9 days ago)
- Topics: abseil, asm, collection, data-structures, generics, golang, hashmap, hashtable, sse3, swisstable
- Language: Go
- Homepage:
- Size: 35.2 KB
- Stars: 793
- Watchers: 14
- Forks: 42
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- my-awesome - dolthub/swiss - structures,generics,golang,hashmap,hashtable,sse3,swisstable pushed_at:2024-07 star:0.8k fork:0.0k Golang port of Abseil's SwissTable (Go)
README
# SwissMap
SwissMap is a hash table adapated from the "SwissTable" family of hash tables from [Abseil](https://abseil.io/blog/20180927-swisstables). It uses [AES](https://github.com/dolthub/maphash) instructions for fast-hashing and performs key lookups in parallel using [SSE](https://en.wikipedia.org/wiki/Streaming_SIMD_Extensions) instructions. Because of these optimizations, SwissMap is faster and more memory efficient than Golang's built-in `map`. If you'd like to learn more about its design and implementation, check out this [blog post](https://www.dolthub.com/blog/2023-03-28-swiss-map/) announcing its release.
## Example
SwissMap exposes the same interface as the built-in `map`. Give it a try using this [Go playground](https://go.dev/play/p/JPDC5WhYN7g).
```go
package mainimport "github.com/dolthub/swiss"
func main() {
m := swiss.NewMap[string, int](42)m.Put("foo", 1)
m.Put("bar", 2)m.Iter(func(k string, v int) (stop bool) {
println("iter", k, v)
return false // continue
})if x, ok := m.Get("foo"); ok {
println(x)
}
if m.Has("bar") {
x, _ := m.Get("bar")
println(x)
}m.Put("foo", -1)
m.Delete("bar")if x, ok := m.Get("foo"); ok {
println(x)
}
if m.Has("bar") {
x, _ := m.Get("bar")
println(x)
}m.Clear()
// Output:
// iter foo 1
// iter bar 2
// 1
// 2
// -1
}
```