Skip to content

smallnest/safemap

 
 

Repository files navigation

safemap Build Status

一个线程安全的,支持泛型的,高性能的map库。基于orcaman/concurrent-map的实现和github.com/dolthub/maphash的hash算法。

usage

Import the package:

import (
	"github.com/smallnest/safemap"
)
go get github.com/smallnest/safemap@latest

The package is now imported under the "safemap" namespace.

example

	// Create a new map (K type is string, and V type is string too).
	m := safemap.New[string,string]()

	// Sets item within map, sets "bar" under key "foo"
	m.Set("foo", "bar")

	// Retrieve item from map.
	bar, ok := m.Get("foo")

	// Removes item under key "foo"
	m.Remove("foo")

	//  Create a new map (K type is int, and V type is string too).
	m2 := safemap.New[int,string]()

	// Sets item within map, sets "bar" under key 1
	m2.Set(1, "bar")

	// Retrieve item from map.
	bar, ok = m2.Get(1)

	// Removes item under key 1
	m2.Remove(1)

For more examples have a look at safemap_test.go.

Running tests:

go test github.com/smallnest/safemap

license

MIT (see LICENSE file)

About

a thread-safe concurrent map for go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Go 100.0%