Skip to content

Commit 8d8b457

Browse files
committed
keys & values functions
1 parent cc51e31 commit 8d8b457

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

contracts/data/EnumerableMap.sol

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,70 @@ library EnumerableMap {
177177
}
178178
}
179179

180+
function keys(AddressToAddressMap storage map)
181+
internal
182+
view
183+
returns (address[] memory keys)
184+
{
185+
uint256 len = map._inner._entries.length;
186+
keys = new address[](len);
187+
188+
unchecked {
189+
for (uint256 i; i < len; ++i) {
190+
keys[i] = address(
191+
uint160(uint256(map._inner._entries[i]._key))
192+
);
193+
}
194+
}
195+
}
196+
197+
function keys(UintToAddressMap storage map)
198+
internal
199+
view
200+
returns (uint256[] memory keys)
201+
{
202+
uint256 len = map._inner._entries.length;
203+
keys = new uint256[](len);
204+
205+
unchecked {
206+
for (uint256 i; i < len; ++i) {
207+
keys[i] = uint256(map._inner._entries[i]._key);
208+
}
209+
}
210+
}
211+
212+
function values(AddressToAddressMap storage map)
213+
internal
214+
view
215+
returns (address[] memory values)
216+
{
217+
uint256 len = map._inner._entries.length;
218+
values = new address[](len);
219+
unchecked {
220+
for (uint256 i; i < len; ++i) {
221+
values[i] = address(
222+
uint160(uint256(map._inner._entries[i]._value))
223+
);
224+
}
225+
}
226+
}
227+
228+
function values(UintToAddressMap storage map)
229+
internal
230+
view
231+
returns (address[] memory values)
232+
{
233+
uint256 len = map._inner._entries.length;
234+
values = new address[](len);
235+
unchecked {
236+
for (uint256 i; i < len; ++i) {
237+
values[i] = address(
238+
uint160(uint256(map._inner._entries[i]._value))
239+
);
240+
}
241+
}
242+
}
243+
180244
function _at(Map storage map, uint256 index)
181245
private
182246
view

0 commit comments

Comments
 (0)