title: Searching using unordered map vs array
body: <p>I have a block allocation function that takes in an array and then searches through it to find values <code>0</code> which indicates the free space, and then allocates blocks to the available free space. I am trying to use unordered map to improve the speed of searching for <code>0</code>s. In my function, all the elements in the array are inserted into the unordered map. I was wondering if implementing unordered map like below even improves the searching speed compared to just using arrays?</p>
  <pre><code>int arr[] = {15, 11, 0, 0, 0, 27, 0, 0}; // example array
  int n = sizeof(arr)/sizeof(arr[0]);
  unordered_map&lt;int, int&gt; hash;
      for(i=n;i&gt;=0;i--)
      {
          hash[i+1] = arr[i]; 
      }
      for(auto v : hash)
      {
          if(v.second==0) 
          {
              return v.second; 
          }
      }
  </code></pre>
  <pre><code>int arr[] = {15, 11, 0, 0, 0, 27, 0, 0};
  int n = sizeof(arr)/sizeof(arr[0]);
      for(i=0;i&lt;n;i++)
      {
          if(arr[i]==0) 
          {
              return arr[i];
          }
      }
  </code></pre>