API reference

struct IntervalSet

Public Types

typedef boost::icl::closed_interval<int, std::less> ClosedInterval

A closed interval of integers.

Public Functions

IntervalSet()

Create an empty IntervalSet.

IntervalSet(const ClosedInterval &interval)

Create an IntervalSet made of a single interval.

IntervalSet(const IntervalSet &other)

Create an IntervalSet from another IntervalSet (copy constructor).

IntervalSet(int integer)

Create an IntervalSet from a single integer.

element_const_iterator elements_begin() const

Iterator to beginning element.

Note: Iterating intervals is much more efficient (via intervals_begin() and intervals_end()).

element_const_iterator elements_end() const

Iterator to ending element.

Note: Iterating intervals is much more efficient (via intervals_begin() and intervals_end()).

const_iterator intervals_begin() const

Iterator to beginning interval.

const_iterator intervals_end() const

Iterator to ending interval.

void clear()

Remove all the elements in the IntervalSet. In other words, make it empty.

void insert(const IntervalSet &interval_set)

Insert an IntervalSet in another. This is similar to operator+=(const IntervalSet &).

void insert(ClosedInterval interval)

Insert a ClosedInterval in an IntervalSet.

void insert(int integer)

Insert an integer in an IntervalSet.

void remove(const IntervalSet &interval_set)

Remove an IntervalSet from another. This is similar to operator-=(const Intervalset &).

void remove(ClosedInterval interval)

Remove a ClosedInterval from an IntervalSet.

void remove(int integer)

Remove an integer from an IntervalSet.

IntervalSet left(unsigned int nb_integers) const

Create a sub-IntervalSet made of the nb_integers leftmost elements of the source IntervalSet.

Pre

The source IntervalSet must contains nb_integers or more elements.

IntervalSet random_pick(unsigned int nb_integers) const

Create a sub-IntervalSet made of nb_integers randomly-picked elements from the source IntervalSet.

Pre

The source IntervalSet must contains nb_integers or more elements.

const_iterator biggest_interval() const

Returns a const iterator to the biggest ClosedInterval in an IntervalSet.

int first_element() const

Returns the value of the first element of an IntervalSet.

Pre

The IntervalSet must NOT be empty.

unsigned int size() const

Returns the number of elements of an IntervalSet.

bool is_empty() const

Returns whether an IntervalSet is empty. An empty IntervalSet does not contain any element.

bool contains(int integer) const

Returns whether an IntervalSet contains an integer.

bool contains(const ClosedInterval &interval) const

Returns whether an IntervalSet fully contains a ClosedInterval.

bool is_subset_of(const IntervalSet &other) const

Returns whether an IntervalSet is a subset of another IntervalSet.

std::string to_string_brackets(const std::string &union_str = "∪", const std::string &opening_bracket = "[", const std::string &closing_bracket = "]", const std::string &sep = ",") const

Returns a string representation of an IntervalSet.

This is the classical representation used in mathematics. For example, {1,2,3,7} is represented as [1,3]∪[7].

std::string to_string_hyphen(const std::string &sep = ",", const std::string &joiner = "-") const

Returns a string representation of an IntervalSet.

This is a compact representation where {1,2,3,7} is represented as 1-3,7. Use sep=’ ‘ to get a Batsim-compatible representation (see Batsim documentation about Interval sets representation).

std::string to_string_elements(const std::string &sep = ",") const

Returns a string representation of an IntervalSet.

This is the set representation of an IntervalSet. For example, {1,2,3,7} is represented as 1,2,3,7

IntervalSet &operator=(const IntervalSet &other)

Assignment operator. Reset an IntervalSet content to the one of another IntervalSet.

IntervalSet &operator=(const IntervalSet::ClosedInterval &interval)

Assignment operator. Reset an IntervalSet content to the one of a ClosedInterval.

bool operator==(const IntervalSet &other) const

Returns whether two IntervalSet exactly contain the same elements.

bool operator!=(const IntervalSet &other) const

Returns whether the content of two IntervalSet is different.

IntervalSet &operator-=(const IntervalSet &other)

Difference + assignment operator. This is similar to remove(const IntervalSet &).

a -= b; means “Set a’s value to be a without the elements of b”.

IntervalSet &operator+=(const IntervalSet &other)

Union + assignment operator. This is similar to insert(const IntervalSet &).

a += b; means “Set a’s value to be the union of a and b”.

IntervalSet operator-(const IntervalSet &other) const

Difference operator. a - b returns an IntervalSet of the elements that are in a but are not in b.

IntervalSet operator+(const IntervalSet &other) const

Union operator. a + b returns an IntervalSet of the elements that are in a, in b, or both in a and b.

int operator[](int index) const

Subscript operator.

Returns the index-th element of the IntervalSet.

Pre

index must be positive and strictly smaller than size()

Public Static Functions

static IntervalSet from_string_hyphen(const std::string &str, const std::string &sep = ",", const std::string &joiner = "-")

Parse an IntervalSet string representation and return the corresponding IntervalSet.

See IntervalSet::to_string_hyphen for representation details.

static IntervalSet empty_interval_set()

Returns an empty IntervalSet.