Lunchbox  1.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lunchbox::UnorderedIntervalSet< T > Class Template Reference

A container to store intervals of elements efficently. More...

#include <unorderedIntervalSet.h>

+ Collaboration diagram for lunchbox::UnorderedIntervalSet< T >:

Public Member Functions

 UnorderedIntervalSet ()
 Construct a new interval set. More...
 
void insert (const T &element)
 Insert a new element. More...
 
void insert (const T &startElement, const T &endElement)
 Insert a new closed interval of elements. More...
 
void insert (const UnorderedIntervalSet &rhs)
 Insert another interval set into this. More...
 
void erase (const T &element)
 Remove the given element. More...
 
void erase (const T &startElement, const T &endElement)
 Remove all element inside the given closed interval. More...
 
void clear ()
 Remove all stored elements. More...
 
void swap (UnorderedIntervalSet &rhs)
 Swap this container with another one. More...
 
bool exists (const T &element) const
 
const_iterator find (const T &element) const
 
const_iterator begin () const
 
const_iterator end () const
 
size_t size () const
 
bool empty () const
 

Detailed Description

template<typename T>
class lunchbox::UnorderedIntervalSet< T >

A container to store intervals of elements efficently.

The type can be any class or typename which has the semantics of natural numbers for addition and comparison operations. The intervals are stored in an unordered fashion. Not thread-safe.

Example:

/* Copyright (c) 2013, Daniel Nachbaur <daniel.nachbaur@epfl.ch>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 2.1 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <test.h>
#include <lunchbox/unorderedIntervalSet.h>
int main( int, char** )
{
SetType set;
TEST( set.empty( ));
set.insert( 2 );
TEST( set.size() == 1 );
set.insert( 1, 5 );
TEST( set.exists( 3 ));
TEST( set.size() == 5 );
set.insert( 1, 5 );
TEST( set.size() == 5 );
set.insert( 2, 4 );
TEST( set.size() == 5 );
TEST( set.find( 0 ) == set.end( ));
TEST( *set.find( 3 ) == 3 );
TEST( set.find( 6 ) == set.end( ));
size_t i = 1;
for( SetType::const_iterator it = set.begin(); it != set.end(); ++it, ++i )
TEST( *it == i );
set.erase( 3, 4 );
TEST( set.size() == 3 );
set.erase( 2 );
TEST( set.size() == 2 );
TEST( set.exists( 1 ));
TEST( set.exists( 5 ));
set.clear();
TEST( set.empty( ));
set.insert( 0, 1 );
TEST( set.size() == 2 );
set.insert( 3, 5 );
TEST( set.size() == 5 );
SetType::const_iterator it = set.begin();
TEST( *it == 0 );
++it;
TEST( *it == 1 );
++it;
TEST( *it == 3 );
++it;
TEST( *it == 4 );
++it;
TEST( *it == 5 );
set.erase( 4, 7 );
TEST( set.size() == 3 );
set.erase( 40, 70 );
TEST( set.size() == 3 );
return EXIT_SUCCESS;
}

Definition at line 37 of file unorderedIntervalSet.h.

Constructor & Destructor Documentation

template<typename T >
lunchbox::UnorderedIntervalSet< T >::UnorderedIntervalSet ( )

Construct a new interval set.

Version
1.7.1

Member Function Documentation

template<typename T >
const_iterator lunchbox::UnorderedIntervalSet< T >::begin ( ) const
Returns
an iterator to the first element.
Version
1.7.1
template<typename T >
void lunchbox::UnorderedIntervalSet< T >::clear ( )

Remove all stored elements.

Version
1.7.1
template<typename T >
bool lunchbox::UnorderedIntervalSet< T >::empty ( ) const
Returns
true if container is empty.
Version
1.7.1
template<typename T >
const_iterator lunchbox::UnorderedIntervalSet< T >::end ( ) const
Returns
an iterator to the end of the interval set.
Version
1.7.1
template<typename T >
void lunchbox::UnorderedIntervalSet< T >::erase ( const T &  element)

Remove the given element.

Version
1.7.1
template<typename T >
void lunchbox::UnorderedIntervalSet< T >::erase ( const T &  startElement,
const T &  endElement 
)

Remove all element inside the given closed interval.

Version
1.7.1
template<typename T >
bool lunchbox::UnorderedIntervalSet< T >::exists ( const T &  element) const
Returns
true if element exists.
Version
1.7.1
template<typename T >
const_iterator lunchbox::UnorderedIntervalSet< T >::find ( const T &  element) const
Returns
an iterator to element if stored, end() otherwise.
Version
1.7.1
template<typename T >
void lunchbox::UnorderedIntervalSet< T >::insert ( const T &  element)

Insert a new element.

Version
1.7.1
template<typename T >
void lunchbox::UnorderedIntervalSet< T >::insert ( const T &  startElement,
const T &  endElement 
)

Insert a new closed interval of elements.

Version
1.7.1
template<typename T >
void lunchbox::UnorderedIntervalSet< T >::insert ( const UnorderedIntervalSet< T > &  rhs)

Insert another interval set into this.

Version
1.7.1
template<typename T >
size_t lunchbox::UnorderedIntervalSet< T >::size ( ) const
Returns
the number of elements in the stored intervals.
Version
1.7.1
template<typename T >
void lunchbox::UnorderedIntervalSet< T >::swap ( UnorderedIntervalSet< T > &  rhs)

Swap this container with another one.

Version
1.7.1

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