Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I just wanted to post a helpful article about bitArrays for those of us who are developing our own versions of Faceting with Lucene.net. See: <a href="http://dotnetperls.com/precomputed-bitcount" rel="nofollow noreferrer">http://dotnetperls.com/precomputed-bitcount</a> </p> <p>This is a good explination on the fastet way to get the cardinality of the on bits in an integer ( which is a bulk of what the above code sample does ).</p> <p>Imlementing the method in the article in my faceted search and some other simple changes i was able to cut the time it took the get the count by ~ 65%. The differences where in:</p> <ol> <li>Declaring the _bitcount global ( so its not created per call )</li> <li>Changing the for to foreach (ANT Profiler showed a 25% gain here)</li> <li><p>Implementening the 65535 table vs the 256 to shift 16 bits at a time rather then 8.</p> <pre><code>private static int[] _bitcounts = InitializeBitcounts(); private static int GetCardinality(BitArray bitArray) { uint[] array = (uint[])bitArray.GetType().GetField("m_array", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(bitArray); int count = 0; foreach (uint value in array) { count += _bitcounts[value &amp; 65535] + _bitcounts[(value &gt;&gt; 16) &amp; 65535]; } return count; } private static int[] InitializeBitcounts() { int[] bitcounts = new int[65536]; int position1 = -1; int position2 = -1; // // Loop through all the elements and assign them. // for (int i = 1; i &lt; 65536; i++, position1++) { // // Adjust the positions we read from. // if (position1 == position2) { position1 = 0; position2 = i; } bitcounts[i] = bitcounts[position1] + 1; } return bitcounts; } </code></pre></li> </ol>
 

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