Struct Set

Set is a data structure that stores unique values without any particular order.

struct Set(T, alias hasher)
  
if (isHashFunction!(hasher, T));

This Set is implemented using closed hashing. Hash collisions are resolved with linear probing.

T should be hashable with hasher. hasher is a callable that accepts an argument of type T and returns a hash value for it (size_t).

Constructors

NameDescription
this (n, allocator) Constructor.
this (init, allocator) Initializes this Set from another one.
this (range, allocator) Initializes the set from a forward range.
this (array, allocator) Initializes the set from a static array.

Properties

NameTypeDescription
allocator[get] shared(Allocator)
bucketCount[get] size_tReturns current bucket count in the container.
capacity[get] size_tMaximum amount of elements this Set can hold without resizing and rehashing. Note that it doesn't mean that the Set will hold exactly capacity elements. capacity tells the size of the container under a best-case distribution of elements.
empty[get] boolTells whether the container contains any elements.
length[get] size_tIterates over the Set and counts the elements.

Methods

NameDescription
clear () Removes all elements.
insert (value) Inserts a new element.
insert (range) Inserts the value from a forward range into the set.
opAssign (that) Assigns another set.
opBinaryRight (value) in operator.
opIndex () Returns a bidirectional range over the container.
rehash (n) Sets the number of buckets in the container to at least n and rearranges all the elements according to their hash values.
remove (value) Removes an element.

Aliases

NameDescription
ConstRange The range types for Set.
Range The range types for Set.

Parameters

NameDescription
T Element type.
hasher Hash function for T.