Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why do you want to store these in a set. Unless you doing something out of the ordinary, there will be a small number of threads. The overhead of maintaining a set is probably higher than just putting them in a vector and doing a linear search. </p> <p>If searching will happen more frequently than adding and deleting, you can just use a sorted vector. There is a &lt; operator defined for boost::thread::id, so you can sort the vector (or insert into the correct place) after each addition or deletion, and use <code>lower_bound()</code> to do a binary search. This is the same complexity as searching a set, and should have lower overhead for small amounts of data. </p> <p>If you still need to do this, how about just treating it as a sizeof(boost::thread:id) bytes, and operating on those.</p> <p>This example assumes that the size of boost::thread::id is a multiple of the size of an int, and that there is no packing, and no virtual functions. If that is not true, it will have to be modified, or will not work at all.</p> <p>EDIT: I took a look at the <code>boost::thread::id</code> class, and it has a <code>boost::shared_pointer&lt;&gt;</code> as a member, so the code below is horribly broken. I think the only solution is to have the authors of <code>boost::thread</code> add a hash function. I'm leaving the example just in case its useful in some other context.</p> <pre><code>boost::thread::id id; unsigned* data; // The next line doesn't do anything useful in this case. data = reinterpret_cast&lt;unsigned *&gt;(&amp;id); unsigned hash = 0; for (unsigned int i = 0; i &lt; sizeof(boost::thread::id)/4; i++) hash ^= data[i]; </code></pre>
    singulars
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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