-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
1,164 additions
and
389 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
pragma solidity ^0.4.23; | ||
|
||
|
||
library Set { | ||
|
||
struct Data { | ||
bytes32[] items; | ||
mapping(bytes32 => uint) lookup; | ||
} | ||
|
||
function length(Data storage s) internal view returns(uint) { | ||
return s.items.length; | ||
} | ||
|
||
function at(Data storage s, uint index) internal view returns(bytes32) { | ||
return s.items[index]; | ||
} | ||
|
||
function contains(Data storage s, bytes32 item) internal view returns(bool) { | ||
return s.lookup[item] != 0; | ||
} | ||
|
||
function add(Data storage s, bytes32 item) public returns(bool) { | ||
if (s.lookup[item] > 0) { | ||
return false; | ||
} | ||
s.lookup[item] = s.items.push(item); | ||
return true; | ||
} | ||
|
||
function remove(Data storage s, bytes32 item) public returns(bool) { | ||
uint index = s.lookup[item]; | ||
if (index == 0) { | ||
return false; | ||
} | ||
if (index < s.items.length) { | ||
bytes32 lastItem = s.items[s.items.length - 1]; | ||
s.items[index - 1] = lastItem; | ||
s.lookup[lastItem] = index; | ||
} | ||
s.items.length -= 1; | ||
delete s.lookup[item]; | ||
return true; | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
const Multiownable = artifacts.require('Multiownable'); | ||
const Set = artifacts.require('Set'); | ||
|
||
module.exports = function (deployer) { | ||
module.exports = async function (deployer) { | ||
Multiownable.link('Set', (await Set.new()).address); | ||
deployer.deploy(Multiownable); | ||
}; |
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
Oops, something went wrong.