Skip to content

Latest commit

 

History

History
33 lines (22 loc) · 1.16 KB

README.md

File metadata and controls

33 lines (22 loc) · 1.16 KB

refcountmap - a reference counting generic map

GoDoc unit tests report card codecov

Install:

go get github.com/memsql/refcountmap

The idea with refcountmap is that the value for each key is a singleton. When you ask for a value for a specific key, if that key isn't already in the map, then the value is created. If you ask for that same key again, you get another copy of that value. When you're done with a value, you release it. When all copies of the value have been released, the key is removed from the map.

The map is thread-safe.

An example

m := refcountmap.New[string](func() *Thing {
	return &Thing{}
})

thing1 := m.Get("hat")
thing2 := m.Get("hat")

// thing1 and thing2 should be pointers to the same Thing