Difference between revisions of "Mappings"

From rbachwiki
Jump to navigation Jump to search
(Created page with "# One way hash function. # Cannot loop through a mapping # On Demand Data Structure # Hash key then get results # A hash function is any function that can me bused to map dat...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
==Mappings==
# One way hash function.
# One way hash function.
# Cannot loop through a mapping
# Cannot loop through a mapping
Line 22: Line 24:
  }
  }
  function setPerson(address _a, uint _id, bytes32 _name) public{
  function setPerson(address _a, uint _id, bytes32 _name) public{
   var person = p(_a); // this will get the memory location
   var person = p[_a]; // this will get the memory location
  person.id = _id;
  person.name = _name;
  person.isPerson = true;
    
    
  }
  }
  }
  }




==[[#top|Back To Top]]-[[Main_Page| Home]] - [[Solidity_ethereum_Language|Category]]==
==[[#top|Back To Top]]-[[Main_Page| Home]] - [[Solidity_ethereum_Language|Category]]==

Latest revision as of 18:13, 21 March 2018

Mappings

  1. One way hash function.
  2. Cannot loop through a mapping
  3. On Demand Data Structure
  4. Hash key then get results
  5. A hash function is any function that can me bused to map data of arbitrary size to data of fixed size
contract MappingDemo {
struct Person {
 uint id;
 bytes32 name;
 bool isPerson;
}
mapping(address => Person) p;

function getPerson(address _a) view public returns(uint, bytes32, bool)
{
 var person = p[_a];
 // take the value of a and hash it using sha3(_a)
 // once it hashes it, it will use that value, as the location of where in memory or value is.
 // memory location 0x0a 
 return (person.id, person.name, person.isPerson);
 
}
function setPerson(address _a, uint _id, bytes32 _name) public{
 var person = p[_a]; // this will get the memory location
 person.id = _id;
 person.name = _name;
 person.isPerson = true;
 
}
}


Back To Top- Home - Category