title: Insert into an unordered boost bimap using TBB
body: <p>I am very much confused with respect to <code>TBB</code>. I am trying to insert <code>&lt;key, value&gt;</code> pair in an unordered bimap, where the <code>key</code> is of type <code>uint64_t</code> and <code>value</code> is of type <code>string</code>. I made an attempt to create the <code>loop object</code>, which is in <code>TBB.h</code> file, and looks like</p>
  
  <pre><code>void ParallelIndex(uint64_t &amp;kmer_len, std::string &amp;split_kmer, std::string &amp;sequence_content,
              uint64_t &amp;sequence_length, size_t &amp;kmer_position ) {
          parallel_for( blocked_range&lt;size_t&gt;(0, sequence_length),
                  [&amp;](const blocked_range&lt;size_t&gt;&amp; r) {
              for(i = r.begin(); i &lt; r.end();  ++i ){
                  split_kmer = sequence_content.substr(i, kmer_len);
                  reference_index_vector.insert(position(kmer_position, split_kmer)); 
                  i += kmer_len-1;
                  kmer_position += kmer_len;
  
                  }
          }
          );
      }
  </code></pre>
  
  <p>and in the <code>main</code> function, which is in <code>TBB.cpp</code>, I tried to invoke the function </p>
  
  <pre><code>index.ParallelIndex(index.kmer_len, index.split_kmer, index.sequence_content,
          index.sequence_length, index.kmer_position );
  </code></pre>
  
  <p>It starts with 0 and goes through n. I am trying to increment <code>i</code> by 5 (first <code>++i</code> and <code>i +=kmer_len-1</code>, like <code>i = 0, 5, 10, 15, ...</code> till n),  but <code>i</code> gets incremented by only 1.</p>
  
  <p><strong>Complete code</strong> is shown below:</p>
  
  <p><strong>TBB.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;algorithm&gt;
  #include &lt;boost/bimap.hpp&gt;
  #include &lt;boost/bimap/unordered_set_of.hpp&gt;
  #include &lt;boost/bimap/unordered_multiset_of.hpp&gt;
  #include "tbb/parallel_for.h"
  #include "TBB.h"
  #include "tbb/tbb.h"
  #include &lt;tbb/blocked_range.h&gt;
  
  
  
  using namespace tbb;
  
  
  namespace bimaps = boost::bimaps;
  typedef boost::bimap&lt;bimaps::unordered_set_of&lt;uint64_t&gt;,
          bimaps::unordered_multiset_of&lt;std::string&gt; &gt; bimap_reference;
  typedef bimap_reference::value_type position;
  bimap_reference reference_index_vector;
  
  
  
  uint64_t thread_test::create_index::kmer_len = 5;
  std::string thread_test::create_index::split_kmer = "";
  std::string thread_test::create_index::sequence_content = "ABCDDBACDDDCBBAAACBDAADCBDAAADCBDADADACBDDCBBBCDCBCDAADCBBCDAAAD";
  uint64_t thread_test::create_index::sequence_length = 0;
  size_t thread_test::create_index::kmer_position = 0;
  size_t thread_test::create_index::i = 0;
  int main(){
      thread_test::create_index index;
      index.sequence_length = index.sequence_content.length();
  
      index.ParallelIndex(index.kmer_len, index.split_kmer, index.sequence_content,
              index.sequence_length, index.kmer_position );
  
      for( bimap_reference::const_iterator iter = reference_index_vector.begin(), iend = reference_index_vector.end();
                  iter != iend; ++iter ) {
              std::cout &lt;&lt; iter-&gt;left &lt;&lt; " &lt;--&gt; "&lt;&lt; iter-&gt;right &lt;&lt;std::endl;
          }
  
  }
  </code></pre>
  
  <p><strong>TBB.h</strong></p>
  
  <pre><code>#ifndef TBB_H_
  #define TBB_H_
  
  #include&lt;iostream&gt;
  #include &lt;algorithm&gt;
  #include &lt;utility&gt;
  #include &lt;boost/bimap.hpp&gt;
  #include &lt;boost/bimap/unordered_set_of.hpp&gt;
  #include &lt;boost/bimap/unordered_multiset_of.hpp&gt;
  #include "tbb/tbb.h"
  #include &lt;tbb/parallel_for.h&gt;
  #include &lt;tbb/blocked_range.h&gt;
  #include &lt;tbb/mutex.h&gt;
  
  
  using namespace tbb;
  
  
  namespace bimaps = boost::bimaps;
  
  typedef boost::bimap&lt;bimaps::unordered_set_of&lt;uint64_t&gt;,
          bimaps::unordered_multiset_of&lt;std::string &gt; &gt; bimap_reference;
  typedef bimap_reference::value_type position;
  extern bimap_reference reference_index_vector;
  
  
  
  namespace thread_test{
  
  class create_index{
  
  public:
      static uint64_t kmer_len;
      static std::string split_kmer;
      static std::string sequence_content;
      static uint64_t sequence_length;
      static size_t kmer_position;
      static size_t i;
  
  //  using lambda function
  
      void ParallelIndex(uint64_t &amp;kmer_len, std::string &amp;split_kmer, std::string &amp;sequence_content,
              uint64_t &amp;sequence_length, size_t &amp;kmer_position ) {
          parallel_for( blocked_range&lt;size_t&gt;(0, sequence_length),
                  [&amp;](const blocked_range&lt;size_t&gt;&amp; r) {
              for(i = r.begin(); i &lt; r.end();  ++i ){
                  split_kmer = sequence_content.substr(i, kmer_len);
                  reference_index_vector.insert(position(kmer_position, split_kmer));
                  i += kmer_len-1;
                  kmer_position += kmer_len;
                  }
          }
          );
      }
  };
  }
  
  #endif /* TBB_H_ */
  </code></pre>
  
  <p>problem is <code>i</code> gets incremented by 1 but I try to increment it by 5 as mentioned above.</p>