@@ -156,6 +156,18 @@ library EnumerableMap {
156
156
return value;
157
157
}
158
158
159
+ /**
160
+ * @dev Return the an array containing all the keys
161
+ *
162
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
163
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
164
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
165
+ * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
166
+ */
167
+ function keys (Bytes32ToBytes32Map storage map ) internal view returns (bytes32 [] memory ) {
168
+ return map._keys.values ();
169
+ }
170
+
159
171
// UintToUintMap
160
172
161
173
struct UintToUintMap {
@@ -174,7 +186,7 @@ library EnumerableMap {
174
186
}
175
187
176
188
/**
177
- * @dev Removes a value from a set . O(1).
189
+ * @dev Removes a value from a map . O(1).
178
190
*
179
191
* Returns true if the key was removed from the map, that is if it was present.
180
192
*/
@@ -197,7 +209,7 @@ library EnumerableMap {
197
209
}
198
210
199
211
/**
200
- * @dev Returns the element stored at position `index` in the set . O(1).
212
+ * @dev Returns the element stored at position `index` in the map . O(1).
201
213
* Note that there are no guarantees on the ordering of values inside the
202
214
* array, and it may change when more values are added or removed.
203
215
*
@@ -240,6 +252,26 @@ library EnumerableMap {
240
252
return uint256 (get (map._inner, bytes32 (key), errorMessage));
241
253
}
242
254
255
+ /**
256
+ * @dev Return the an array containing all the keys
257
+ *
258
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
259
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
260
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
261
+ * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
262
+ */
263
+ function keys (UintToUintMap storage map ) internal view returns (uint256 [] memory ) {
264
+ bytes32 [] memory store = keys (map._inner);
265
+ uint256 [] memory result;
266
+
267
+ /// @solidity memory-safe-assembly
268
+ assembly {
269
+ result := store
270
+ }
271
+
272
+ return result;
273
+ }
274
+
243
275
// UintToAddressMap
244
276
245
277
struct UintToAddressMap {
@@ -258,7 +290,7 @@ library EnumerableMap {
258
290
}
259
291
260
292
/**
261
- * @dev Removes a value from a set . O(1).
293
+ * @dev Removes a value from a map . O(1).
262
294
*
263
295
* Returns true if the key was removed from the map, that is if it was present.
264
296
*/
@@ -281,7 +313,7 @@ library EnumerableMap {
281
313
}
282
314
283
315
/**
284
- * @dev Returns the element stored at position `index` in the set . O(1).
316
+ * @dev Returns the element stored at position `index` in the map . O(1).
285
317
* Note that there are no guarantees on the ordering of values inside the
286
318
* array, and it may change when more values are added or removed.
287
319
*
@@ -328,6 +360,26 @@ library EnumerableMap {
328
360
return address (uint160 (uint256 (get (map._inner, bytes32 (key), errorMessage))));
329
361
}
330
362
363
+ /**
364
+ * @dev Return the an array containing all the keys
365
+ *
366
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
367
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
368
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
369
+ * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
370
+ */
371
+ function keys (UintToAddressMap storage map ) internal view returns (uint256 [] memory ) {
372
+ bytes32 [] memory store = keys (map._inner);
373
+ uint256 [] memory result;
374
+
375
+ /// @solidity memory-safe-assembly
376
+ assembly {
377
+ result := store
378
+ }
379
+
380
+ return result;
381
+ }
382
+
331
383
// AddressToUintMap
332
384
333
385
struct AddressToUintMap {
@@ -346,7 +398,7 @@ library EnumerableMap {
346
398
}
347
399
348
400
/**
349
- * @dev Removes a value from a set . O(1).
401
+ * @dev Removes a value from a map . O(1).
350
402
*
351
403
* Returns true if the key was removed from the map, that is if it was present.
352
404
*/
@@ -369,7 +421,7 @@ library EnumerableMap {
369
421
}
370
422
371
423
/**
372
- * @dev Returns the element stored at position `index` in the set . O(1).
424
+ * @dev Returns the element stored at position `index` in the map . O(1).
373
425
* Note that there are no guarantees on the ordering of values inside the
374
426
* array, and it may change when more values are added or removed.
375
427
*
@@ -416,6 +468,26 @@ library EnumerableMap {
416
468
return uint256 (get (map._inner, bytes32 (uint256 (uint160 (key))), errorMessage));
417
469
}
418
470
471
+ /**
472
+ * @dev Return the an array containing all the keys
473
+ *
474
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
475
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
476
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
477
+ * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
478
+ */
479
+ function keys (AddressToUintMap storage map ) internal view returns (address [] memory ) {
480
+ bytes32 [] memory store = keys (map._inner);
481
+ address [] memory result;
482
+
483
+ /// @solidity memory-safe-assembly
484
+ assembly {
485
+ result := store
486
+ }
487
+
488
+ return result;
489
+ }
490
+
419
491
// Bytes32ToUintMap
420
492
421
493
struct Bytes32ToUintMap {
@@ -434,7 +506,7 @@ library EnumerableMap {
434
506
}
435
507
436
508
/**
437
- * @dev Removes a value from a set . O(1).
509
+ * @dev Removes a value from a map . O(1).
438
510
*
439
511
* Returns true if the key was removed from the map, that is if it was present.
440
512
*/
@@ -457,7 +529,7 @@ library EnumerableMap {
457
529
}
458
530
459
531
/**
460
- * @dev Returns the element stored at position `index` in the set . O(1).
532
+ * @dev Returns the element stored at position `index` in the map . O(1).
461
533
* Note that there are no guarantees on the ordering of values inside the
462
534
* array, and it may change when more values are added or removed.
463
535
*
@@ -503,4 +575,24 @@ library EnumerableMap {
503
575
) internal view returns (uint256 ) {
504
576
return uint256 (get (map._inner, key, errorMessage));
505
577
}
578
+
579
+ /**
580
+ * @dev Return the an array containing all the keys
581
+ *
582
+ * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
583
+ * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
584
+ * this function has an unbounded cost, and using it as part of a state-changing function may render the function
585
+ * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
586
+ */
587
+ function keys (Bytes32ToUintMap storage map ) internal view returns (bytes32 [] memory ) {
588
+ bytes32 [] memory store = keys (map._inner);
589
+ bytes32 [] memory result;
590
+
591
+ /// @solidity memory-safe-assembly
592
+ assembly {
593
+ result := store
594
+ }
595
+
596
+ return result;
597
+ }
506
598
}
0 commit comments