Uint16Set
based on https://github.com/rob-Hitchens/SetTypes/blob/master/contracts/UintSet.sol
Key sets with enumeration and delete. Uses mappings for random and existence checks and dynamic arrays for enumeration. Key uniqueness is enforced.
Sets are unordered. Delete operations reorder keys. All operations have a fixed gas cost at any scale, O(1). author: Rob Hitchens
Functions
insert
insert a key.
duplicate keys are not permitted.
function insert(Set storage self, uint16 key) internal returns (bool keyaAlreadyExists);
Parameters
Name | Type | Description |
---|---|---|
self | Set | storage pointer to a Set. |
key | uint16 | value to insert. |
Returns
Name | Type | Description |
---|---|---|
keyaAlreadyExists | bool | whether the key already existed in the set |
remove
remove a key.
key to remove must exist.
function remove(Set storage self, uint16 key) internal returns (bool keyDidNotExist);
Parameters
Name | Type | Description |
---|---|---|
self | Set | storage pointer to a Set. |
key | uint16 | value to remove. |
Returns
Name | Type | Description |
---|---|---|
keyDidNotExist | bool | whether the key already did not yet exist in the set |
count
count the keys.
function count(
Set storage self
) internal view returns (uint16);
Parameters
Name | Type | Description |
---|---|---|
self | Set | storage pointer to a Set. |
exists
check if a key is in the Set.
function exists(Set storage self, uint16 key) internal view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
self | Set | storage pointer to a Set. |
key | uint16 | value to check. |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool true: Set member, false: not a Set member. |
Structs
Set
struct Set {
mapping(uint16 => uint16) keyPointers;
uint16[] keyList;
}