Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


This library has some basic missing utils in Solidity.


mapping + keys iteration.
Inspired by Dictionary in python or 'Objectin javascript,Dictionaryis an improved and faster mapping data-structure that allows you to retrieve all the keys in a mapping object while minimizing storage usage. The data-stucture combines linked-list iteration style with soliditymapping` hash-table.


pragma solidity ^0.4.0;
// import the contract
import "";

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");
        // get an item
        dic.get(2); // => '0x666f6f' (byte hex of 'foo')
        // get all keys
        dic.keys(); // => [1, 2]

Basic Operations

set(uint id, bytes data)
get(uint id) --> bytes data
remove(uint id)
getSize() --> uint num of keys

Iteration operations

Keys are stored based on the order you specify, allows you to iterate over keys.
keys() - return an array of all the keys.
next(uint id) / prev(uint id) - return the next/prev key for a given key.
firstNodeId / lastNodeId - return the first/last key.
Example iteration:

uint nodeId = dic.firstNodeId;
while (nodeId != 0) {
  // do something
  nodeId =;

Insertion Options

insertBeginning(uint id, bytes data) - add a node to the begining of the list.
insertEnd(uint id, bytes data) - add a node to the end of the list.
insertBefore(uint beforeId, uint id, bytes data) - add a node before another.
insertEnd(uint beforeId, uint id, bytes data) - add a node after another.
The default order for .set(uint id, bytes data) is insertEnd.


Key must be bigger than 0.