Code has been added to clipboard!

Solidity Using For Example 1

Example
// Same code as before, only no comments

pragma solidity ^0.4.11;

library SetLib {
  struct LibData { mapping(uint => bool) flagsMapping; }

  function insertData(LibData storage selfStore, uint value)
      returns (bool)
  {
      if (selfStore.flagsMapping[value])
          return false;
      selfStore.flagsMapping[value] = true;
      return true;
  }

  function removeData(LibData storage selfStore, uint value)
      returns (bool)
        {
      if (!selfStore.flagsMapping[value])
          return false;
      selfStore.flagsMapping[value] = false;
      return true;
  }

  function contains(LibData storage selfStore, uint value)
      returns (bool)
  {
      return selfStore.flagsMapping[value];
  }
}

contract Cont {
    SetLib.LibData valuesKnown;

    function registerData(uint value) {
        // Here, all variables of type Set.Data have
        // corresponding member functions.
        // The following function call is identical to
        // Set.insert(knownValues, value)
        require(SetLib.insertData(valuesKnown, value));
    }
}