Skip to content

Latest commit

 

History

History
47 lines (32 loc) · 3.45 KB

OZ EnumerableSet.md

File metadata and controls

47 lines (32 loc) · 3.45 KB

OpenZeppelin EnumerableSet: Library for managing sets of primitive types. Sets have the following properties:

  1. Elements are added, removed, and checked for existence in constant time (O(1))

  2. Elements are enumerated in O(n). No guarantees are made on the ordering. As of v3.3.0, sets of type bytes32 (Bytes32Set), address (AddressSet) and uint256 (UintSet) are supported.

  3. add(struct EnumerableSet.Bytes32Set set, bytes32 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.

  4. remove(struct EnumerableSet.Bytes32Set set, bytes32 value)bool: Removes a value from a set. Returns true if the value was removed from the set, that is if it was present.

  5. contains(struct EnumerableSet.Bytes32Set set, bytes32 value)bool: Returns true if the value is in the set.

  6. length(struct EnumerableSet.Bytes32Set set)uint256: Returns the number of values in the set.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

  11. 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.

  12. 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.

  13. 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.

  14. contains(struct EnumerableSet.UintSet set, uint256 value)bool: Returns true if the value is in the set. O(1).

  15. length(struct EnumerableSet.UintSet set)uint256: Returns the number of values on the set.

  16. 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.


Slide Screenshot

179.jpg


Slide Text

  • Managing Sets
  • Added/Removed/Checked -> o(1)
  • Enumerated -> o(n)
  • Supported Set Types -> bytes/address/uint256

References


Tags