@@ -324,12 +324,12 @@ struct ${name} {
324
324
* Returns true if the value was added to the set, that is if it was not
325
325
* already present.
326
326
*/
327
- function add(${ name } storage self , ${ value . type } memory value) internal returns (bool) {
328
- if (!contains(self , value)) {
329
- self ._values.push(value);
327
+ function add(${ name } storage set , ${ value . type } memory value) internal returns (bool) {
328
+ if (!contains(set , value)) {
329
+ set ._values.push(value);
330
330
// The value is stored at length-1, but we add 1 to all indexes
331
331
// and use 0 as a sentinel value
332
- self ._positions[value] = self ._values.length;
332
+ set ._positions[value] = set ._values.length;
333
333
return true;
334
334
} else {
335
335
return false;
@@ -342,33 +342,33 @@ function add(${name} storage self, ${value.type} memory value) internal returns
342
342
* Returns true if the value was removed from the set, that is if it was
343
343
* present.
344
344
*/
345
- function remove(${ name } storage self , ${ value . type } memory value) internal returns (bool) {
345
+ function remove(${ name } storage set , ${ value . type } memory value) internal returns (bool) {
346
346
// We cache the value's position to prevent multiple reads from the same storage slot
347
- uint256 position = self ._positions[value];
347
+ uint256 position = set ._positions[value];
348
348
349
349
if (position != 0) {
350
- // Equivalent to contains(self , value)
350
+ // Equivalent to contains(set , value)
351
351
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
352
352
// the array, and then remove the last element (sometimes called as 'swap and pop').
353
353
// This modifies the order of the array, as noted in {at}.
354
354
355
355
uint256 valueIndex = position - 1;
356
- uint256 lastIndex = self ._values.length - 1;
356
+ uint256 lastIndex = set ._values.length - 1;
357
357
358
358
if (valueIndex != lastIndex) {
359
- ${ value . type } memory lastValue = self ._values[lastIndex];
359
+ ${ value . type } memory lastValue = set ._values[lastIndex];
360
360
361
361
// Move the lastValue to the index where the value to delete is
362
- self ._values[valueIndex] = lastValue;
362
+ set ._values[valueIndex] = lastValue;
363
363
// Update the tracked position of the lastValue (that was just moved)
364
- self ._positions[lastValue] = position;
364
+ set ._positions[lastValue] = position;
365
365
}
366
366
367
367
// Delete the slot where the moved value was stored
368
- self ._values.pop();
368
+ set ._values.pop();
369
369
370
370
// Delete the tracked position for the deleted slot
371
- delete self ._positions[value];
371
+ delete set ._positions[value];
372
372
373
373
return true;
374
374
} else {
@@ -393,15 +393,15 @@ function clear(${name} storage set) internal {
393
393
/**
394
394
* @dev Returns true if the value is in the set. O(1).
395
395
*/
396
- function contains(${ name } storage self , ${ value . type } memory value) internal view returns (bool) {
397
- return self ._positions[value] != 0;
396
+ function contains(${ name } storage set , ${ value . type } memory value) internal view returns (bool) {
397
+ return set ._positions[value] != 0;
398
398
}
399
399
400
400
/**
401
401
* @dev Returns the number of values on the set. O(1).
402
402
*/
403
- function length(${ name } storage self ) internal view returns (uint256) {
404
- return self ._values.length;
403
+ function length(${ name } storage set ) internal view returns (uint256) {
404
+ return set ._values.length;
405
405
}
406
406
407
407
/**
@@ -414,8 +414,8 @@ function length(${name} storage self) internal view returns (uint256) {
414
414
*
415
415
* - \`index\` must be strictly less than {length}.
416
416
*/
417
- function at(${ name } storage self , uint256 index) internal view returns (${ value . type } memory) {
418
- return self ._values[index];
417
+ function at(${ name } storage set , uint256 index) internal view returns (${ value . type } memory) {
418
+ return set ._values[index];
419
419
}
420
420
421
421
/**
@@ -426,8 +426,8 @@ function at(${name} storage self, uint256 index) internal view returns (${value.
426
426
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
427
427
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
428
428
*/
429
- function values(${ name } storage self ) internal view returns (${ value . type } [] memory) {
430
- return self ._values;
429
+ function values(${ name } storage set ) internal view returns (${ value . type } [] memory) {
430
+ return set ._values;
431
431
}
432
432
433
433
/**
0 commit comments