Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>m.rehash(pow(2,x)); </code></pre> <p>if <code>pow(2, x)</code> is the number of buckets you want preallocated. You can also:</p> <pre><code>m.reserve(pow(2,x)); </code></pre> <p>but now <code>pow(2, x)</code> is the number of elements you are planning on inserting. Both functions do nothing but preallocate buckets. They don't insert any elements. And they are both meant to be used exactly for your use case.</p> <p>Note: You aren't guaranteed to get exactly <code>pow(2, x)</code> buckets. Some implementations will use only a number of buckets which is a power of 2. Other implementations will use only a prime number of buckets. Still others will use only a subset of primes for the number of buckets. But in any case, the implementation should accept your <em>hint</em> at the number of buckets you desire, and then internally round up to its next acceptable number of buckets.</p> <p>Here is the precise wording that the latest (N4660) uses to specify the argument to <code>rehash</code>:</p> <p><code>a.rehash(n)</code> : <em>Postconditions:</em> <code>a.bucket_count() &gt;= a.size() / a.max_load_factor() and a.bucket_count() &gt;= n</code>.</p> <p>This postcondition ensures that <code>bucket()_count() &gt;= n</code>, and that <code>load_factor()</code> remains less than or equal to <code>max_load_factor()</code>.</p> <p>Subsequently <code>reserve(n)</code> is defined in terms of <code>rehash(n)</code>:</p> <p><code>a.reserve(n)</code> : Same as <code>a.rehash(ceil(n / a.max_load_factor()))</code>.</p>
    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. 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.
    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