Documentation
¶
Overview ¶
Key Concepts:
1. Slot: Entry container.
Neighbourhood: Key could be found in slot which hashed to or next Neighbourhood - 1 slots.
2. Bucket: It's a virtual struct made of neighbourhood slots.
3. Table: An array of buckets.
Index ¶
Constants ¶
const ( // MaxCap is the maximum capacity of Set. // The real max number of keys may be around 0.9 * MaxCap. MaxCap = defaultMaxCap )
Variables ¶
var ( ErrUnsupported = errors.New("unsupported platform, need AVX atomic supports") ErrIsClosed = errors.New("is closed") ErrAddTooFast = errors.New("add too fast") // Cycle being caught up. ErrIsFull = errors.New("set is full") ErrIsSealed = errors.New("is sealed") ErrExisted = errors.New("existed") )
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is unsigned 64-bit integer set. Providing Lock-free Write & Wait-free Read.
func New ¶
New creates a new Set. cap is the set capacity at the beginning, Set will grow if no bucket to add until meet MaxCap.
If cap is zero, using minCap.
func (*Set) Add ¶
Add adds key into Set. Return nil if succeed.
P.S.: It's better to use only one goroutine to Add at the same time, it'll be more friendly for optimistic lock used by Set.
func (*Set) Range ¶
Range calls f sequentially for each key present in the Set. If f returns false, range stops the iteration.
Range does not necessarily correspond to any consistent snapshot of the Set's contents: no key will be visited more than once, but if the value for any key is Added or Removed concurrently, Range may reflect any mapping for that key from any point during the Range call.
Range may be O(N) with the number of elements in the set even if f returns false after a constant number of calls.