consecutive_set< T > Class Template Reference

Set class optimized for sets containing consecutive values. More...

#include <consecutive_set.h>

List of all members.

Classes

class  empty_set_exception
 Exception that will be thrown if trying to retrieve values from an empty set. More...
class  subset_t
 Internal representation of a number of consecutive values.

Public Member Functions

 consecutive_set ()
 Initializes an empty set.
 consecutive_set (T start, T end)
 Initializes a set with a range of consecutive values.
void swap (consecutive_set &set)
 Swap contents of two sets.
std::ostream & print (std::ostream &os) const
 Print contents of set to output stream.
bool is_consistent () const
 Checks consistency of the objects internal structures.
consecutive_set sum (const consecutive_set &set) const
 Calculate union with other set.
void sum_update (const consecutive_set &set)
 Update set to contain union with other set.
consecutive_set intersection (const consecutive_set &set) const
 Calculate intersection with other set.
void intersection_update (const consecutive_set &set)
 Update set to contain intersection with other set.
consecutive_set diff (const consecutive_set &set) const
 Calculate difference to other set.
void diff_update (const consecutive_set &set)
 Update set to contain difference to other set. All value that exist in both sets will be removed from the set.
consecutive_set symdiff (const consecutive_set &set) const
 Calculate symmetric difference to other set.
void symdiff_update (const consecutive_set &set)
 Update set to contain symmetric difference to other set. Removes all values that exist in both sets and add those that only existed in the second set.
bool is_subset (const consecutive_set &set) const
 Check if set is a subset. The set is a subset to the other set if all values in the set exists in the other set.
bool is_superset (const consecutive_set &set) const
 Check if set is a superset. The set is a superset to the other set if all values in the other set exists in the set.
void add (T value)
 Add a single value to set. Nothing will be changed if a value that already exists in the set is added again.
void remove (T value)
 Remove a value from the set. The value that is to be removed must exist in the set or an assertion will fail.
bool contains (T value) const
 Check if a value exists in the set.
pop ()
 Remove and return a value from the set. Throws exception if the set is empty.
pop (const consecutive_set &constraints)
 Remove and return a value from a set and within constraints. Will return the smallest value found in the intersection of the set and constraints set, and throws an empty_set_exception if that set is empty.
consecutive_set pop (T num_values)
 Remove and return a subset. Will return the smallest values found in the set. May return less than the number of requested values.
consecutive_set pop (T num_values, const consecutive_set &constraints)
 Remove and return values from a set and within constraints. Will return the smallest values found in the intersection of the set and constraints set. May return less than the number of requested values.
pop_back ()
 Remove and return a value from the set. Throws exception if the set is empty.
pop_back (const consecutive_set &constraints)
 Remove and return a value from a set and within constraints. Will return the highest value found in the intersection of the set and constraints set, and throws an empty_set_exception if that set is empty.
consecutive_set pop_back (T num_values)
 Remove and return a subset. Will return the highest values found in the set. May return less than the number of requested values.
consecutive_set pop_back (T num_values, const consecutive_set &constraints)
 Remove and return values from a set and within constraints. Will return the highest values found in the intersection of the set and constraints set. May return less than the number of requested values.
void clear ()
 Empties the set.
size () const
 Returns the number of values in the set.
bool operator<= (const consecutive_set &set) const
 Checks if the set is a subset.
bool operator>= (const consecutive_set &set) const
 Checks if the set is a superset.
consecutive_setoperator|= (const consecutive_set &set)
 Update set to contain the union of the two sets.
consecutive_setoperator|= (T value)
 Update set to contain the union of the set and the value.
consecutive_set operator| (const consecutive_set &set) const
 Return a new set containing the union of the two sets.
consecutive_setoperator&= (const consecutive_set &set)
 Update set to contain the intersection of the two sets.
consecutive_set operator& (const consecutive_set &set) const
 Return a new set containing the intersection of the two sets.
consecutive_setoperator-= (const consecutive_set &set)
 Update set to contain the difference of the two sets.
consecutive_setoperator-= (T value)
 Update set to contain the difference of the set and the value.
consecutive_set operator- (const consecutive_set &set) const
 Return a new set containing the difference of the two sets.
consecutive_setoperator^= (const consecutive_set &set)
 Update set to contain the symmetric difference of the two sets.
consecutive_set operator^ (const consecutive_set &set) const
 Return a new set containing the symmetric difference of the two sets.


Detailed Description

template<typename T>
class consecutive_set< T >

Set class optimized for sets containing consecutive values.

Constructor & Destructor Documentation

