You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/getting-started/guides/libs/arrays/set-helper.md
+123-1Lines changed: 123 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -36,14 +36,73 @@ function add(
36
36
37
37
```solidity
38
38
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(
39
98
StringSet.Set storage set,
40
99
string[] memory array_
41
100
) internal;
42
101
```
43
102
44
103
#### Description
45
104
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.
47
106
48
107
#### Time complexity
49
108
@@ -61,6 +120,7 @@ arr_[0] = 3;
61
120
arr_[1] = 4;
62
121
63
122
nums.add(arr_); // [1, 2, 3, 4]
123
+
nums.add(arr_); // Reverts with: "SetHelper: element already exists"
64
124
```
65
125
66
126
### remove
@@ -79,6 +139,13 @@ function remove(
79
139
) internal;
80
140
```
81
141
142
+
```solidity
143
+
function remove(
144
+
EnumerableSet.Bytes32Set storage set,
145
+
bytes32[] memory array_
146
+
) internal;
147
+
```
148
+
82
149
```solidity
83
150
function remove(
84
151
StringSet.Set storage set,
@@ -111,3 +178,58 @@ arr_[3] = 10;
111
178
112
179
nums.remove(arr_); // [2, 4]
113
180
```
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"
0 commit comments