title: How are hashtables (maps) stored in memory?
body: <p>This question is specifically for hashtables, but might also cover other data structures such as linked lists or trees. </p>
  
  <p>For instance, if you have a struct as follows:</p>
  
  <pre><code>struct Data 
  {
     int value1;
     int value2;
     int value3;
  }
  </code></pre>
  
  <p>And each integer is 4-byte aligned and stored in memory sequentially, are the key and value of a hash table stored sequentially as well? If you consider the following:</p>
  
  <pre><code>std::map&lt;int, string&gt; list;
  list[0] = "first";
  </code></pre>
  
  <p>Is that first element represented like this? </p>
  
  <pre><code>struct ListNode
  {
     int key;
     string value;
  }
  </code></pre>
  
  <p>And if the key and value are 4-byte aligned and stored sequentially, does it matter where the next  pair is stored?</p>
  
  <p>What about a node in a linked list?</p>
  
  <p>Just trying to visualize this conceptually, and also see if the same guidelines for memory storage also apply for open-addressing hashing (the load is under 1) vs. chained hashing (load doesn't matter). </p>