template<typename T >
consecutive_set< T >::consecutive_set ( start,
end 
) [inline]

Initializes a set with a range of consecutive values.

Parameters:
start First value in set
end Last value in set


Member Function Documentation

template<typename T >
void consecutive_set< T >::add ( value  )  [inline]

Add a single value to set. Nothing will be changed if a value that already exists in the set is added again.

Parameters:
value Value that shall be added to the set
See also:
operator|=(T)

template<typename T >
bool consecutive_set< T >::contains ( value  )  const [inline]

Check if a value exists in the set.

Parameters:
value Value to inspect
Returns:
true if value exists in the set

template<typename T >
consecutive_set< T > consecutive_set< T >::diff ( const consecutive_set< T > &  set  )  const [inline]

Calculate difference to other set.

Parameters:
set Second set containing values to be removed from the new set
Returns:
New set containing all values that only existed in this set
See also:
operator-()

template<typename T >
void consecutive_set< T >::diff_update ( const consecutive_set< T > &  set  )  [inline]

Update set to contain difference to other set. All value that exist in both sets will be removed from the set.

Parameters:
set Second set containing values to be removed from the set
See also:
operator-=()

template<typename T >
consecutive_set< T > consecutive_set< T >::intersection ( const consecutive_set< T > &  set  )  const [inline]

Calculate intersection with other set.

Parameters:
set Second set used for calculation of the intersection
Returns:
New set containing intersection of the two sets
See also:
operator&()

template<typename T >
void consecutive_set< T >::intersection_update ( const consecutive_set< T > &  set  )  [inline]

Update set to contain intersection with other set.

Parameters:
set Second set used for calculation of the intersection
See also:
operator&=()

template<typename T >
bool consecutive_set< T >::is_consistent (  )  const [inline]

Checks consistency of the objects internal structures.

Returns:
true if internal representation of the set is correct

template<typename T >
bool consecutive_set< T >::is_subset ( const consecutive_set< T > &  set  )  const [inline]

Check if set is a subset. The set is a subset to the other set if all values in the set exists in the other set.

Parameters:
set Other set
Returns:
true if the set is a subset
See also:
operator<=()

template<typename T >
bool consecutive_set< T >::is_superset ( const consecutive_set< T > &  set  )  const [inline]

Check if set is a superset. The set is a superset to the other set if all values in the other set exists in the set.

Parameters:
set Other set
Returns:
true if the set is a superset
See also:
operator>=()

template<typename T >
consecutive_set< T > consecutive_set< T >::operator& ( const consecutive_set< T > &  set  )  const [inline]

Return a new set containing the intersection of the two sets.

See also:
intersection()

template<typename T >
consecutive_set< T > & consecutive_set< T >::operator&= ( const consecutive_set< T > &  set  )  [inline]

Update set to contain the intersection of the two sets.

See also:
intersection_update()

template<typename T >
consecutive_set< T > consecutive_set< T >::operator- ( const consecutive_set< T > &  set  )  const [inline]

Return a new set containing the difference of the two sets.

See also:
diff()

template<typename T >
consecutive_set< T > & consecutive_set< T >::operator-= ( value  )  [inline]

Update set to contain the difference of the set and the value.

See also:
remove()

template<typename T >
consecutive_set< T > & consecutive_set< T >::operator-= ( const consecutive_set< T > &  set  )  [inline]

Update set to contain the difference of the two sets.

See also:
diff_update()

template<typename T >
bool consecutive_set< T >::operator<= ( const consecutive_set< T > &  set  )  const [inline]

Checks if the set is a subset.

See also:
is_subset()

template<typename T >
bool consecutive_set< T >::operator>= ( const consecutive_set< T > &  set  )  const [inline]

Checks if the set is a superset.

See also:
is_superset()

template<typename T >
consecutive_set< T > consecutive_set< T >::operator^ ( const consecutive_set< T > &  set  )  const [inline]

Return a new set containing the symmetric difference of the two sets.

See also:
symdiff()

template<typename T >
consecutive_set< T > & consecutive_set< T >::operator^= ( const consecutive_set< T > &  set  )  [inline]

Update set to contain the symmetric difference of the two sets.

See also:
symdiff_update()

template<typename T >
consecutive_set< T > consecutive_set< T >::operator| ( const consecutive_set< T > &  set  )  const [inline]

Return a new set containing the union of the two sets.

See also:
sum()

template<typename T >
consecutive_set< T > & consecutive_set< T >::operator|= ( value  )  [inline]

Update set to contain the union of the set and the value.

