Skip to content

Commit 6f5319d

Browse files
authored
✨ EnumerableMapLib capped variants (#1447)
1 parent 65e87c7 commit 6f5319d

File tree

5 files changed

+701
-0
lines changed

5 files changed

+701
-0
lines changed

docs/utils/enumerablemaplib.md

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ function set(Bytes32ToBytes32Map storage map, bytes32 key, bytes32 value)
133133
Adds a key-value pair to the map, or updates the value for an existing key.
134134
Returns true if `key` was added to the map, that is if it was not already present.
135135

136+
### set(Bytes32ToBytes32Map,bytes32,bytes32,uint256)
137+
138+
```solidity
139+
function set(
140+
Bytes32ToBytes32Map storage map,
141+
bytes32 key,
142+
bytes32 value,
143+
uint256 cap
144+
) internal returns (bool)
145+
```
146+
147+
Adds a key-value pair to the map, or updates the value for an existing key.
148+
Returns true if `key` was added to the map, that is if it was not already present.
149+
Reverts if the map grows bigger than the custom on-the-fly capacity `cap`.
150+
136151
### remove(Bytes32ToBytes32Map,bytes32)
137152

138153
```solidity
@@ -144,6 +159,20 @@ function remove(Bytes32ToBytes32Map storage map, bytes32 key)
144159
Removes a key-value pair from the map.
145160
Returns true if `key` was removed from the map, that is if it was present.
146161

162+
### update(Bytes32ToBytes32Map,bytes32,bytes32,bool,uint256)
163+
164+
```solidity
165+
function update(
166+
Bytes32ToBytes32Map storage map,
167+
bytes32 key,
168+
bytes32 value,
169+
bool isAdd,
170+
uint256 cap
171+
) internal returns (bool)
172+
```
173+
174+
Shorthand for `isAdd ? map.set(key, value, cap) : map.remove(key)`.
175+
147176
### contains(Bytes32ToBytes32Map,bytes32)
148177

149178
```solidity
@@ -221,6 +250,21 @@ function set(Bytes32ToUint256Map storage map, bytes32 key, uint256 value)
221250
Adds a key-value pair to the map, or updates the value for an existing key.
222251
Returns true if `key` was added to the map, that is if it was not already present.
223252

253+
### set(Bytes32ToUint256Map,bytes32,uint256,uint256)
254+
255+
```solidity
256+
function set(
257+
Bytes32ToUint256Map storage map,
258+
bytes32 key,
259+
uint256 value,
260+
uint256 cap
261+
) internal returns (bool)
262+
```
263+
264+
Adds a key-value pair to the map, or updates the value for an existing key.
265+
Returns true if `key` was added to the map, that is if it was not already present.
266+
Reverts if the map grows bigger than the custom on-the-fly capacity `cap`.
267+
224268
### remove(Bytes32ToUint256Map,bytes32)
225269

226270
```solidity
@@ -232,6 +276,20 @@ function remove(Bytes32ToUint256Map storage map, bytes32 key)
232276
Removes a key-value pair from the map.
233277
Returns true if `key` was removed from the map, that is if it was present.
234278

279+
### update(Bytes32ToUint256Map,bytes32,uint256,bool,uint256)
280+
281+
```solidity
282+
function update(
283+
Bytes32ToUint256Map storage map,
284+
bytes32 key,
285+
uint256 value,
286+
bool isAdd,
287+
uint256 cap
288+
) internal returns (bool)
289+
```
290+
291+
Shorthand for `isAdd ? map.set(key, value, cap) : map.remove(key)`.
292+
235293
### contains(Bytes32ToUint256Map,bytes32)
236294

237295
```solidity
@@ -309,6 +367,21 @@ function set(Bytes32ToAddressMap storage map, bytes32 key, address value)
309367
Adds a key-value pair to the map, or updates the value for an existing key.
310368
Returns true if `key` was added to the map, that is if it was not already present.
311369

370+
### set(Bytes32ToAddressMap,bytes32,address,uint256)
371+
372+
```solidity
373+
function set(
374+
Bytes32ToAddressMap storage map,
375+
bytes32 key,
376+
address value,
377+
uint256 cap
378+
) internal returns (bool)
379+
```
380+
381+
Adds a key-value pair to the map, or updates the value for an existing key.
382+
Returns true if `key` was added to the map, that is if it was not already present.
383+
Reverts if the map grows bigger than the custom on-the-fly capacity `cap`.
384+
312385
### remove(Bytes32ToAddressMap,bytes32)
313386

314387
```solidity
@@ -320,6 +393,20 @@ function remove(Bytes32ToAddressMap storage map, bytes32 key)
320393
Removes a key-value pair from the map.
321394
Returns true if `key` was removed from the map, that is if it was present.
322395

396+
### update(Bytes32ToAddressMap,bytes32,address,bool,uint256)
397+
398+
```solidity
399+
function update(
400+
Bytes32ToAddressMap storage map,
401+
bytes32 key,
402+
address value,
403+
bool isAdd,
404+
uint256 cap
405+
) internal returns (bool)
406+
```
407+
408+
Shorthand for `isAdd ? map.set(key, value, cap) : map.remove(key)`.
409+
323410
### contains(Bytes32ToAddressMap,bytes32)
324411

325412
```solidity
@@ -397,6 +484,21 @@ function set(Uint256ToBytes32Map storage map, uint256 key, bytes32 value)
397484
Adds a key-value pair to the map, or updates the value for an existing key.
398485
Returns true if `key` was added to the map, that is if it was not already present.
399486

487+
### set(Uint256ToBytes32Map,uint256,bytes32,uint256)
488+
489+
```solidity
490+
function set(
491+
Uint256ToBytes32Map storage map,
492+
uint256 key,
493+
bytes32 value,
494+
uint256 cap
495+
) internal returns (bool)
496+
```
497+
498+
Adds a key-value pair to the map, or updates the value for an existing key.
499+
Returns true if `key` was added to the map, that is if it was not already present.
500+
Reverts if the map grows bigger than the custom on-the-fly capacity `cap`.
501+
400502
### remove(Uint256ToBytes32Map,uint256)
401503

402504
```solidity
@@ -408,6 +510,20 @@ function remove(Uint256ToBytes32Map storage map, uint256 key)
408510
Removes a key-value pair from the map.
409511
Returns true if `key` was removed from the map, that is if it was present.
410512

513+
### update(Uint256ToBytes32Map,uint256,bytes32,bool,uint256)
514+
515+
```solidity
516+
function update(
517+
Uint256ToBytes32Map storage map,
518+
uint256 key,
519+
bytes32 value,
520+
bool isAdd,
521+
uint256 cap
522+
) internal returns (bool)
523+
```
524+
525+
Shorthand for `isAdd ? map.set(key, value, cap) : map.remove(key)`.
526+
411527
### contains(Uint256ToBytes32Map,uint256)
412528

413529
```solidity
@@ -485,6 +601,21 @@ function set(Uint256ToUint256Map storage map, uint256 key, uint256 value)
485601
Adds a key-value pair to the map, or updates the value for an existing key.
486602
Returns true if `key` was added to the map, that is if it was not already present.
487603

604+
### set(Uint256ToUint256Map,uint256,uint256,uint256)
605+
606+
```solidity
607+
function set(
608+
Uint256ToUint256Map storage map,
609+
uint256 key,
610+
uint256 value,
611+
uint256 cap
612+
) internal returns (bool)
613+
```
614+
615+
Adds a key-value pair to the map, or updates the value for an existing key.
616+
Returns true if `key` was added to the map, that is if it was not already present.
617+
Reverts if the map grows bigger than the custom on-the-fly capacity `cap`.
618+
488619
### remove(Uint256ToUint256Map,uint256)
489620

490621
```solidity
@@ -496,6 +627,20 @@ function remove(Uint256ToUint256Map storage map, uint256 key)
496627
Removes a key-value pair from the map.
497628
Returns true if `key` was removed from the map, that is if it was present.
498629

630+
### update(Uint256ToUint256Map,uint256,uint256,bool,uint256)
631+
632+
```solidity
633+
function update(
634+
Uint256ToUint256Map storage map,
635+
uint256 key,
636+
uint256 value,
637+
bool isAdd,
638+
uint256 cap
639+
) internal returns (bool)
640+
```
641+
642+
Shorthand for `isAdd ? map.set(key, value, cap) : map.remove(key)`.
643+
499644
### contains(Uint256ToUint256Map,uint256)
500645

501646
```solidity
@@ -573,6 +718,21 @@ function set(Uint256ToAddressMap storage map, uint256 key, address value)
573718
Adds a key-value pair to the map, or updates the value for an existing key.
574719
Returns true if `key` was added to the map, that is if it was not already present.
575720

721+
### set(Uint256ToAddressMap,uint256,address,uint256)
722+
723+
```solidity
724+
function set(
725+
Uint256ToAddressMap storage map,
726+
uint256 key,
727+
address value,
728+
uint256 cap
729+
) internal returns (bool)
730+
```
731+
732+
Adds a key-value pair to the map, or updates the value for an existing key.
733+
Returns true if `key` was added to the map, that is if it was not already present.
734+
Reverts if the map grows bigger than the custom on-the-fly capacity `cap`.
735+
576736
### remove(Uint256ToAddressMap,uint256)
577737

578738
```solidity
@@ -584,6 +744,20 @@ function remove(Uint256ToAddressMap storage map, uint256 key)
584744
Removes a key-value pair from the map.
585745
Returns true if `key` was removed from the map, that is if it was present.
586746

747+
### update(Uint256ToAddressMap,uint256,address,bool,uint256)
748+
749+
```solidity
750+
function update(
751+
Uint256ToAddressMap storage map,
752+
uint256 key,
753+
address value,
754+
bool isAdd,
755+
uint256 cap
756+
) internal returns (bool)
757+
```
758+
759+
Shorthand for `isAdd ? map.set(key, value, cap) : map.remove(key)`.
760+
587761
### contains(Uint256ToAddressMap,uint256)
588762

589763
```solidity
@@ -661,6 +835,21 @@ function set(AddressToBytes32Map storage map, address key, bytes32 value)
661835
Adds a key-value pair to the map, or updates the value for an existing key.
662836
Returns true if `key` was added to the map, that is if it was not already present.
663837

838+
### set(AddressToBytes32Map,address,bytes32,uint256)
839+
840+
```solidity
841+
function set(
842+
AddressToBytes32Map storage map,
843+
address key,
844+
bytes32 value,
845+
uint256 cap
846+
) internal returns (bool)
847+
```
848+
849+
Adds a key-value pair to the map, or updates the value for an existing key.
850+
Returns true if `key` was added to the map, that is if it was not already present.
851+
Reverts if the map grows bigger than the custom on-the-fly capacity `cap`.
852+
664853
### remove(AddressToBytes32Map,address)
665854

666855
```solidity
@@ -672,6 +861,20 @@ function remove(AddressToBytes32Map storage map, address key)
672861
Removes a key-value pair from the map.
673862
Returns true if `key` was removed from the map, that is if it was present.
674863

864+
### update(AddressToBytes32Map,address,bytes32,bool,uint256)
865+
866+
```solidity
867+
function update(
868+
AddressToBytes32Map storage map,
869+
address key,
870+
bytes32 value,
871+
bool isAdd,
872+
uint256 cap
873+
) internal returns (bool)
874+
```
875+
876+
Shorthand for `isAdd ? map.set(key, value, cap) : map.remove(key)`.
877+
675878
### contains(AddressToBytes32Map,address)
676879

677880
```solidity
@@ -749,6 +952,21 @@ function set(AddressToUint256Map storage map, address key, uint256 value)
749952
Adds a key-value pair to the map, or updates the value for an existing key.
750953
Returns true if `key` was added to the map, that is if it was not already present.
751954

955+
### set(AddressToUint256Map,address,uint256,uint256)
956+
957+
```solidity
958+
function set(
959+
AddressToUint256Map storage map,
960+
address key,
961+
uint256 value,
962+
uint256 cap
963+
) internal returns (bool)
964+
```
965+
966+
Adds a key-value pair to the map, or updates the value for an existing key.
967+
Returns true if `key` was added to the map, that is if it was not already present.
968+
Reverts if the map grows bigger than the custom on-the-fly capacity `cap`.
969+
752970
### remove(AddressToUint256Map,address)
753971

754972
```solidity
@@ -760,6 +978,20 @@ function remove(AddressToUint256Map storage map, address key)
760978
Removes a key-value pair from the map.
761979
Returns true if `key` was removed from the map, that is if it was present.
762980

981+
### update(AddressToUint256Map,address,uint256,bool,uint256)
982+
983+
```solidity
984+
function update(
985+
AddressToUint256Map storage map,
986+
address key,
987+
uint256 value,
988+
bool isAdd,
989+
uint256 cap
990+
) internal returns (bool)
991+
```
992+
993+
Shorthand for `isAdd ? map.set(key, value, cap) : map.remove(key)`.
994+
763995
### contains(AddressToUint256Map,address)
764996

765997
```solidity
@@ -837,6 +1069,21 @@ function set(AddressToAddressMap storage map, address key, address value)
8371069
Adds a key-value pair to the map, or updates the value for an existing key.
8381070
Returns true if `key` was added to the map, that is if it was not already present.
8391071

1072+
### set(AddressToAddressMap,address,address,uint256)
1073+
1074+
```solidity
1075+
function set(
1076+
AddressToAddressMap storage map,
1077+
address key,
1078+
address value,
1079+
uint256 cap
1080+
) internal returns (bool)
1081+
```
1082+
1083+
Adds a key-value pair to the map, or updates the value for an existing key.
1084+
Returns true if `key` was added to the map, that is if it was not already present.
1085+
Reverts if the map grows bigger than the custom on-the-fly capacity `cap`.
1086+
8401087
### remove(AddressToAddressMap,address)
8411088

8421089
```solidity
@@ -848,6 +1095,20 @@ function remove(AddressToAddressMap storage map, address key)
8481095
Removes a key-value pair from the map.
8491096
Returns true if `key` was removed from the map, that is if it was present.
8501097

1098+
### update(AddressToAddressMap,address,address,bool,uint256)
1099+
1100+
```solidity
1101+
function update(
1102+
AddressToAddressMap storage map,
1103+
address key,
1104+
address value,
1105+
bool isAdd,
1106+
uint256 cap
1107+
) internal returns (bool)
1108+
```
1109+
1110+
Shorthand for `isAdd ? map.set(key, value, cap) : map.remove(key)`.
1111+
8511112
### contains(AddressToAddressMap,address)
8521113

8531114
```solidity

0 commit comments

Comments
 (0)