c++ - implemenation of sets using bits -


I'm reading about the set set as bits in the following location

Sequence SetAsBitVector: Public Set {typedef unsigned int Word; Enum {wordBits = bitsizeof (word)}; The & lt; Word & gt; Vector; Public: Set-up vector (unsigned integer); // ...}; SetAsBitVector :: SetAsBitVector (unsigned int n): set (n), vector ((n + wordBits - 1U) / wordBits) {// here question? For (unsigned int i = 0; i

To insert any item in the set, we have to change the appropriate bit in a bit array. The ith bit bit bit of bit array is mod w of the word roof (i / w). Thus, the insertion function is implemented using the beetwold or operation so that it is shown in the above program. Although this is slightly more complex than the SetAsArray class for this operation, the time to run for this operation is still (1). Since w = word bits have the power of two, it is possible to change the division and modulo operations, and with%, such shifts and masks:

vector [items] changes | = 1 & lt; & Lt; (Items and masks);

Question

Li>

I have a question in the constructor why why is the author subtracting the word "B" from 1, instead we can use it directly as n / wordbits?

  • The second question is whay by the statement of the author "ince w = wordbits is the power of two, split and modulo operation, and /, and replace with shift, mask like this Possible:

  • vector [item] change | | = 1 << p>

    In the case of requesting an example that is the value of change and the mask.

    1. Why is the author mentioned on the basis of architecture and compiler?
    2. < / Ol>

    I have re-tagged it as C ++ because it is not explicitly.

    1. For example, if you say that it is equal to something like wordBits from n , the generic formula is being used exactly, i.e. B = (a + q - 1) / q ensures that b * q is less than a .
    2. The original binary Arithmetic Is equal to the queen and so on.
    3. On some machines, speeds are faster than poly and mask divisions and modules

    Comments

    Popular posts from this blog

    winforms - C# Form - Property Change -

    java - Messages from .properties file do not display UTF-8 characters -

    javascript - amcharts makechart not working -