github.com/dolthub/swiss@v0.2.2-0.20240312182618-f4b2babd2bc1/README.md (about)

     1  # SwissMap
     2  
     3  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.
     4  
     5  
     6  ## Example
     7  
     8  SwissMap exposes the same interface as the built-in `map`. Give it a try using this [Go playground](https://go.dev/play/p/JPDC5WhYN7g).
     9  
    10  ```go
    11  package main
    12  
    13  import "github.com/dolthub/swiss"
    14  
    15  func main() {
    16  	m := swiss.NewMap[string, int](42)
    17  
    18  	m.Put("foo", 1)
    19  	m.Put("bar", 2)
    20  
    21  	m.Iter(func(k string, v int) (stop bool) {
    22  		println("iter", k, v)
    23  		return false // continue
    24  	})
    25  
    26  	if x, ok := m.Get("foo"); ok {
    27  		println(x)
    28  	}
    29  	if m.Has("bar") {
    30  		x, _ := m.Get("bar")
    31  		println(x)
    32  	}
    33  
    34  	m.Put("foo", -1)
    35  	m.Delete("bar")
    36  
    37  	if x, ok := m.Get("foo"); ok {
    38  		println(x)
    39  	}
    40  	if m.Has("bar") {
    41  		x, _ := m.Get("bar")
    42  		println(x)
    43  	}
    44  
    45  	m.Clear()
    46  
    47  	// Output:
    48  	// iter foo 1
    49  	// iter bar 2
    50  	// 1
    51  	// 2
    52  	// -1
    53  }
    54  ```