See also:
add()

template<typename T >
consecutive_set< T > & consecutive_set< T >::operator|= ( const consecutive_set< T > &  set  )  [inline]

Update set to contain the union of the two sets.

See also:
sum_update()

template<typename T >
consecutive_set< T > consecutive_set< T >::pop ( num_values,
const consecutive_set< T > &  constraints 
) [inline]

Remove and return values from a set and within constraints. Will return the smallest values found in the intersection of the set and constraints set. May return less than the number of requested values.

Parameters:
num_values Requested number of values
constraints Constraints set that returned set must a subset of.
Returns:
New set with up to the requested number of values

template<typename T >
consecutive_set< T > consecutive_set< T >::pop ( num_values  )  [inline]

Remove and return a subset. Will return the smallest values found in the set. May return less than the number of requested values.

Parameters:
num_values Requested number of values
Returns:
New set with up to the requested number of values

template<typename T >
T consecutive_set< T >::pop ( const consecutive_set< T > &  constraints  )  [inline]

Remove and return a value from a set and within constraints. Will return the smallest value found in the intersection of the set and constraints set, and throws an empty_set_exception if that set is empty.

Parameters:
constraints Constraints set that returned value must be found in.
See also:
empty_set_exception
Returns:
Returns the smallest value within the set and constraints

template<typename T >
T consecutive_set< T >::pop (  )  [inline]

Remove and return a value from the set. Throws exception if the set is empty.

See also:
empty_set_exception
Returns:
Returns the smallest value in the set

template<typename T >
consecutive_set< T > consecutive_set< T >::pop_back ( num_values,
const consecutive_set< T > &  constraints 
) [inline]

Remove and return values from a set and within constraints. Will return the highest values found in the intersection of the set and constraints set. May return less than the number of requested values.

Parameters:
num_values Requested number of values
constraints Constraints set that returned set must a subset of.
Returns:
New set with up to the requested number of values

template<typename T >
consecutive_set< T > consecutive_set< T >::pop_back ( num_values  )  [inline]

Remove and return a subset. Will return the highest values found in the set. May return less than the number of requested values.

Parameters:
num_values Requested number of values
Returns:
New set with up to the requested number of values

template<typename T >
T consecutive_set< T >::pop_back ( const consecutive_set< T > &  constraints  )  [inline]

Remove and return a value from a set and within constraints. Will return the highest value found in the intersection of the set and constraints set, and throws an empty_set_exception if that set is empty.

Parameters:
constraints Constraints set that returned value must be found in.
See also:
empty_set_exception
Returns:
Returns the highest value within the set and constraints

template<typename T >
T consecutive_set< T >::pop_back (  )  [inline]

Remove and return a value from the set. Throws exception if the set is empty.

See also:
empty_set_exception
Returns:
Returns the highest value in the set

template<typename T >
std::ostream & consecutive_set< T >::print ( std::ostream &  os  )  const [inline]

Print contents of set to output stream.

Parameters:
os Output stream
Returns:
Same output stream reference as argument os

template<typename T >
void consecutive_set< T >::remove ( value  )  [inline]

Remove a value from the set. The value that is to be removed must exist in the set or an assertion will fail.

Parameters:
value Value to be removed from the set
See also:
operator-=(T)

template<typename T >
consecutive_set< T > consecutive_set< T >::sum ( const consecutive_set< T > &  set  )  const [inline]

Calculate union with other set.

Parameters:
set Second set used for calculation of the union
Returns:
New set containing union of the two sets
See also:
operator|()

template<typename T >
void consecutive_set< T >::sum_update ( const consecutive_set< T > &  set  )  [inline]

Update set to contain union with other set.

Parameters:
set Second set used for calculation of the union
See also:
operator|=()

template<typename T >
void consecutive_set< T >::swap ( consecutive_set< T > &  set  )  [inline]

Swap contents of two sets.

Parameters:
set Other set that will exchange values

template<typename T >
consecutive_set< T > consecutive_set< T >::symdiff ( const consecutive_set< T > &  set  )  const [inline]

Calculate symmetric difference to other set.

Parameters:
set Second set
Returns:
New set containing all values that only exists in one of the two sets
See also:
operator^()

template<typename T >
void consecutive_set< T >::symdiff_update ( const consecutive_set< T > &  set  )  [inline]

Update set to contain symmetric difference to other set. Removes all values that exist in both sets and add those that only existed in the second set.

Parameters:
set Second set
See also:
operator^=()


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

Generated on Wed Oct 8 22:53:02 2008 by  doxygen 1.5.7