Hot answers tagged

3

It's not clear if you want to retrieve all the values in a mapping or use the mapping to store structures that contain interesting, multipart things. No to the first interpretation. Yes to the second. Lay out an instance (for one key) in a struct. Map the structs to the keys. struct MyStruct { uint part1; bool part2; ... } mapping(uint => ...


2

Here's an example of how to set a storage array's length using sstore: pragma solidity ^0.6.0; contract Tata { uint256[] public testArray; function getLength() external view returns (uint256) { return testArray.length; } function setLength(uint256 newLength) external { assembly { sstore(testArray_slot, newLength) } ...


1

Ah I think I figured it out! My error -- if p is the "location" of the array, then keccak(p) is the location of the data, so keccak(p) + 0 would give the first data value. I incorrectly interpreted keccak(p) as the place where the array length is stored (i.e. [length, val0, val1, ...]), while in reality we have something more along the lines of length at ...


1

library GraphLibrary { struct Graph { mapping (uint => mapping (uint => uint)) edges; mapping (uint => uint) sourceNodes; mapping (uint => uint) targetNodes; uint lastEdgeID; } function addEdge (Graph storage _graph, uint _sourceNodeID, uint _targetNodeID) external returns (uint) { require (_graph.edges [_sourceNodeID][...


Only top voted, non community-wiki answers of a minimum length are eligible