contract ArrayMapping { address[] public keys; bytes4[] public values; function setValue(address[] key, bytes4[] value) public { //This will set the whole arrays // Array in the format // key[i] = value[j,j+1.....m] } function getValues(address key) public view returns (address[]) { uint256 index = findIndex(key); require(index < keys.length, "Key does not exist"); uint256 start_index, end_index = findValueIndex(index); require(start_index< end_index, "Values does not exist"); return values[start_index:end_index]; } function findValueIndex(uint256 vi) internal view returns (uint256, uint256) { for (uint256 i=0; i <values.length; i++) { uint256 start_index = 0; uint256 end_index = 0 if (values[i].length == 0) { index++; if (start_index !=0) { end_index = i-1; return start_index, end_index; } } if (index == vi){ start_index = i+1; } } return values.length, values.length; } function findIndex(address 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