Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sounds like this might be useful:</p> <p><a href="http://www.aggregate.org/MAGIC/#Population%20Count%20%28Ones%20Count%29" rel="nofollow">http://www.aggregate.org/MAGIC/#Population%20Count%20%28Ones%20Count%29</a> and <a href="http://www.aggregate.org/MAGIC/#Leading%20Zero%20Count" rel="nofollow">http://www.aggregate.org/MAGIC/#Leading%20Zero%20Count</a></p> <p>You don't say if you wanted to do some sort of RLE or to simply count in-bytes zeros and one bits (like 0b1001 should return 1x1 2x0 1x1).</p> <p>A look up table plus SWAR algorithm for fast check might gives you that information easily. A bit like this:</p> <pre><code>byte lut[0x10000] = { /* see below */ }; for (uint * word = words; word &lt; words + bitmapSize; word++) { if (word == 0 || word == (uint)-1) // Fast bailout { // Do what you want if all 0 or all 1 } byte hiVal = lut[*word &gt;&gt; 16], loVal = lut[*word &amp; 0xFFFF]; // Do what you want with hiVal and loVal </code></pre> <p>The LUT will have to be constructed depending on your intended algorithm. If you want to count the number of contiguous 0 and 1 in the word, you'll built it like this:</p> <pre><code> for (int i = 0; i &lt; sizeof(lut); i++) lut[i] = countContiguousZero(i); // Or countContiguousOne(i) // The implementation of countContiguousZero can be slow, you don't care // The result of the function should return the largest number of contiguous zero (0 to 15, using the 4 low bits of the byte, and might return the position of the run in the 4 high bits of the byte // Since you've already dismissed word = 0, you don't need the 16 contiguous zero case. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload