-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathex10_mappings.sol
49 lines (38 loc) · 1006 Bytes
/
ex10_mappings.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
pragma solidity ^0.4.21;
/**
* Simple Example not using iteration
*
*/
contract MappingsSimple {
mapping(address => uint) public myMapping;
function addData(address _address, uint _value) public {
myMapping[_address] = _value;
}
}
/**
* Simple Example using iteration
*
*/
contract MappingsSimpleIteration {
struct MyData {
uint _value;
address _address;
}
mapping(uint => MyData) public myMapping;
uint public mappingSize;
function addData(address _address, uint _value) public {
myMapping[mappingSize++] = MyData(_value, _address);
}
}
/**
* Advanced Example using Libraries
*
*/
import {IterableMapping} from 'https://github.com/ethereum/dapp-bin/library/iterable_mapping.sol';
contract MappingsAdvanced {
using IterableMapping for IterableMapping.itmap;
IterableMapping.itmap public data;
function insertValue(uint _key, uint _value) public {
data.insert(_key, _value);
}
}