title: segmentation fault in unordered_map after ~ 10000 keys added
body: <p>Segmentation fault occurs when datact=10736 when trying to insert into an unordered_map (see commented line for which call throws the fault). See below for attempted fixes.</p>
  
  <p>When SIGSEGV is thrown it points me to line 764 of <code>hashtable_policy.h</code></p>
  
  <p>INPUT: data file with column1=counts, column2=16-character strings</p>
  
  <p>PURPOSE: cluster 16-character sequences by adding all the counts of 1-substitution different sequences together. First sequence seen is "origin" by which all its 1-substitution friends are identified.</p>
  
  <p>PSEUDOCODE: for each line in file:</p>
  
  <ol>
  <li><p>read count, read sequence.</p></li>
  <li><p>if sequence key_value exists in hash 'location' (type
  unordered_map), add current count; </p></li>
  <li><p>otherwise make a new key_value, have it point to the count here, and
  assign all 1-substitution sequences to also point to this count.</p></li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  #include &lt;sstream&gt;
  #include &lt;cmath&gt;
  #include &lt;vector&gt;
  #include &lt;unordered_map&gt;
  #include &lt;map&gt;
  
  #include "matrix.h"
  
  using namespace std;
  
  int nuc2num(char currchar)
  {   // returns 0,1,2,3 for A,C,T,G respectively
      int outnum;
  
      if (currchar=='A')
      {
          outnum=0;
      }
      else if (currchar=='C')
      {
          outnum=1;
      }
      else if (currchar=='T')
      {
          outnum=2;
      }
      else
      {
          outnum=3;
      }
      return outnum;
  }
  
  int main(int argc, char* argv[])
  {
      //command line arguments
      //  arg1=filename, arg2=barcode sequence length, arg3=#mismatches permitted
  
      //input handling
      //  file format: column 1 | column 2
      //               counts   | sequence    [int | string]
  
      string filename;
      string funnelstring;
  
      // define lookup matrix; rows=ACTG, cols = ACTG without row element
      Matrix &lt;char&gt; sub_lookup(4,3);
      sub_lookup[0][0] = 'C';
      sub_lookup[0][1] = 'T';
      sub_lookup[0][2] = 'G';
      sub_lookup[1][0] = 'A';
      sub_lookup[1][1] = 'T';
      sub_lookup[1][2] = 'G';
      sub_lookup[2][0] = 'A';
      sub_lookup[2][1] = 'C';
      sub_lookup[2][2] = 'G';
      sub_lookup[3][0] = 'A';
      sub_lookup[3][1] = 'C';
      sub_lookup[3][2] = 'T';
  
      int L,k;
  
      int j=0;
  
      const int buffersize=10000;
      int currentsize=buffersize;
  
      int datact=0;
      int currchar;
  
      vector &lt;unsigned int&gt; ctarr(buffersize);
      vector &lt;string&gt; seqarr(buffersize);
  
      filename=argv[1];
      L=atoi(argv[2]);
      k=atoi(argv[3]);
  
      unsigned int sct;
      int substrlen;
      string sequence,textct;
      ifstream seqfile (filename.c_str());
  
      //map &lt;string,unsigned int*&gt; location;
      unordered_map &lt;string,unsigned int*&gt; location;
  
      if (seqfile.is_open())
      {
          getline(seqfile,textct,'\n');
          while (textct != "")
          {
              sct=atoi(textct.c_str());
              substrlen=textct.length();
              //cout &lt;&lt; textct &lt;&lt; endl;
              sequence=textct.substr(substrlen-L,L);
              //cout &lt;&lt; sequence &lt;&lt; endl;
  
              //is there an associated guy?
              if (location.find(sequence) != location.end()) //just asks whether this key has been assigned
              {   //there's a value in the region
                  *location[sequence]+=sct;
              }
              else
              {   //no value in region, make a footprint
                  ctarr[datact]=sct;
                  seqarr[datact]=sequence;
                  location[sequence]=&amp;ctarr[datact]; //assign current key to point to data count
  
  
                  //assign k substitution "funnel" region to point to this count as well
                  for (j=0; j&lt;L; j++)
                  {
                      funnelstring=sequence;
                      currchar = nuc2num(sequence[j]);
  
                      if (datact==10736 &amp;&amp; j==13)
                      {
                          cout &lt;&lt; "here" &lt;&lt; endl;
                          cout &lt;&lt; sequence &lt;&lt; endl;
                      }
  
                      for (k=0; k&lt;3; k++)
                      {
                          funnelstring[j]=sub_lookup[currchar][k];
  
  //                    if (datact==10736 &amp;&amp; j==13)
  //                    {
  //                        cout &lt;&lt; funnelstring &lt;&lt; endl;
  //                        cout &lt;&lt; location.max_size() &lt;&lt; " | " &lt;&lt; location.size() &lt;&lt; endl;
  //                        string asdf;
  //                        asdf="AAAAAAAAAAAAAAAA";
  //                        location[asdf]=&amp;ctarr[datact]; //still segfaults
  //                    }
  
                          if (location.find(funnelstring) == location.end()) // asks whether this key has been assigned
                          {   //this region is not assigned to another funnel
                              location[funnelstring]=&amp;ctarr[datact]; //LINE THAT CAUSES SIGSEGV
                          }
                      }
                  }
                  datact++;
                  cout &lt;&lt; datact &lt;&lt; endl;
                  if (datact&gt;=currentsize)
                  {
                      ctarr.resize(currentsize+buffersize);
                      seqarr.resize(currentsize+buffersize);
                      currentsize+=buffersize;
                  }
              }
  
              getline(seqfile,textct,'\n');
           }
          seqfile.close();
      }
  </code></pre>
  
  <p>Explorations.</p>
  
  <ol>
  <li>It doesn't matter what key is added, when <code>datact==10736</code> and <code>j=13</code>, any
  key added to (unordered_map) location results in a SIGSEGV.</li>
  <li>The line of code in question (marked by a comment above) is called many times prior, and operates correctly.</li>
  <li>Exchanging unordered_map for map results in the same event, but at a different (higher) count of datact. Still low (between <code>datact</code>==16-35
  thousand).</li>
  <li>Rewriting this code almost exactly, but with randomly generated 16-character sequences works perfectly, as far as I can tell (no
  segfaults for datact up to 200,000, didnt test higher).</li>
  <li>In the code in (4), it does appear that there is a rehash right around 10000, which could be related or coincidence.</li>
  </ol>
  
  <p>If need be, I can post the datafile that is read.</p>
  
  <p><strong>EDIT: Solved</strong>
  Instead of <code>unordered_map &lt;string,unsigned int*&gt; location</code>, replaced with <code>unordered_map &lt;string,unsigned int&gt; location</code> (value_type is int instead of int*). Now value_type holds the index in the ctarr[]. Runs fine. Thanks!</p>