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
This commit is contained in:
38
contracts/mocks/EnumerableMapMock.sol
Normal file
38
contracts/mocks/EnumerableMapMock.sol
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user