Involved Source Filesclone.go The unique package provides facilities for canonicalizing ("interning")
comparable values.handle.go
Package-Level Type Names (total 3, in which 1 is exported)
/* sort exporteds by: | */
Type Parameters:
T: comparable Handle is a globally unique identity for some value of type T.
Two handles compare equal exactly if the two values used to create the handles
would have also compared equal. The comparison of two handles is trivial and
typically much more efficient than comparing the values used to create them.value*T Value returns a shallow copy of the T value that produced the Handle.
Value is safe for concurrent use by multiple goroutines.
func Make[T](value T) Handle[T]
var net/netip.z0unique.Handle[addrDetail]
var net/netip.z4unique.Handle[...]
var net/netip.z6nozunique.Handle[...]
Type Parameters:
T: comparableHashTrieMapisync.HashTrieMap[T, weak.Pointer[T]]cloneSeqcloneSeqcloneSeq.stringOffsets[]uintptrHashTrieMap.initMusync.MutexHashTrieMap.initedatomic.Uint32HashTrieMap.keyHashsync.hashFuncHashTrieMap.rootatomic.Pointer[sync.indirect[T, weak.Pointer[T]]]HashTrieMap.seeduintptrHashTrieMap.valEqualsync.equalFunc All returns an iterator over each key and value present in the map.
The iterator does not necessarily correspond to any consistent snapshot of the
HashTrieMap's contents: no key will be visited more than once, but if the value
for any key is stored or deleted concurrently (including by yield), the iterator
may reflect any mapping for that key from any point during iteration. The iterator
does not block other methods on the receiver; even yield itself may call any
method on the HashTrieMap. Clear deletes all the entries, resulting in an empty HashTrieMap. CompareAndDelete deletes the entry for key if its value is equal to old.
The value type must be comparable, otherwise this CompareAndDelete will panic.
If there is no current value for key in the map, CompareAndDelete returns false
(even if the old value is the nil interface value). CompareAndSwap swaps the old and new values for key
if the value stored in the map is equal to old.
The value type must be of a comparable type, otherwise CompareAndSwap will panic. Delete deletes the value for a key. Load returns the value stored in the map for a key, or nil if no
value is present.
The ok result indicates whether value was found in the map. LoadAndDelete deletes the value for a key, returning the previous value if any.
The loaded result reports whether the key was present. LoadOrStore returns the existing value for the key if present.
Otherwise, it stores and returns the given value.
The loaded result is true if the value was loaded, false if stored. Range calls f sequentially for each key and value present in the map.
If f returns false, range stops the iteration.
This exists for compatibility with sync.Map; All should be preferred.
It provides the same guarantees as sync.Map, and All. Store sets the value for a key. Swap swaps the value for a key and returns the previous value if any.
The loaded result reports whether the key was present. expand takes oldEntry and newEntry whose hashes conflict from bit 64 down to hashShift and
produces a subtree of indirect nodes to hold the two new entries. find searches the tree for a node that contains key (hash must be the hash of key).
If valEqual != nil, then it will also enforce that the values are equal as well.
Returns a non-nil node, which will always be an entry, if found.
If i != nil then i.mu is locked, and it is the caller's responsibility to unlock it.(*uniqueMap[K, V]) init()(*uniqueMap[K, V]) initSlow()(*uniqueMap[K, V]) iter(i *sync.indirect[T, weak.Pointer[T]], yield func(key T, value weak.Pointer[T]) bool) bool
func addUniqueMap[T](typ *abi.Type) *uniqueMap[T]
Package-Level Functions (total 8, in which 1 is exported)
Type Parameters:
T: comparable Make returns a globally unique handle for a value of type T. Handles
are equal if and only if the values used to produce them are equal.
Make is safe for concurrent use by multiple goroutines.
buildArrayCloneSeq populates a cloneSeq for an abi.Type that has Kind abi.Array.
buildStructCloneSeq populates a cloneSeq for an abi.Type that has Kind abi.Struct.
Type Parameters:
T: comparable clone makes a copy of value, and may update string values found in value
with a cloned version of those strings. The purpose of explicitly cloning
strings is to avoid accidentally giving a large string a long lifetime.
Note that this will clone strings in structs and arrays found in value,
and will clone value if it itself is a string. It will not, however, clone
strings if value is of interface or slice type (that is, found via an
indirection).
makeCloneSeq creates a cloneSeq for a type.
startBackgroundCleanup sets up a background goroutine to occasionally call cleanupFuncs.
cleanupFuncs are functions that clean up dead weak pointers in type-specific
maps in uniqueMaps. We express cleanup this way because there's no way to iterate
over the sync.Map and call functions on the type-specific data structures otherwise.
These cleanup funcs each close over one of these type-specific maps.
cleanupMu protects cleanupNotify and is held across the entire cleanup. Used for testing.
cleanupNotify is a test-only mechanism that allow tests to wait for the cleanup to run.
varcleanupNotify []func() // One-time notifications when cleanups finish.
setupMake is used to perform initial setup for unique.Make.
singleStringClone describes how to clone a single string.
uniqueMaps is an index of type-specific concurrent maps used for unique.Make.
The two-level map might seem odd at first since the HashTrieMap could have "any"
as its key type, but the issue is escape analysis. We do not want to force lookups
to escape the argument, and using a type-specific map allows us to avoid that where
possible (for example, for strings and plain-ol'-data structs). We also get the
benefit of not cramming every different type into a single map, but that's certainly
not enough to outweigh the cost of two map lookups. What is worth it though, is saving
on those allocations.