Brick Library 0.1
Performance-portable stencil datalayout & codegen
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Related Functions | List of all members
BitSet Struct Reference

Set using bitfield. More...

#include <bitset.h>

Public Member Functions

 BitSet ()
 Default to empty set.
 
 BitSet (uint64_t s)
 Initialize a set based on an unsigned bitfield.
 
 BitSet (std::initializer_list< int > l)
 Initialize a set based on a list of numbers.
 
BitSetflip (long pos)
 Flipping an element.
 
long size () const
 The number of elements currently stored in the set.
 
bool get (long pos) const
 Return whether a number is in the set.
 
BitSet operator& (BitSet a) const
 Intersection with another set.
 
BitSet operator| (BitSet a) const
 Union with another set.
 
BitSet operator^ (BitSet a) const
 \(A \cup B - A \cap B\)
 
 operator bool () const
 Test emptiness, true if not empty.
 
bool operator<= (BitSet a) const
 True if \(A \subseteq B\).
 
bool operator>= (BitSet a) const
 True if \(A \supseteq B\).
 
BitSet operator! () const
 Negate all elements in the set, not a set operation.
 

Static Public Member Functions

static uint64_t to_set (long pos)
 Turn number into corresponding element of set.
 

Public Attributes

uint64_t set
 The bitfield of this set.
 

Static Public Attributes

static const long zero = 31
 negative zero start at 31 (1<<31).
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &os, const BitSet &bs)
 Print a bit set.
 
std::istream & operator>> (std::istream &is, BitSet &bs)
 Read a bit set.
 

Detailed Description

Set using bitfield.

Numbers are translated into elements and then stored in the bitfield. Can only held numbers in \([-32,31]\).

Constructor & Destructor Documentation

◆ BitSet() [1/3]

BitSet::BitSet ( )
inline

Default to empty set.

◆ BitSet() [2/3]

BitSet::BitSet ( uint64_t  s)
inline

Initialize a set based on an unsigned bitfield.

◆ BitSet() [3/3]

BitSet::BitSet ( std::initializer_list< int >  l)
inline

Initialize a set based on a list of numbers.

Parameters
lA list of numbers

Example:

BitSet bs = {1,-1,2};
Set using bitfield.
Definition: bitset.h:18
Here is the call graph for this function:

Member Function Documentation

◆ flip()

BitSet & BitSet::flip ( long  pos)
inline

Flipping an element.

Parameters
posthe number
Returns
a new set

Add the element if not exist, or remove it if it does.

Here is the call graph for this function:

◆ get()

bool BitSet::get ( long  pos) const
inline

Return whether a number is in the set.

Here is the call graph for this function:

◆ operator bool()

BitSet::operator bool ( ) const
inline

Test emptiness, true if not empty.

◆ operator!()

BitSet BitSet::operator! ( ) const
inline

Negate all elements in the set, not a set operation.

Returns
a new set

For example:

BitSet bs = {1,-2,3};
BitSet nb = !bs; // {-1,2,3}

◆ operator&()

BitSet BitSet::operator& ( BitSet  a) const
inline

Intersection with another set.

◆ operator<=()

bool BitSet::operator<= ( BitSet  a) const
inline

True if \(A \subseteq B\).

◆ operator>=()

bool BitSet::operator>= ( BitSet  a) const
inline

True if \(A \supseteq B\).

◆ operator^()

BitSet BitSet::operator^ ( BitSet  a) const
inline

\(A \cup B - A \cap B\)

◆ operator|()

BitSet BitSet::operator| ( BitSet  a) const
inline

Union with another set.

◆ size()

long BitSet::size ( ) const
inline

The number of elements currently stored in the set.

◆ to_set()

static uint64_t BitSet::to_set ( long  pos)
inlinestatic

Turn number into corresponding element of set.

Parameters
posInput number
Returns
an element of set

Friends And Related Function Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream &  os,
const BitSet bs 
)
related

Print a bit set.

Example:

BitSet bs = {1,-2,3};
std::cout << bs; // {1+2-3+}
Here is the call graph for this function:

◆ operator>>()

std::istream & operator>> ( std::istream &  is,
BitSet bs 
)
related

Read a bit set.

Input is the same format as output. Numbers are separated by appended sign.

Here is the call graph for this function:

Member Data Documentation

◆ set

uint64_t BitSet::set

The bitfield of this set.

◆ zero

const long BitSet::zero = 31
static

negative zero start at 31 (1<<31).


The documentation for this struct was generated from the following file: