Skip to content

Instantly share code, notes, and snippets.

@sagivo
Last active January 18, 2018 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagivo/2db94edec8b5d68ad6ba75e9ede2cf24 to your computer and use it in GitHub Desktop.
Save sagivo/2db94edec8b5d68ad6ba75e9ede2cf24 to your computer and use it in GitHub Desktop.
Import Obj
pragma solidity ^0.4.0;
// import the contract
import "github.com/sagivo/solidity-utils/contracts/lib/Dictionary.sol";
// have fun
contract Foo {
// declare and use new Dictionary structure
using Dictionary for Dictionary.Data;
Dictionary.Data private dic;
function Foo() public view returns (uint) {
dic.set(1, "value");
dic.set(2, "foo");
dic.set(123, "bar");
dic.set(1, "new value");
// get an item
dic.get(2); // => '0x666f6f' (byte hex of 'foo')
// get all keys
dic.keys(); // => [1, 2, 123]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment