Skip to content

Commit d986887

Browse files
authored
Added lib docs (#27)
* added docs * fix
1 parent 14974fe commit d986887

File tree

2 files changed

+137
-1
lines changed

2 files changed

+137
-1
lines changed

docs/getting-started/guides/libs/arrays/array-helper.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ function reverse(
146146
) internal pure returns (address[] memory reversed_);
147147
```
148148

149+
```solidity
150+
function reverse(
151+
bool[] memory arr_
152+
) internal pure returns (address[] memory reversed_);
153+
```
154+
149155
```solidity
150156
function reverse(
151157
string[] memory arr_
@@ -197,6 +203,14 @@ function insert(
197203
) internal pure returns (uint256);
198204
```
199205

206+
```solidity
207+
function insert(
208+
bool[] memory to_,
209+
uint256 index_,
210+
bool[] memory what_
211+
) internal pure returns (uint256);
212+
```
213+
200214
```solidity
201215
function insert(
202216
string[] memory to_,

docs/getting-started/guides/libs/arrays/set-helper.md

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,73 @@ function add(
3636

3737
```solidity
3838
function add(
39+
EnumerableSet.Bytes32Set storage set,
40+
bytes32[] memory array_
41+
) internal;
42+
```
43+
44+
```solidity
45+
function add(
46+
StringSet.Set storage set,
47+
string[] memory array_
48+
) internal;
49+
```
50+
51+
#### Description
52+
53+
This function adds the provided `array_` to the provided `set`. Parameter `set` is always a **storage** array, whereas `array_` is a **memory** array.
54+
55+
#### Time complexity
56+
57+
Linear.
58+
59+
#### Example
60+
61+
```solidity
62+
EnumerableSet.UintSet public nums;
63+
nums.add(1);
64+
nums.add(2);
65+
66+
uint256[] memory arr_ = new uint256[](2);
67+
arr_[0] = 3;
68+
arr_[1] = 4;
69+
70+
nums.add(arr_); // [1, 2, 3, 4]
71+
```
72+
73+
### strictAdd
74+
75+
```solidity
76+
function strictAdd(
77+
EnumerableSet.AddressSet storage set,
78+
address[] memory array_
79+
) internal;
80+
```
81+
82+
```solidity
83+
function strictAdd(
84+
EnumerableSet.UintSet storage set,
85+
uint256[] memory array_
86+
) internal;
87+
```
88+
89+
```solidity
90+
function strictAdd(
91+
EnumerableSet.Bytes32Set storage set,
92+
bytes32[] memory array_
93+
) internal;
94+
```
95+
96+
```solidity
97+
function strictAdd(
3998
StringSet.Set storage set,
4099
string[] memory array_
41100
) internal;
42101
```
43102

44103
#### Description
45104

46-
This function adds the provided `array_` to the provided `set`.
105+
This function strictly adds the provided `array_` to the provided `set`. Parameter `set` is always a **storage** array, whereas `array_` is a **memory** array. Reverts if elements duplicate.
47106

48107
#### Time complexity
49108

@@ -61,6 +120,7 @@ arr_[0] = 3;
61120
arr_[1] = 4;
62121
63122
nums.add(arr_); // [1, 2, 3, 4]
123+
nums.add(arr_); // Reverts with: "SetHelper: element already exists"
64124
```
65125

66126
### remove
@@ -79,6 +139,13 @@ function remove(
79139
) internal;
80140
```
81141

142+
```solidity
143+
function remove(
144+
EnumerableSet.Bytes32Set storage set,
145+
bytes32[] memory array_
146+
) internal;
147+
```
148+
82149
```solidity
83150
function remove(
84151
StringSet.Set storage set,
@@ -111,3 +178,58 @@ arr_[3] = 10;
111178
112179
nums.remove(arr_); // [2, 4]
113180
```
181+
182+
### strictRemove
183+
184+
```solidity
185+
function strictRemove(
186+
EnumerableSet.AddressSet storage set,
187+
address[] memory array_
188+
) internal;
189+
```
190+
191+
```solidity
192+
function strictRemove(
193+
EnumerableSet.UintSet storage set,
194+
uint256[] memory array_
195+
) internal;
196+
```
197+
198+
```solidity
199+
function strictRemove(
200+
EnumerableSet.Bytes32Set storage set,
201+
bytes32[] memory array_
202+
) internal;
203+
```
204+
205+
```solidity
206+
function strictRemove(
207+
StringSet.Set storage set,
208+
string[] memory array_
209+
) internal;
210+
```
211+
212+
#### Description
213+
214+
This function strictly removes the provided `array_` from the provided `set`. Parameter `set` is always a **storage** array, whereas `array_` is a **memory** array. Reverts if set doesn't contain provided elements.
215+
216+
#### Time complexity
217+
218+
Linear.
219+
220+
#### Example
221+
222+
```solidity
223+
EnumerableSet.UintSet public nums;
224+
nums.add(1);
225+
nums.add(2);
226+
nums.add(3);
227+
nums.add(4);
228+
229+
uint256[] memory arr_ = new uint256[](4);
230+
arr_[0] = 1;
231+
arr_[1] = 3;
232+
233+
nums.remove(arr_); // [2, 4]
234+
nums.remove(arr_); // Reverts with: "SetHelper: no such element"
235+
```

0 commit comments

Comments
 (0)