contract ArrayMapping { bytes4[] public keys; address[] public values; function setValue(bytes4 key, address value) public { uint256 index = findIndex(key); if (index < keys.length) { values[index] = value; } else { keys.push(key); values.push(value); } } function getValue(bytes4 key) public view returns (address) { uint256 index = findIndex(key); require(index < keys.length, "Key does not exist"); return values[index]; } function findIndex(bytes4 key) internal view returns (uint256) { for (uint256 i = 0; i < keys.length; i++) { if (keys[i] == key) { return i; } } return keys.length; } }
0.4.18