Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>int checker</code> is used here as a storage for bits. Every bit in integer value can be treated as a flag, so eventually <code>int</code> is an array of bits (flag). Each bit in your code states whether the character with bit's index was found in string or not. You could use bit vector for the same reason instead of <code>int</code>. There are two differences between them:</p> <ul> <li><p><strong>Size</strong>. <code>int</code> has fixed size, usually 4 bytes which means 8*4=32 bits (flags). Bit vector usually can be of different size or you should specify the size in constructor.</p></li> <li><p><strong>API</strong>. With bit vectors you will have easier to read code, probably something like this:</p> <p><code>vector.SetFlag(4, true); // set flag at index 4 as true</code></p> <p>for <code>int</code> you will have lower-level bit logic code:</p> <p><code>checker |= (1 &lt;&lt; 5); // set flag at index 5 to true</code></p></li> </ul> <p>Also probably <code>int</code> may be a little bit faster, because operations with bits are very low level and can be executed as-is by CPU. BitVector allows writing a little bit less cryptic code instead plus it can store more flags.</p> <p>For future reference: bit vector is also known as bitSet or bitArray. Here are some links to this data structure for different languages/platforms:</p> <ul> <li>CPP: <a href="http://www.cplusplus.com/reference/bitset/bitset/" rel="noreferrer">BitSet</a></li> <li>Java: <a href="http://docs.oracle.com/javase/7/docs/api/java/util/BitSet.html" rel="noreferrer">BitSet</a></li> <li>C#: <a href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.bitvector32.aspx" rel="noreferrer">BitVector32</a> and <a href="http://msdn.microsoft.com/en-us/library/system.collections.bitarray.aspx" rel="noreferrer">BitArray</a></li> </ul>
 

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