Skip to main content

DynamicSet

Overview​

License: MIT​

library DynamicSet

Dynamic Set Library

This library provides implementation of two sets with dynamic data types: BytesSet and StingSet. The library can also be used to create sets that store custom structures via ABI encoding.

Usage example:​

using DynamicSet for DynamicSet.BytesSet;

DynamicSet.BytesSet internal _set;

Structs info​

BytesSet​

struct BytesSet {
DynamicSet.Set _inner;
}

BytesSet *

StringSet​

struct StringSet {
DynamicSet.Set _inner;
}

StringSet *

Set​

struct Set {
bytes[] _values;
mapping(bytes32 => uint256) _indexes;
}

Functions info​

add​

function add(
DynamicSet.BytesSet storage set,
bytes memory value_
) internal returns (bool)

The function to add a bytes value to the set

Parameters:

NameTypeDescription
setstruct DynamicSet.BytesSetThe BytesSet storage reference
value_bytesThe value to be added

Return values:

NameTypeDescription
[0]boolTrue if the value was added successfully, false otherwise

remove​

function remove(
DynamicSet.BytesSet storage set,
bytes memory value_
) internal returns (bool)

The function to remove a bytes value from the set

Parameters:

NameTypeDescription
setstruct DynamicSet.BytesSetThe BytesSet storage reference
value_bytesThe value to be removed

Return values:

NameTypeDescription
[0]boolTrue if the value was removed successfully, false otherwise

contains​

function contains(
DynamicSet.BytesSet storage set,
bytes memory value_
) internal view returns (bool)

The function to check if a value is contained in the set

Parameters:

NameTypeDescription
setstruct DynamicSet.BytesSetThe BytesSet storage reference
value_bytesThe value to be checked

Return values:

NameTypeDescription
[0]boolTrue if the value is contained in the set, false otherwise

length​

function length(
DynamicSet.BytesSet storage set
) internal view returns (uint256)

The function to get the number of values in the set

Parameters:

NameTypeDescription
setstruct DynamicSet.BytesSetThe BytesSet storage reference

Return values:

NameTypeDescription
[0]uint256The number of values in the set

at​

function at(
DynamicSet.BytesSet storage set,
uint256 index_
) internal view returns (bytes memory)

The function to get the value at the specified index in the set

Parameters:

NameTypeDescription
setstruct DynamicSet.BytesSetThe BytesSet storage reference
index_uint256The index of the value to retrieve

Return values:

NameTypeDescription
[0]bytesThe value at the specified index

values​

function values(
DynamicSet.BytesSet storage set
) internal view returns (bytes[] memory)

The function to get an array containing all values in the set

Parameters:

NameTypeDescription
setstruct DynamicSet.BytesSetThe BytesSet storage reference

Return values:

NameTypeDescription
[0]bytes[]An array containing all values in the set

add​

function add(
DynamicSet.StringSet storage set,
string memory value_
) internal returns (bool)

The function to add a string value to the set

Parameters:

NameTypeDescription
setstruct DynamicSet.StringSetThe StringSet storage reference
value_stringThe value to be added

Return values:

NameTypeDescription
[0]boolTrue if the value was added successfully, false otherwise

remove​

function remove(
DynamicSet.StringSet storage set,
string memory value_
) internal returns (bool)

The function to remove a string value from the set

Parameters:

NameTypeDescription
setstruct DynamicSet.StringSetThe StringSet storage reference
value_stringThe value to be removed

Return values:

NameTypeDescription
[0]boolTrue if the value was removed successfully, false otherwise

contains​

function contains(
DynamicSet.StringSet storage set,
string memory value_
) internal view returns (bool)

The function to check if a value is contained in the set

Parameters:

NameTypeDescription
setstruct DynamicSet.StringSetThe StringSet storage reference
value_stringThe value to be checked

Return values:

NameTypeDescription
[0]boolTrue if the value is contained in the set, false otherwise

length​

function length(
DynamicSet.StringSet storage set
) internal view returns (uint256)

The function to get the number of values in the set

Parameters:

NameTypeDescription
setstruct DynamicSet.StringSetThe StringSet storage reference

Return values:

NameTypeDescription
[0]uint256The number of values in the set

at​

function at(
DynamicSet.StringSet storage set,
uint256 index_
) internal view returns (string memory)

The function to get the value at the specified index in the set

Parameters:

NameTypeDescription
setstruct DynamicSet.StringSetThe StringSet storage reference
index_uint256The index of the value to retrieve

Return values:

NameTypeDescription
[0]stringThe value at the specified index

values​

function values(
DynamicSet.StringSet storage set
) internal view returns (string[] memory values_)

The function to get an array containing all values in the set

Parameters:

NameTypeDescription
setstruct DynamicSet.StringSetThe StringSet storage reference

Return values:

NameTypeDescription
values_string[]An array containing all values in the set

_add​

function _add(
DynamicSet.Set storage set,
bytes memory value_
) internal returns (bool)

_remove​

function _remove(
DynamicSet.Set storage set,
bytes memory value_
) internal returns (bool)

_contains​

function _contains(
DynamicSet.Set storage set,
bytes memory value_
) internal view returns (bool)

_length​

function _length(DynamicSet.Set storage set) internal view returns (uint256)

_at​

function _at(
DynamicSet.Set storage set,
uint256 index_
) internal view returns (bytes memory)

_values​

function _values(
DynamicSet.Set storage set
) internal view returns (bytes[] memory)