MCPcopy Create free account
hub / github.com/cockroachdb/swiss / Map

Struct Map

map.go:283–312  ·  view source on GitHub ↗

Map is an unordered map from keys to values with Put, Get, Delete, and All operations. Map is inspired by Google's Swiss Tables design as implemented in Abseil's flat_hash_map, combined with extendible hashing. By default, a Map[K,V] uses the same hash function as Go's builtin map[K]V, though a diff

Source from the content-addressed store, hash-verified

281//
282// A Map is NOT goroutine-safe.
283type Map[K comparable, V any] struct {
284 // The hash function to each keys of type K. The hash function is
285 // extracted from the Go runtime's implementation of map[K]struct{}.
286 hash hashFn
287 seed uintptr
288 // The allocator to use for the ctrls and slots slices.
289 allocator Allocator[K, V]
290 // bucket0 is always present and inlined in the Map to avoid a pointer
291 // indirection during the common case that the map contains a single
292 // bucket. bucket0 is also used during split operations as a temporary
293 // bucket to split into before the bucket is installed in the directory.
294 bucket0 bucket[K, V]
295 // The directory of buckets. See the comment on bucket.index for details
296 // on how the physical bucket values map to logical buckets.
297 dir unsafeSlice[bucket[K, V]]
298 // The number of filled slots across all buckets (i.e. the number of
299 // elements in the map).
300 used int
301 // globalShift is the number of bits to right shift a hash value to
302 // generate an index for the global directory. As a special case, if
303 // globalShift==0 then bucket0 is used and the directory is not accessed.
304 // Note that globalShift==(64-globalDepth). globalShift is used rather
305 // than globalDepth because the shifting is the more common operation than
306 // needing to compare globalDepth to a bucket's localDepth.
307 globalShift uint32
308 // The maximum capacity a bucket is allowed to grow to before it will be
309 // split.
310 maxBucketCapacity uint32
311 _ noCopy
312}
313
314// normalizeCapacity rounds capacity to the next power of 2.
315func normalizeCapacity(capacity uint32) uint32 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected