Skip to content

Instantly share code, notes, and snippets.

@zabirauf
Created January 16, 2018 03:17
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 zabirauf/1f03cabc9150e5c817e75803066baf22 to your computer and use it in GitHub Desktop.
Save zabirauf/1f03cabc9150e5c817e75803066baf22 to your computer and use it in GitHub Desktop.
// Code for StringToUintMap.sol
pragma solidity ^0.4.15;
library StringToUintMap {
struct Data {
mapping (string => uint8) map;
}
function insert(
Data storage self,
string key,
uint8 value) public returns (bool updated)
{
require(value > 0);
updated = self.map[key] != 0;
self.map[key] = value;
}
function get(Data storage self, string key) public returns (uint8) {
return self.map[key];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment