Make code examples conform to style guide

This commit is contained in:
Chris Ward 2019-05-27 16:59:54 +02:00
parent dee023bda6
commit e81e71e879

View File

@ -49,46 +49,48 @@ more advanced example to implement a set).
pragma solidity >=0.4.22 <0.7.0; pragma solidity >=0.4.22 <0.7.0;
library Set { library Set {
// We define a new struct datatype that will be used to // We define a new struct datatype that will be used to
// hold its data in the calling contract. // hold its data in the calling contract.
struct Data { mapping(uint => bool) flags; } struct Data { mapping(uint => bool) flags; }
// Note that the first parameter is of type "storage // Note that the first parameter is of type "storage
// reference" and thus only its storage address and not // reference" and thus only its storage address and not
// its contents is passed as part of the call. This is a // its contents is passed as part of the call. This is a
// special feature of library functions. It is idiomatic // special feature of library functions. It is idiomatic
// to call the first parameter `self`, if the function can // to call the first parameter `self`, if the function can
// be seen as a method of that object. // be seen as a method of that object.
function insert(Data storage self, uint value) function insert(Data storage self, uint value)
public public
returns (bool) returns (bool)
{ {
if (self.flags[value]) if (self.flags[value])
return false; // already there return false; // already there
self.flags[value] = true; self.flags[value] = true;
return true; return true;
} }
function remove(Data storage self, uint value) function remove(Data storage self, uint value)
public public
returns (bool) returns (bool)
{ {
if (!self.flags[value]) if (!self.flags[value])
return false; // not there return false; // not there
self.flags[value] = false; self.flags[value] = false;
return true; return true;
} }
function contains(Data storage self, uint value) function contains(Data storage self, uint value)
public public
view view
returns (bool) returns (bool)
{ {
return self.flags[value]; return self.flags[value];
} }
} }
contract C { contract C {
Set.Data knownValues; Set.Data knownValues;