Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

dolthub/swiss

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9ab8df3 · Mar 7, 2025

History

29 Commits
Feb 28, 2023
Mar 28, 2023
Feb 23, 2023
Feb 23, 2023
Mar 7, 2025
Mar 12, 2024
Mar 12, 2024
Mar 28, 2023
Mar 12, 2024
Mar 12, 2024
Apr 3, 2023
Apr 3, 2023
Mar 12, 2024
Apr 2, 2023
Mar 28, 2023
Aug 28, 2023

Repository files navigation

This Repository Is Archived

This repository has been archived. Go 1.24+ uses swiss tables for its native maps. Please see our announcement blog about our decision to archive dolthub/swiss.

SwissMap

SwissMap is a hash table adapated from the "SwissTable" family of hash tables from Abseil. It uses AES instructions for fast-hashing and performs key lookups in parallel using SSE 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 announcing its release.

Example

SwissMap exposes the same interface as the built-in map. Give it a try using this Go playground.

package main

import "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
}