ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
BoolSet.h

The SET of the integers in \( [ 0 , N ) \) as a boolean vector of section 8.1. More...

Files

file  ADS/set/BoolSet.h
 The SET of the integers in \( [ 0 , N ) \) as a boolean vector of section 8.1: contains(), insert() and remove() in \( O( 1 ) \), min(), max() and forEach() in \( O( N ) \), union, intersection, difference and symmetric difference in \( \Theta( N ) \) (the first is called setUnion(), union being a keyword of C++, and so the others are setIntersection(), setDifference() and setSymmetricDifference()).

Classes

class  ADS::BoolSet
 a set of integers in \( [ 0 , N ) \) as a boolean vector More...

Functions

BoolSet ADS::setUnion (const BoolSet &A, const BoolSet &B)
 the union, a set of dimension \( \max( \mathrm{dim}( A ) , \mathrm{dim}( B ) ) \)
BoolSet ADS::setIntersection (const BoolSet &A, const BoolSet &B)
 the intersection, a set of dimension \( \min( \mathrm{dim}( A ) , \mathrm{dim}( B ) ) \)
BoolSet ADS::setDifference (const BoolSet &A, const BoolSet &B)
 the difference, a set of dimension A.dim()
BoolSet ADS::setSymmetricDifference (const BoolSet &A, const BoolSet &B)
 the symmetric difference, the items in exactly one of \( A \) and \( B \), a set of dimension \( \max( \mathrm{dim}( A ) , \mathrm{dim}( B ) ) \)

Detailed description

The SET of the integers in \( [ 0 , N ) \) as a boolean vector of section 8.1.

The definitions, the invariants and the costs of the area are in Theory of sets.

Function documentation

◆ setDifference()

BoolSet ADS::setDifference ( const BoolSet & A,
const BoolSet & B )
inline

the difference, a set of dimension A.dim()

In pseudocode (section 8.1), a word of 64 booleans at a time, a word missing in the shorter vector being 0:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{setDifference}( A , B ) \cr 2 & \quad C \gets \text{a set of dimension } \mathrm{dim}( A ) \cr 3 & \quad C.W[ k ] \gets A.W[ k ] \wedge \lnot B.W[ k ] \text{ for each word } k \text{ of } C;\ \textbf{return}\ C \end{array}} \]

◆ setIntersection()

BoolSet ADS::setIntersection ( const BoolSet & A,
const BoolSet & B )
inline

the intersection, a set of dimension \( \min( \mathrm{dim}( A ) , \mathrm{dim}( B ) ) \)

In pseudocode (section 8.1), a word of 64 booleans at a time, a word missing in the shorter vector being 0:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{setIntersection}( A , B ) \cr 2 & \quad C \gets \text{a set of dimension } \min( \mathrm{dim}( A ) , \mathrm{dim}( B ) ) \cr 3 & \quad C.W[ k ] \gets A.W[ k ] \wedge B.W[ k ] \text{ for each word } k \text{ of } C;\ \textbf{return}\ C \end{array}} \]

◆ setSymmetricDifference()

BoolSet ADS::setSymmetricDifference ( const BoolSet & A,
const BoolSet & B )
inline

the symmetric difference, the items in exactly one of \( A \) and \( B \), a set of dimension \( \max( \mathrm{dim}( A ) , \mathrm{dim}( B ) ) \)

In pseudocode (exercise 8.5), a word of 64 booleans at a time, a word missing in the shorter vector being 0:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{setSymmetricDifference}( A , B ) \cr 2 & \quad C \gets \text{a set of dimension } \max( \mathrm{dim}( A ) , \mathrm{dim}( B ) ) \cr 3 & \quad C.W[ k ] \gets A.W[ k ] \oplus B.W[ k ] \text{ for each word } k \text{ of } C;\ \textbf{return}\ C \end{array}} \]

◆ setUnion()

BoolSet ADS::setUnion ( const BoolSet & A,
const BoolSet & B )
inline

the union, a set of dimension \( \max( \mathrm{dim}( A ) , \mathrm{dim}( B ) ) \)

In pseudocode (section 8.1), a word of 64 booleans at a time, a word missing in the shorter vector being 0:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{setUnion}( A , B ) \cr 2 & \quad C \gets \text{a set of dimension } \max( \mathrm{dim}( A ) , \mathrm{dim}( B ) )\quad \triangleright \ \text{a missing word is zero} \cr 3 & \quad C.W[ k ] \gets A.W[ k ] \vee B.W[ k ] \text{ for each word } k \text{ of } C;\ \textbf{return}\ C \end{array}} \]