@@ -519,12 +519,12 @@ library EnumerableSet {
519
519
* Returns true if the value was added to the set, that is if it was not
520
520
* already present.
521
521
*/
522
- function add (StringSet storage self , string memory value ) internal returns (bool ) {
523
- if (! contains (self , value)) {
524
- self ._values.push (value);
522
+ function add (StringSet storage set , string memory value ) internal returns (bool ) {
523
+ if (! contains (set , value)) {
524
+ set ._values.push (value);
525
525
// The value is stored at length-1, but we add 1 to all indexes
526
526
// and use 0 as a sentinel value
527
- self ._positions[value] = self ._values.length ;
527
+ set ._positions[value] = set ._values.length ;
528
528
return true ;
529
529
} else {
530
530
return false ;
@@ -537,33 +537,33 @@ library EnumerableSet {
537
537
* Returns true if the value was removed from the set, that is if it was
538
538
* present.
539
539
*/
540
- function remove (StringSet storage self , string memory value ) internal returns (bool ) {
540
+ function remove (StringSet storage set , string memory value ) internal returns (bool ) {
541
541
// We cache the value's position to prevent multiple reads from the same storage slot
542
- uint256 position = self ._positions[value];
542
+ uint256 position = set ._positions[value];
543
543
544
544
if (position != 0 ) {
545
- // Equivalent to contains(self , value)
545
+ // Equivalent to contains(set , value)
546
546
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
547
547
// the array, and then remove the last element (sometimes called as 'swap and pop').
548
548
// This modifies the order of the array, as noted in {at}.
549
549
550
550
uint256 valueIndex = position - 1 ;
551
- uint256 lastIndex = self ._values.length - 1 ;
551
+ uint256 lastIndex = set ._values.length - 1 ;
552
552
553
553
if (valueIndex != lastIndex) {
554
- string memory lastValue = self ._values[lastIndex];
554
+ string memory lastValue = set ._values[lastIndex];
555
555
556
556
// Move the lastValue to the index where the value to delete is
557
- self ._values[valueIndex] = lastValue;
557
+ set ._values[valueIndex] = lastValue;
558
558
// Update the tracked position of the lastValue (that was just moved)
559
- self ._positions[lastValue] = position;
559
+ set ._positions[lastValue] = position;
560
560
}
561
561
562
562
// Delete the slot where the moved value was stored
563
- self ._values.pop ();
563
+ set ._values.pop ();
564
564
565
565
// Delete the tracked position for the deleted slot
566
- delete self ._positions[value];
566
+ delete set ._positions[value];
567
567
568
568
return true ;
569
569
} else {
@@ -588,15 +588,15 @@ library EnumerableSet {
588
588
/**
589
589
* @dev Returns true if the value is in the set. O(1).
590
590
*/
591
- function contains (StringSet storage self , string memory value ) internal view returns (bool ) {
592
- return self ._positions[value] != 0 ;
591
+ function contains (StringSet storage set , string memory value ) internal view returns (bool ) {
592
+ return set ._positions[value] != 0 ;
593
593
}
594
594
595
595
/**
596
596
* @dev Returns the number of values on the set. O(1).
597
597
*/
598
- function length (StringSet storage self ) internal view returns (uint256 ) {
599
- return self ._values.length ;
598
+ function length (StringSet storage set ) internal view returns (uint256 ) {
599
+ return set ._values.length ;
600
600
}
601
601
602
602
/**
@@ -609,8 +609,8 @@ library EnumerableSet {
609
609
*
610
610
* - `index` must be strictly less than {length}.
611
611
*/
612
- function at (StringSet storage self , uint256 index ) internal view returns (string memory ) {
613
- return self ._values[index];
612
+ function at (StringSet storage set , uint256 index ) internal view returns (string memory ) {
613
+ return set ._values[index];
614
614
}
615
615
616
616
/**
@@ -621,8 +621,8 @@ library EnumerableSet {
621
621
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
622
622
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
623
623
*/
624
- function values (StringSet storage self ) internal view returns (string [] memory ) {
625
- return self ._values;
624
+ function values (StringSet storage set ) internal view returns (string [] memory ) {
625
+ return set ._values;
626
626
}
627
627
628
628
/**
@@ -661,12 +661,12 @@ library EnumerableSet {
661
661
* Returns true if the value was added to the set, that is if it was not
662
662
* already present.
663
663
*/
664
- function add (BytesSet storage self , bytes memory value ) internal returns (bool ) {
665
- if (! contains (self , value)) {
666
- self ._values.push (value);
664
+ function add (BytesSet storage set , bytes memory value ) internal returns (bool ) {
665
+ if (! contains (set , value)) {
666
+ set ._values.push (value);
667
667
// The value is stored at length-1, but we add 1 to all indexes
668
668
// and use 0 as a sentinel value
669
- self ._positions[value] = self ._values.length ;
669
+ set ._positions[value] = set ._values.length ;
670
670
return true ;
671
671
} else {
672
672
return false ;
@@ -679,33 +679,33 @@ library EnumerableSet {
679
679
* Returns true if the value was removed from the set, that is if it was
680
680
* present.
681
681
*/
682
- function remove (BytesSet storage self , bytes memory value ) internal returns (bool ) {
682
+ function remove (BytesSet storage set , bytes memory value ) internal returns (bool ) {
683
683
// We cache the value's position to prevent multiple reads from the same storage slot
684
- uint256 position = self ._positions[value];
684
+ uint256 position = set ._positions[value];
685
685
686
686
if (position != 0 ) {
687
- // Equivalent to contains(self , value)
687
+ // Equivalent to contains(set , value)
688
688
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
689
689
// the array, and then remove the last element (sometimes called as 'swap and pop').
690
690
// This modifies the order of the array, as noted in {at}.
691
691
692
692
uint256 valueIndex = position - 1 ;
693
- uint256 lastIndex = self ._values.length - 1 ;
693
+ uint256 lastIndex = set ._values.length - 1 ;
694
694
695
695
if (valueIndex != lastIndex) {
696
- bytes memory lastValue = self ._values[lastIndex];
696
+ bytes memory lastValue = set ._values[lastIndex];
697
697
698
698
// Move the lastValue to the index where the value to delete is
699
- self ._values[valueIndex] = lastValue;
699
+ set ._values[valueIndex] = lastValue;
700
700
// Update the tracked position of the lastValue (that was just moved)
701
- self ._positions[lastValue] = position;
701
+ set ._positions[lastValue] = position;
702
702
}
703
703
704
704
// Delete the slot where the moved value was stored
705
- self ._values.pop ();
705
+ set ._values.pop ();
706
706
707
707
// Delete the tracked position for the deleted slot
708
- delete self ._positions[value];
708
+ delete set ._positions[value];
709
709
710
710
return true ;
711
711
} else {
@@ -730,15 +730,15 @@ library EnumerableSet {
730
730
/**
731
731
* @dev Returns true if the value is in the set. O(1).
732
732
*/
733
- function contains (BytesSet storage self , bytes memory value ) internal view returns (bool ) {
734
- return self ._positions[value] != 0 ;
733
+ function contains (BytesSet storage set , bytes memory value ) internal view returns (bool ) {
734
+ return set ._positions[value] != 0 ;
735
735
}
736
736
737
737
/**
738
738
* @dev Returns the number of values on the set. O(1).
739
739
*/
740
- function length (BytesSet storage self ) internal view returns (uint256 ) {
741
- return self ._values.length ;
740
+ function length (BytesSet storage set ) internal view returns (uint256 ) {
741
+ return set ._values.length ;
742
742
}
743
743
744
744
/**
@@ -751,8 +751,8 @@ library EnumerableSet {
751
751
*
752
752
* - `index` must be strictly less than {length}.
753
753
*/
754
- function at (BytesSet storage self , uint256 index ) internal view returns (bytes memory ) {
755
- return self ._values[index];
754
+ function at (BytesSet storage set , uint256 index ) internal view returns (bytes memory ) {
755
+ return set ._values[index];
756
756
}
757
757
758
758
/**
@@ -763,8 +763,8 @@ library EnumerableSet {
763
763
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
764
764
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
765
765
*/
766
- function values (BytesSet storage self ) internal view returns (bytes [] memory ) {
767
- return self ._values;
766
+ function values (BytesSet storage set ) internal view returns (bytes [] memory ) {
767
+ return set ._values;
768
768
}
769
769
770
770
/**
0 commit comments