Note that there are some explanatory texts on larger screens.

plurals
  1. POUnderstanding this bitset implementation (C++)
    primarykey
    data
    text
    <p>I just got this frame for a sudoku solver, but I don't understand the syntax they've used and how I'm supposed to proceed. They call it a bitset, but upon searching for it I found nothing similar. </p> <pre><code> // This file contains a simple implementation of sets of // digits between 1 and 9, called fields. #ifndef __SUDOKU_FIELD_H__ #define __SUDOKU_FIELD_H__ #include &lt;iostream&gt; #include &lt;cassert&gt; #include "digit.h" class Field { private: // Use integers for a bitset unsigned int _digits; // Number of digits in bitset unsigned int _size; public: // Initialize with all digits between 1 and 9 included Field(void) : _digits((1 &lt;&lt; 1) | (1 &lt;&lt; 2) | (1 &lt;&lt; 3) | (1 &lt;&lt; 4) | (1 &lt;&lt; 5) | (1 &lt;&lt; 6) | (1 &lt;&lt; 7) | (1 &lt;&lt; 8) | (1 &lt;&lt; 9)), _size(9) {} // Return size of digit set (number of digits in set) unsigned int size(void) const { // FILL IN } // Test whether digit set is empty bool empty(void) const { // FILL IN } // Test whether set is assigned (that is, single digit left) bool assigned(void) const { // FILL IN } // Test whether digit d is included in set bool in(digit d) const { assert((d &gt;= 1) &amp;&amp; (d &lt;= 9)); // FILL IN } // Return digit to which the set is assigned digit value(void) const { assert(assigned()); // FILL IN } // Print digits still included void print(std::ostream&amp; os) const; // Remove digit d from set (d must be still included) void prune(digit d) { assert(in(d)); // FILL IN } // Assign field to digit d (d must be still included) void assign(digit d) { assert(in(d)); // FILL IN } }; // Print field inline std::ostream&amp; operator&lt;&lt;(std::ostream&amp; os, const Field&amp; f) { f.print(os); return os; } #endif </code></pre> <p>Obviously the //FILL IN's are for me to write, and the meaning of the bitset is 9 bits where all of them initially are set to 1. The question is how I manipulate or use them.</p> <p>Oh, by the way, this is a digit:</p> <pre><code>#ifndef __SUDOKU_DIGIT_H__ #define __SUDOKU_DIGIT_H__ typedef unsigned char digit; #endif </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.
 

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