179 - OZ EnumerableSet
OpenZeppelin EnumerableSet: Library for managing sets of primitive types. Sets have the following properties:
-
Elements are added, removed, and checked for existence in constant time (
O(1)
) -
Elements are enumerated in
O(n)
. No guarantees are made on the ordering. As of v3.3.0, sets of typebytes32
(Bytes32Set
),address
(AddressSet
) anduint256
(UintSet
) are supported. -
add(struct EnumerableSet.Bytes32Set set, bytes32 value)
→bool
: Add a value to a set. Returnstrue
if the value was added to the set, that is if it was not already present. -
remove(struct EnumerableSet.Bytes32Set set, bytes32 value)
→bool
: Removes a value from a set. Returnstrue
if the value was removed from the set, that is if it was present. -
contains(struct EnumerableSet.Bytes32Set set, bytes32 value)
→bool
: Returnstrue
if the value is in the set. -
length(struct EnumerableSet.Bytes32Set set)
→uint256
: Returns the number of values in the set. -
at(struct EnumerableSet.Bytes32Set set, uint256 index)
→bytes32
: Returns the value stored at position index in the set. Note that there are no guarantees on the ordering of values inside the array, and it may change when more values are added or removed. Requirements: index must be strictly less than length. -
add(struct EnumerableSet.AddressSet set, address value)
→bool
: Add a value to a set. Returns true if the value was added to the set, that is if it was not already present. -
remove(struct EnumerableSet.AddressSet set, address value)
→bool
: Removes a value from a set. Returns true if the value was removed from the set, that is if it was present. -
contains(struct EnumerableSet.AddressSet set, address value)
→bool
: Returns true if the value is in the set. length(struct EnumerableSet.AddressSet set) → uint256: Returns the number of values in the set. -
at(struct EnumerableSet.AddressSet set, uint256 index)
→address
: Returns the value stored at position index in the set. Note that there are no guarantees on the ordering of values inside the array, and it may change when more values are added or removed. Requirements: index must be strictly less than length. -
add(struct EnumerableSet.UintSet set, uint256 value)
→bool
: Add a value to a set. Returns true if the value was added to the set, that is if it was not already present. -
remove(struct EnumerableSet.UintSet set, uint256 value)
→bool
: Removes a value from a set. Returns true if the value was removed from the set, that is if it was present. -
contains(struct EnumerableSet.UintSet set, uint256 value)
→bool
: Returns true if the value is in the set. O(1). -
length(struct EnumerableSet.UintSet set)
→uint256
: Returns the number of values on the set. -
at(struct EnumerableSet.UintSet set, uint256 index)
→uint256
: Returns the value stored at position index in the set. Note that there are no guarantees on the ordering of values inside the array, and it may change when more values are added or removed. Requirements: index must be strictly less than length.
- Managing Sets
- Added/Removed/Checked -> o(1)
- Enumerated -> o(n)
- Supported Set Types -> bytes/address/uint256