A dynamic set of non-negative integers. More...

#include <IndexSet.h>

Classes

class  iterator
 

Public Member Functions

 IndexSet ()
 
 IndexSet (long low, long high)
 
 IndexSet (long j)
 
long first () const
 Returns the first element, 0 if the set is empty. More...
 
long last () const
 Returns the last element, -1 if the set is empty. More...
 
long next (long j) const
 Returns the next element after j, if any; otherwise j+1. More...
 
long prev (long j) const
 
long card () const
 The cardinality of the set. More...
 
bool contains (long j) const
 Returns true iff the set contains j. More...
 
bool contains (const IndexSet &s) const
 Returns true iff the set contains s. More...
 
bool disjointFrom (const IndexSet &s) const
 Returns true iff the set is disjoint from s. More...
 
bool operator== (const IndexSet &s) const
 
bool operator!= (const IndexSet &s) const
 
void clear ()
 Set to the empty set. More...
 
void insert (long j)
 Add j to the set. More...
 
void remove (long j)
 Remove j from the set. More...
 
void insert (const IndexSet &s)
 Add s to the set (union) More...
 
void remove (const IndexSet &s)
 Remove s from the set (set minus) More...
 
void retain (const IndexSet &s)
 Retains only those elements that are also in s (intersection) More...
 
bool isInterval () const
 Is this set a contiguous interval? More...
 
void writeTo (std::ostream &str) const
 Write out the IndexSet object in binary format. More...
 
void writeToJSON (std::ostream &str) const
 Write out the IndexSet object to the output stream using JSON format. More...
 
JsonWrapper writeToJSON () const
 Write out the IndexSet object to a JsonWrapper. More...
 
iterator begin () const
 
iterator end () const
 

Static Public Member Functions

static const IndexSetemptySet ()
 Read-only access to an empty set. More...
 
static IndexSet readFrom (std::istream &str)
 Read from the stream the serialized IndexSet object in binary format. More...
 
static IndexSet readFromJSON (std::istream &str)
 Read from the stream the serialized IndexSet object using JSON format. More...
 
static IndexSet readFromJSON (const JsonWrapper &j)
 Read from the JsonWrapper the serialized IndexSet object. More...
 

Detailed Description

A dynamic set of non-negative integers.

You can iterate through a set as follows:

for (long i = s.first(); i <= s.last(); i = s.next(i)) ...
for (long i = s.last(); i >= s.first(); i = s.prev(i)) ...

Constructor & Destructor Documentation

◆ IndexSet() [1/3]

helib::IndexSet::IndexSet ( )
inline

◆ IndexSet() [2/3]

helib::IndexSet::IndexSet ( long  low,
long  high 
)
inline

◆ IndexSet() [3/3]

helib::IndexSet::IndexSet ( long  j)
inlineexplicit

Member Function Documentation

◆ begin()

iterator helib::IndexSet::begin ( ) const
inline

◆ card()

long helib::IndexSet::card ( ) const
inline

The cardinality of the set.

◆ clear()

void helib::IndexSet::clear ( )

Set to the empty set.

◆ contains() [1/2]

bool helib::IndexSet::contains ( const IndexSet s) const

Returns true iff the set contains s.

◆ contains() [2/2]

bool helib::IndexSet::contains ( long  j) const

Returns true iff the set contains j.

◆ disjointFrom()

bool helib::IndexSet::disjointFrom ( const IndexSet s) const

Returns true iff the set is disjoint from s.

◆ emptySet()

const IndexSet & helib::IndexSet::emptySet ( )
static

Read-only access to an empty set.

◆ end()

iterator helib::IndexSet::end ( ) const
inline

◆ first()

long helib::IndexSet::first ( ) const
inline

Returns the first element, 0 if the set is empty.

◆ insert() [1/2]

void helib::IndexSet::insert ( const IndexSet s)

Add s to the set (union)

◆ insert() [2/2]

void helib::IndexSet::insert ( long  j)

Add j to the set.

◆ isInterval()

bool helib::IndexSet::isInterval ( ) const
inline

Is this set a contiguous interval?

◆ last()

long helib::IndexSet::last ( ) const
inline

Returns the last element, -1 if the set is empty.

◆ next()

long helib::IndexSet::next ( long  j) const

Returns the next element after j, if any; otherwise j+1.

◆ operator!=()

bool helib::IndexSet::operator!= ( const IndexSet s) const
inline

◆ operator==()

bool helib::IndexSet::operator== ( const IndexSet s) const

◆ prev()

long helib::IndexSet::prev ( long  j) const

◆ readFrom()

IndexSet helib::IndexSet::readFrom ( std::istream &  str)
static

Read from the stream the serialized IndexSet object in binary format.

Parameters
strInput std::istream.
Returns
The deserialized IndexSet object.

◆ readFromJSON() [1/2]

IndexSet helib::IndexSet::readFromJSON ( const JsonWrapper j)
static

Read from the JsonWrapper the serialized IndexSet object.

Parameters
jThe JsonWrapper containing the serialized IndexSet object.
Returns
The deserialized IndexSet object.

◆ readFromJSON() [2/2]

IndexSet helib::IndexSet::readFromJSON ( std::istream &  str)
static

Read from the stream the serialized IndexSet object using JSON format.

Parameters
strInput std::istream.
Returns
The deserialized IndexSet object.

◆ remove() [1/2]

void helib::IndexSet::remove ( const IndexSet s)

Remove s from the set (set minus)

◆ remove() [2/2]

void helib::IndexSet::remove ( long  j)

Remove j from the set.

◆ retain()

void helib::IndexSet::retain ( const IndexSet s)

Retains only those elements that are also in s (intersection)

◆ writeTo()

void helib::IndexSet::writeTo ( std::ostream &  str) const

Write out the IndexSet object in binary format.

Parameters
strOutput std::ostream.

◆ writeToJSON() [1/2]

JsonWrapper helib::IndexSet::writeToJSON ( ) const

Write out the IndexSet object to a JsonWrapper.

Returns
The JsonWrapper.

◆ writeToJSON() [2/2]

void helib::IndexSet::writeToJSON ( std::ostream &  str) const

Write out the IndexSet object to the output stream using JSON format.

Parameters
strOutput std::ostream.