Unordered Set¶
| Spice | |
|---|---|
UnorderedSet<V> struct¶
Implements: IIterable<V>
An unordered set in Spice is a commonly used data structure, which can be used to represent a list of unique values.
Time complexity:
Insert: O(1) (average case), O(n) (worst case)
Delete: O(1) (average case), O(n) (worst case)
Lookup: O(1) (average case), O(n) (worst case)
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct an empty unordered set with the given number of buckets
Parameters
| Name | Type | Description |
|---|---|---|
bucketCount |
unsigned long |
Number of buckets in the underlying hash table (default: 100l) |
Methods¶
insert¶
| Spice | |
|---|---|
Insert a value into the set. If the value already exists, nothing happens.
Parameters
| Name | Type | Description |
|---|---|---|
value |
const V& |
The value to insert |
contains¶
| Spice | |
|---|---|
Check if the set contains the given value.
Parameters
| Name | Type | Description |
|---|---|---|
value |
const V& |
The value to check |
Returns: bool — true if the value is in the set, false otherwise
remove¶
| Spice | |
|---|---|
Remove a value from the set. If the value does not exist, nothing happens.
Parameters
| Name | Type | Description |
|---|---|---|
value |
const V& |
The value to remove |
clear¶
| Spice | |
|---|---|
Clear all values from the set.
getSize¶
| Spice | |
|---|---|
Get the number of elements in the set.
Returns: unsigned long — The number of elements in the set
isEmpty¶
| Spice | |
|---|---|
Check if the set is empty.
Returns: bool — true if the set is empty, false otherwise
toLinkedList¶
| Spice | |
|---|---|
Get all elements in the set as a list.
Returns: LinkedList<V> — A linked list of all elements in the set
getIterator¶
| Spice | |
|---|---|
Retrieve a forward iterator for the unordered set
Returns: UnorderedSetIterator<V>
UnorderedSetIterator<V> struct¶
Implements: IIterator<const V&>
Iterator to iterate over an unordered set data structure
Constructors¶
ctor¶
| Spice | |
|---|---|
Construct an unordered set iterator over the given unordered set
Parameters
| Name | Type | Description |
|---|---|---|
unorderedSet |
UnorderedSet<V>& |
Unordered set to iterate over |
Methods¶
get¶
| Spice | |
|---|---|
Returns the current value of the unordered set
Returns: const V& — Current value
getIdx¶
| Spice | |
|---|---|
Returns the current index and the current item of the unordered set
Returns: Pair<unsigned long, const V&> — Pair of current index and current key/value pair
isValid¶
| Spice | |
|---|---|
Check if the iterator is valid
Returns: bool — true or false
next¶
| Spice | |
|---|---|
Moves the cursor to the next key/value pair
Operators¶
operator++¶
| Spice | |
|---|---|
Advances the cursor by one
Parameters
| Name | Type | Description |
|---|---|---|
it |
UnorderedSetIterator<V>& |
UnorderedSetIterator |