-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EnumerableMap, refactor ERC721 (#2160)
* Implement AddressSet in terms of a generic Set * Add Uint256Set * Add EnumerableMap * Fix wording on EnumerableSet docs and tests * Refactor ERC721 using EnumerableSet and EnumerableMap * Fix tests * Fix linter error * Gas optimization for EnumerableMap * Gas optimization for EnumerableSet * Remove often not-taken if from Enumerable data structures * Fix failing test * Gas optimization for EnumerableMap * Fix linter errors * Add comment for clarification * Improve test naming * Rename EnumerableMap.add to set * Add overload for EnumerableMap.get with custom error message * Improve Enumerable docs * Rename Uint256Set to UintSet * Add changelog entry
- Loading branch information
Showing
12 changed files
with
603 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
pragma solidity ^0.6.0; | ||
|
||
import "../utils/EnumerableMap.sol"; | ||
|
||
contract EnumerableMapMock { | ||
using EnumerableMap for EnumerableMap.UintToAddressMap; | ||
|
||
event OperationResult(bool result); | ||
|
||
EnumerableMap.UintToAddressMap private _map; | ||
|
||
function contains(uint256 key) public view returns (bool) { | ||
return _map.contains(key); | ||
} | ||
|
||
function set(uint256 key, address value) public { | ||
bool result = _map.set(key, value); | ||
emit OperationResult(result); | ||
} | ||
|
||
function remove(uint256 key) public { | ||
bool result = _map.remove(key); | ||
emit OperationResult(result); | ||
} | ||
|
||
function length() public view returns (uint256) { | ||
return _map.length(); | ||
} | ||
|
||
function at(uint256 index) public view returns (uint256 key, address value) { | ||
return _map.at(index); | ||
} | ||
|
||
|
||
function get(uint256 key) public view returns (address) { | ||
return _map.get(key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.