title: convert bitarray to set
body: <p>How to convert bitarray to set quickly with c++?
  Each of the actual bitarrays has 750,000 bits.</p>
  
  <p>Example 1:</p>
  
  <pre><code>bitarray: 01011111
  set: {0,1,2,3,4,5,7}
  or set: {1,3,4,5,6,7}
  </code></pre>
  
  <p>Example 2:</p>
  
  <pre><code>bitarray: 0101 1111 0001 0001
  set: {0,4,8,9,10,11,12,14}
  or set: {1,3,4,5,6,7,11,15}
  </code></pre>
  
  <p>The set is an array of usigned 32 bit integers (uint32_t). Both kinds of set are acceptable.</p>
  
  <p>The bitarray is contiguous in memory. The first bit of the bitarray has correct alignment for simd. For now I am using a custom memory allocator with std::vector to hold the bitarray. 1 bit in memory per 1 bit in the bitarray.</p>
  
  <p>Thanks.</p>
  
  <p>Update:</p>
  
  <p><a href="https://stackoverflow.com/questions/23664015/packing-10-bit-values-into-a-byte-stream-with-simd">this so question does the reverse</a></p>
  
  <p><a href="https://stackoverflow.com/questions/33005271/looping-through-bits-c">loop through bits in c</a></p>
  
  <p><a href="https://stackoverflow.com/questions/2525310/how-to-define-and-work-with-an-array-of-bits-in-c">How to define and work with an array of bits in C?</a></p>
  
  <p>gmpy uses the scan1 function of the <a href="https://gmplib.org/" rel="nofollow noreferrer">gmp library</a>. scan1 seems find first set, as in wikipedia <a href="https://en.wikipedia.org/wiki/Find_first_set" rel="nofollow noreferrer">here</a></p>