Skip to content

Commit

Permalink
Merge pull request #276 from eile/master
Browse files Browse the repository at this point in the history
Rename UnorderedIntervalSet -> IntervalSet
  • Loading branch information
eile committed Sep 29, 2016
2 parents 4ebe04d + d292545 commit 3a51571
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 103 deletions.
4 changes: 3 additions & 1 deletion doc/Changelog.md
Expand Up @@ -2,7 +2,9 @@

# git master

* [](https://github.com/Eyescale/Lunchbox/pull/):
* [276](https://github.com/Eyescale/Lunchbox/pull/276):
Renamed UnorderedIntervalSet to IntervalSet
* [275](https://github.com/Eyescale/Lunchbox/pull/275):
Remove obsolete MPI and OpenMP classes
* [272](https://github.com/Eyescale/Lunchbox/pull/272):
Add getWorkDir()
Expand Down
4 changes: 2 additions & 2 deletions lunchbox/CMakeLists.txt
Expand Up @@ -22,6 +22,8 @@ set(LUNCHBOX_PUBLIC_HEADERS
hash.h
indexIterator.h
init.h
intervalSet.h
intervalSet.ipp
launcher.h
lfQueue.h
lfQueue.ipp
Expand Down Expand Up @@ -62,8 +64,6 @@ set(LUNCHBOX_PUBLIC_HEADERS
timedLock.h
tls.h
types.h
unorderedIntervalSet.h
unorderedIntervalSet.ipp
visitorResult.h
)
if(NOT LUNCHBOX_BUILD_V2_API)
Expand Down
25 changes: 12 additions & 13 deletions lunchbox/unorderedIntervalSet.h → lunchbox/intervalSet.h
@@ -1,6 +1,6 @@

/* Copyright (c) 2008, Juan Hernando <jhernando@fi.upm.es>
* 2013, Daniel Nachbaur <danielnachbaur@epfl.ch>
/* Copyright (c) 2008-2016, Juan Hernando <jhernando@fi.upm.es>
* Daniel Nachbaur <danielnachbaur@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
Expand All @@ -16,8 +16,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef LUNCHBOX_UNORDEREDINTERVALSET_H
#define LUNCHBOX_UNORDEREDINTERVALSET_H
#ifndef LUNCHBOX_INTERVALSET_H
#define LUNCHBOX_INTERVALSET_H

#include <lunchbox/types.h>
#include <set>
Expand All @@ -29,19 +29,18 @@ namespace lunchbox
* 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.
* numbers for addition and comparison operations. Not thread-safe.
*
* Example: @include tests/unorderedIntervalSet.cpp
* Example: @include tests/IntervalSet.cpp
*/
template< typename T > class UnorderedIntervalSet
template< typename T > class IntervalSet
{
public:
/** Element iterator which points to a current element of type T. */
class const_iterator;

/** Construct a new interval set. @version 1.7.1 */
UnorderedIntervalSet();
IntervalSet();

/** Insert a new element. @version 1.7.1 */
void insert( const T& element );
Expand All @@ -50,7 +49,7 @@ template< typename T > class UnorderedIntervalSet
void insert( const T& startElement, const T& endElement );

/** Insert another interval set into this. @version 1.7.1 */
void insert( const UnorderedIntervalSet& rhs );
void insert( const IntervalSet& rhs );

/** Remove the given element. @version 1.7.1 */
void erase( const T& element );
Expand All @@ -62,7 +61,7 @@ template< typename T > class UnorderedIntervalSet
void clear();

/** Swap this container with another one. @version 1.7.1 */
void swap( UnorderedIntervalSet& rhs );
void swap( IntervalSet& rhs );

/** @return true if element exists. @version 1.7.1 */
bool exists( const T& element ) const;
Expand Down Expand Up @@ -109,6 +108,6 @@ template< typename T > class UnorderedIntervalSet
};
}

#include "unorderedIntervalSet.ipp" // template implementation
#include "intervalSet.ipp" // template implementation

#endif // LUNCHBOX_UNORDEREDINTERVALSET_H
#endif // LUNCHBOX_INTERVALSET_H
77 changes: 30 additions & 47 deletions lunchbox/unorderedIntervalSet.ipp → lunchbox/intervalSet.ipp
@@ -1,6 +1,6 @@

/* Copyright (c) 2008, Juan Hernando <jhernando@fi.upm.es>
* 2013, Daniel Nachbaur <danielnachbaur@epfl.ch>
/* Copyright (c) 2008-2016, Juan Hernando <jhernando@fi.upm.es>
* Daniel Nachbaur <danielnachbaur@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
Expand All @@ -25,10 +25,9 @@ namespace lunchbox
{

template< typename T >
class UnorderedIntervalSet< T >::const_iterator :
public boost::iterator_facade<
typename UnorderedIntervalSet< T >::const_iterator,
T, std::forward_iterator_tag, T >
class IntervalSet< T >::const_iterator :
public boost::iterator_facade< typename IntervalSet< T >::const_iterator,
T, std::forward_iterator_tag, T >
{
public:
// Default constructor to an end() iterator.
Expand All @@ -37,27 +36,25 @@ public:

private:
friend class boost::iterator_core_access;
friend class UnorderedIntervalSet;
friend class IntervalSet;

typedef typename UnorderedIntervalSet< T >::EdgeSet::const_iterator
typedef typename IntervalSet< T >::EdgeSet::const_iterator
edge_iterator;

const_iterator( const UnorderedIntervalSet& set,
const edge_iterator& interval)
const_iterator( const IntervalSet& set, const edge_iterator& interval )
: _intervalIteratorEnd( set._intervals.end( ))
, _startEdge( interval )
{
if (_startEdge != _intervalIteratorEnd )
_value = _startEdge->first;
}

const_iterator( const UnorderedIntervalSet & set,
const edge_iterator & interval, const T& current )
const_iterator( const IntervalSet & set, const edge_iterator & interval,
const T& current )
: _value( current )
, _intervalIteratorEnd( set._intervals.end( ))
, _startEdge( interval )
{
}
{}

void increment()
{
Expand Down Expand Up @@ -95,26 +92,22 @@ private:
edge_iterator _startEdge;
};

template < typename T >
UnorderedIntervalSet< T >::UnorderedIntervalSet()
template < typename T > IntervalSet< T >::IntervalSet()
: _size( 0 )
{}

template < typename T >
void UnorderedIntervalSet< T >::insert( const T& element )
template < typename T > void IntervalSet< T >::insert( const T& element )
{
insert( element, element );
}

template < typename T >
void UnorderedIntervalSet< T >::erase( const T& element )
template < typename T > void IntervalSet< T >::erase( const T& element )
{
erase( element, element );
}

template < typename T >
void UnorderedIntervalSet< T >::insert( const T& startElement,
const T& endElement )
template < typename T > void IntervalSet< T >::insert( const T& startElement,
const T& endElement )
{
LBASSERT( startElement <= endElement );

Expand Down Expand Up @@ -227,9 +220,8 @@ void UnorderedIntervalSet< T >::insert( const T& startElement,
LBASSERT( _intervals.size() % 2 == 0 );
}

template < typename T >
void UnorderedIntervalSet< T >::erase( const T& startElement,
const T& endElement )
template < typename T > void IntervalSet< T >::erase( const T& startElement,
const T& endElement )
{
LBASSERT( startElement <= endElement );

Expand Down Expand Up @@ -310,8 +302,7 @@ void UnorderedIntervalSet< T >::erase( const T& startElement,
LBASSERT( _intervals.size() % 2 == 0 );
}

template < typename T >
void UnorderedIntervalSet< T >::insert( const UnorderedIntervalSet& rhs )
template < typename T > void IntervalSet< T >::insert( const IntervalSet& rhs )
{
for( typename EdgeSet::const_iterator i = rhs._intervals.begin();
i != rhs._intervals.end(); ++i )
Expand All @@ -320,22 +311,19 @@ void UnorderedIntervalSet< T >::insert( const UnorderedIntervalSet& rhs )
}
}

template < typename T >
void UnorderedIntervalSet< T >::clear()
template < typename T > void IntervalSet< T >::clear()
{
_intervals.clear();
_size = 0;
}

template < typename T >
bool UnorderedIntervalSet< T >::exists( const T& element ) const
template < typename T > bool IntervalSet< T >::exists( const T& element ) const
{
return find( element ) != end();
}

template < typename T >
typename UnorderedIntervalSet< T >::const_iterator
UnorderedIntervalSet< T >::find( const T& element ) const
template < typename T > typename IntervalSet< T >::const_iterator
IntervalSet< T >::find( const T& element ) const
{
if( _intervals.empty( ))
return end();
Expand All @@ -356,36 +344,31 @@ UnorderedIntervalSet< T >::find( const T& element ) const
return end();
}

template < typename T >
typename UnorderedIntervalSet< T >::const_iterator
UnorderedIntervalSet< T >::begin() const
template < typename T > typename IntervalSet< T >::const_iterator
IntervalSet< T >::begin() const
{
if( _intervals.empty( ))
return end();
return const_iterator( *this, _intervals.begin( ));
}

template < typename T >
typename UnorderedIntervalSet< T >::const_iterator
UnorderedIntervalSet< T >::end() const
template < typename T > typename IntervalSet< T >::const_iterator
IntervalSet< T >::end() const
{
return const_iterator( *this, _intervals.end());
}

template < typename T >
size_t UnorderedIntervalSet< T >::size() const
template < typename T > size_t IntervalSet< T >::size() const
{
return _size;
}

template < typename T >
bool UnorderedIntervalSet< T >::empty() const
template < typename T > bool IntervalSet< T >::empty() const
{
return size() == 0;
}

template < typename T >
void UnorderedIntervalSet< T >::swap( UnorderedIntervalSet& rhs )
template < typename T > void IntervalSet< T >::swap( IntervalSet& rhs )
{
_intervals.swap( rhs._intervals );
}
Expand Down
6 changes: 5 additions & 1 deletion tests/CMakeLists.txt
@@ -1,7 +1,7 @@
# Copyright (c) 2010-2016, Daniel Pfeifer
# Stefan Eilemann <eile@eyescale.ch>
#
# Change this number when adding tests to force a CMake run: 9
# Change this number when adding tests to force a CMake run: 0

include(InstallFiles)
include_directories(${PROJECT_SOURCE_DIR}/tests)
Expand All @@ -19,6 +19,10 @@ endif()
if(COVERAGE AND TRAVIS)
list(APPEND EXCLUDE_FROM_TESTS anySerialization.cpp) #timeout in lcov gather
endif()
if(COMMON_USE_CXX03)
list(APPEND EXCLUDE_FROM_TESTS perf/mutex.cpp)
endif()

set(UNIT_AND_PERF_TESTS persistentMap.cpp)

include(CommonCTest)
Expand Down
6 changes: 3 additions & 3 deletions tests/unorderedIntervalSet.cpp → tests/intervalSet.cpp
@@ -1,5 +1,5 @@

/* Copyright (c) 2013, Daniel Nachbaur <daniel.nachbaur@epfl.ch>
/* Copyright (c) 2013-2016, 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
Expand All @@ -16,11 +16,11 @@
*/

#include <lunchbox/test.h>
#include <lunchbox/unorderedIntervalSet.h>
#include <lunchbox/intervalSet.h>

int main( int, char** )
{
typedef lunchbox::UnorderedIntervalSet< size_t > SetType;
typedef lunchbox::IntervalSet< size_t > SetType;
SetType set;
TEST( set.empty( ));

Expand Down
20 changes: 8 additions & 12 deletions tests/perf/lock.cpp
Expand Up @@ -18,7 +18,6 @@
#define TEST_RUNTIME 600 // seconds, needed for NighlyMemoryCheck
#include <lunchbox/test.h>

#include <lunchbox/atomic.h>
#include <lunchbox/clock.h>
#include <lunchbox/debug.h>
#include <lunchbox/init.h>
Expand Down Expand Up @@ -48,9 +47,6 @@ template< class T > class Thread : public lunchbox::Thread
while( LB_LIKELY( _running ))
{
lock->set();
#ifndef _MSC_VER
TEST( lock->isSet( ));
#endif
lock->unset();
++ops;
}
Expand All @@ -61,31 +57,33 @@ template< class T > void _test()
{
const size_t nThreads = 16;

T* lock = new T;
lock->set();
T lock;
lock.set();

Thread< T > threads[MAXTHREADS];
for( size_t i = 1; i <= nThreads; i = i << 1 )
{
_running = true;
for( size_t j = 0; j < i; ++j )
{
threads[j].lock = lock;
threads[j].lock = &lock;
TEST( threads[j].start( ));
}
lunchbox::sleep( 10 ); // let threads initialize

_clock.reset();
lock->unset();
lock.unset();
lunchbox::sleep( TIME ); // let threads run
_running = false;

for( size_t j = 0; j < i; ++j )
TEST( threads[j].join( ));
const float time = _clock.getTimef();

TEST( !lock->isSet( ));
lock->set();
#ifndef NDEBUG
TEST( !lock.isSet( ));
#endif
lock.set();

size_t ops = 0;
for( size_t j = 0; j < nThreads; ++j )
Expand All @@ -95,8 +93,6 @@ template< class T > void _test()
<< std::setw(12) << /*set, test, unset*/ 3 * ops / time
<< ", " << std::setw(3) << i << std::endl;
}

delete lock;
}

int main( int argc, char **argv )
Expand Down

0 comments on commit 3a51571

Please sign in to comment.