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.
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: comparableHashTrieMap*concurrent.HashTrieMap[T, weak.Pointer[T]]cloneSeqcloneSeqcloneSeq.stringOffsets[]uintptrHashTrieMap.keyEqualconcurrent.equalFuncHashTrieMap.keyHashconcurrent.hashFuncHashTrieMap.root*concurrent.indirect[T, weak.Pointer[T]]HashTrieMap.seeduintptrHashTrieMap.valEqualconcurrent.equalFunc All returns an iter.Seq2 that produces all key-value pairs in the map.
The enumeration does not represent any consistent snapshot of the map,
but is guaranteed to visit each unique key-value pair only once. It is
safe to operate on the tree during iteration. No particular enumeration
order is guaranteed. CompareAndDelete deletes the entry for key if its value is equal to old.
If there is no current value for key in the map, CompareAndDelete returns false
(even if the old value is the nil interface value). 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. 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. 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.( uniqueMap[K, V]) iter(i *concurrent.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.
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.
The pages are generated with Goldsv0.7.6. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.