Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The obvious question is why would you want to actually use a hash ?</p> <p>I understand the issue with <code>map</code> / <code>set</code> for performance critical code, indeed those containers are not very cache friendly because the items might be allocated at very different memory locations.</p> <p>As KeithB suggested (I won't comment on using the binary representation since nothing guarantees that 2 ids have the same binary representation after all...), using a sorted <code>vector</code> can speed up the code in case there is very few items.</p> <p>Sorted vectors / deques are much more cache-friendly, however they suffer from a <em>O(N)</em> complexity on insert/erase because of the copying involved. Once you reach a couple hundreds threads (never seen that many by the way), it could hurt.</p> <p>There is however, a data structure that tries to associate the benefits from maps and sorted vectors: the <a href="http://en.wikipedia.org/wiki/B%2B_tree" rel="nofollow noreferrer">B+Tree</a>.</p> <p>You can view it as a map for which each node would contain more than one element (in sorted order). Only the leaf nodes are used.</p> <p>To get some more performance you can:</p> <ul> <li>Link the leaves linearly: ie the root caches a pointer to the first and last leaf and the leaves are interconnected themselves, so that linear travel completely bypass the interal nodes.</li> <li>Cache the last accessed leaf in the root, after all it's likely that'll also be the next one accessed.</li> </ul> <p>The asymptotic performances are the same than for the map, because it's implemented as a Balanced Binary Tree, but because the values are packed in groups, you're code can become faster by a constant.</p> <p>The real difficulty is to tailor the size of each "bucket", you'll need some profiling for that so it would be better if your implementation allowed some customization there (as it will depend on the architecture on which the code is executed).</p>
    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. VO
      singulars
      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