Skip to content

Commit d975595

Browse files
committed
toArray function
1 parent f674279 commit d975595

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

contracts/data/EnumerableMap.sol

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,44 @@ library EnumerableMap {
139139
return _remove(map._inner, bytes32(key));
140140
}
141141

142+
function toArray(AddressToAddressMap storage map)
143+
internal
144+
view
145+
returns (address[] memory keys, address[] memory values)
146+
{
147+
uint256 len = map._inner._entries.length;
148+
keys = new address[](len);
149+
values = new address[](len);
150+
unchecked {
151+
for (uint256 i; i < len; ++i) {
152+
keys[i] = address(
153+
uint160(uint256(map._inner._entries[i]._key))
154+
);
155+
values[i] = address(
156+
uint160(uint256(map._inner._entries[i]._value))
157+
);
158+
}
159+
}
160+
}
161+
162+
function toArray(UintToAddressMap storage map)
163+
internal
164+
view
165+
returns (uint256[] memory keys, address[] memory values)
166+
{
167+
uint256 len = map._inner._entries.length;
168+
keys = new uint256[](len);
169+
values = new address[](len);
170+
unchecked {
171+
for (uint256 i; i < len; ++i) {
172+
keys[i] = uint256(map._inner._entries[i]._key);
173+
values[i] = address(
174+
uint160(uint256(map._inner._entries[i]._value))
175+
);
176+
}
177+
}
178+
}
179+
142180
function _at(Map storage map, uint256 index)
143181
private
144182
view

0 commit comments

Comments
 (0)