File tree Expand file tree Collapse file tree 5 files changed +709
-0
lines changed Expand file tree Collapse file tree 5 files changed +709
-0
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,57 @@ library EnumerableSet {
150150 return _remove (set._inner, bytes32 (value));
151151 }
152152
153+ function toArray (Bytes32Set storage set )
154+ internal
155+ view
156+ returns (bytes32 [] memory )
157+ {
158+ uint256 len = _length (set._inner);
159+ bytes32 [] memory arr = new bytes32 [](len);
160+
161+ unchecked {
162+ for (uint256 index; index < len; ++ index) {
163+ arr[index] = at (set, index);
164+ }
165+ }
166+
167+ return arr;
168+ }
169+
170+ function toArray (AddressSet storage set )
171+ internal
172+ view
173+ returns (address [] memory )
174+ {
175+ uint256 len = _length (set._inner);
176+ address [] memory arr = new address [](len);
177+
178+ unchecked {
179+ for (uint256 index; index < len; ++ index) {
180+ arr[index] = at (set, index);
181+ }
182+ }
183+
184+ return arr;
185+ }
186+
187+ function toArray (UintSet storage set )
188+ internal
189+ view
190+ returns (uint256 [] memory )
191+ {
192+ uint256 len = _length (set._inner);
193+ uint256 [] memory arr = new uint256 [](len);
194+
195+ unchecked {
196+ for (uint256 index; index < len; ++ index) {
197+ arr[index] = at (set, index);
198+ }
199+ }
200+
201+ return arr;
202+ }
203+
153204 function _at (Set storage set , uint256 index )
154205 private
155206 view
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: MIT
2+
3+ pragma solidity ^ 0.8.8 ;
4+
5+ import { EnumerableSet } from './EnumerableSet.sol ' ;
6+
7+ contract EnumerableSetAddressMock {
8+ using EnumerableSet for EnumerableSet.AddressSet;
9+
10+ EnumerableSet.AddressSet internal addressSet;
11+
12+ function at (uint256 index ) external view returns (address ) {
13+ return addressSet.at (index);
14+ }
15+
16+ function contains (address value ) external view returns (bool ) {
17+ return addressSet.contains (value);
18+ }
19+
20+ function indexOf (address value ) external view returns (uint256 ) {
21+ return addressSet.indexOf (value);
22+ }
23+
24+ function length () external view returns (uint256 ) {
25+ return addressSet.length ();
26+ }
27+
28+ function add (address value ) external returns (bool ) {
29+ return addressSet.add (value);
30+ }
31+
32+ function remove (address value ) external returns (bool ) {
33+ return addressSet.remove (value);
34+ }
35+
36+ function toArray () external view returns (address [] memory ) {
37+ return addressSet.toArray ();
38+ }
39+ }
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: MIT
2+
3+ pragma solidity ^ 0.8.8 ;
4+
5+ import { EnumerableSet } from './EnumerableSet.sol ' ;
6+
7+ contract EnumerableSetBytes32Mock {
8+ using EnumerableSet for EnumerableSet.Bytes32Set;
9+
10+ EnumerableSet.Bytes32Set internal bytes32Set;
11+
12+ function at (uint256 index ) external view returns (bytes32 ) {
13+ return bytes32Set.at (index);
14+ }
15+
16+ function contains (bytes32 value ) external view returns (bool ) {
17+ return bytes32Set.contains (value);
18+ }
19+
20+ function indexOf (bytes32 value ) external view returns (uint256 ) {
21+ return bytes32Set.indexOf (value);
22+ }
23+
24+ function length () external view returns (uint256 ) {
25+ return bytes32Set.length ();
26+ }
27+
28+ function add (bytes32 value ) external returns (bool ) {
29+ return bytes32Set.add (value);
30+ }
31+
32+ function remove (bytes32 value ) external returns (bool ) {
33+ return bytes32Set.remove (value);
34+ }
35+
36+ function toArray () external view returns (bytes32 [] memory ) {
37+ return bytes32Set.toArray ();
38+ }
39+ }
Original file line number Diff line number Diff line change 1+ // SPDX-License-Identifier: MIT
2+
3+ pragma solidity ^ 0.8.8 ;
4+
5+ import { EnumerableSet } from './EnumerableSet.sol ' ;
6+
7+ contract EnumerableSetUintMock {
8+ using EnumerableSet for EnumerableSet.UintSet;
9+
10+ EnumerableSet.UintSet internal uintSet;
11+
12+ function at (uint256 index ) external view returns (uint256 ) {
13+ return uintSet.at (index);
14+ }
15+
16+ function contains (uint256 value ) external view returns (bool ) {
17+ return uintSet.contains (value);
18+ }
19+
20+ function indexOf (uint256 value ) external view returns (uint256 ) {
21+ return uintSet.indexOf (value);
22+ }
23+
24+ function length () external view returns (uint256 ) {
25+ return uintSet.length ();
26+ }
27+
28+ function add (uint256 value ) external returns (bool ) {
29+ return uintSet.add (value);
30+ }
31+
32+ function remove (uint256 value ) external returns (bool ) {
33+ return uintSet.remove (value);
34+ }
35+
36+ function toArray () external view returns (uint256 [] memory ) {
37+ return uintSet.toArray ();
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments