Created
October 19, 2015 03:17
-
-
Save pipermerriam/68d3c81cf201049a87c2 to your computer and use it in GitHub Desktop.
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
import "libraries/GroveLib.sol"; | |
import "libraries/StringUtils.sol"; | |
contract IterableStruct { | |
GroveLib.Index theIndex; | |
uint _id; | |
struct MyStruct { | |
uint id; | |
bytes32 value; | |
} | |
mapping (int => MyStruct) my_structs; | |
function addThing(bytes32 value) { | |
_id++; | |
var thing = my_structs[_id]; | |
thing.id = _id; | |
thing.value = value; | |
GroveLib.insert(theIndex, StringUtils.uintToBytes(uint(thing.id)), int(thing.id)); | |
} | |
function iterateOverThings() { | |
bytes32 id = GroveLib.query(theIndex, ">=", 0); | |
while (id != 0x0) { | |
thing = my_structs[StringUtils.bytesToUint(id)]; | |
// do something with the thing? | |
id = Grove.getNextNode(id); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment