summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjan.reininghaus <jan.reininghaus@8e3bb3c2-eed4-f18f-5264-0b6c94e6926d>2013-05-14 13:40:15 +0000
committerjan.reininghaus <jan.reininghaus@8e3bb3c2-eed4-f18f-5264-0b6c94e6926d>2013-05-14 13:40:15 +0000
commit772d0888efe11e12c6849e44bdda5c0cf58d39ee (patch)
tree6ea357a7bc11d14c0cf047cd46ee1f24fb0147c2
parent595ce965ef6e07c554a91ebb8b41c8e1c06b8b32 (diff)
code cleanup
git-svn-id: https://phat.googlecode.com/svn/trunk@86 8e3bb3c2-eed4-f18f-5264-0b6c94e6926d
-rw-r--r--include/phat/boundary_matrix.h2
-rw-r--r--include/phat/representations/abstract_pivot_column.h4
-rw-r--r--include/phat/representations/bit_tree_pivot_column.h117
-rw-r--r--include/phat/representations/full_pivot_column.h31
-rw-r--r--include/phat/representations/sparse_pivot_column.h20
5 files changed, 73 insertions, 101 deletions
diff --git a/include/phat/boundary_matrix.h b/include/phat/boundary_matrix.h
index a9c4a59..7be14d8 100644
--- a/include/phat/boundary_matrix.h
+++ b/include/phat/boundary_matrix.h
@@ -45,7 +45,7 @@ namespace phat {
void set_dim( index idx, dimension dim ) { rep._set_dim( idx, dim ); }
// replaces content of @col with boundary of given index
- void get_col( index idx, column& col ) const { rep._get_col( idx, col ); }
+ void get_col( index idx, column& col ) const { col.clear(); rep._get_col( idx, col ); }
// set column @idx to the values contained in @col
void set_col( index idx, const column& col ) { rep._set_col( idx, col ); }
diff --git a/include/phat/representations/abstract_pivot_column.h b/include/phat/representations/abstract_pivot_column.h
index f441537..fbee368 100644
--- a/include/phat/representations/abstract_pivot_column.h
+++ b/include/phat/representations/abstract_pivot_column.h
@@ -47,8 +47,10 @@ namespace phat {
void release_pivot_col() {
index idx = idx_of_pivot_cols();
- if( idx != -1 )
+ if( idx != -1 ) {
+ this->matrix[ idx ].clear();
pivot_cols().get_col_and_clear( this->matrix[ idx ] );
+ }
idx_of_pivot_cols() = -1;
}
diff --git a/include/phat/representations/bit_tree_pivot_column.h b/include/phat/representations/bit_tree_pivot_column.h
index e8746f8..888e338 100644
--- a/include/phat/representations/bit_tree_pivot_column.h
+++ b/include/phat/representations/bit_tree_pivot_column.h
@@ -30,12 +30,14 @@ namespace phat {
// 'add_index' is still the real bottleneck in practice.
class bit_tree_column
{
+ protected:
+
size_t offset; // data[i + offset] = ith block of the data-bitset
typedef uint64_t block_type;
std::vector< block_type > data;
// this static is not a problem with OMP, it's initialized just after program starts
- static const size_t debrujin_magic_table[64];
+ static const size_t debrujin_magic_table[ 64 ];
enum { block_size_in_bits = 64 };
enum { block_shift = 6 };
@@ -45,118 +47,90 @@ namespace phat {
// (-x)&x isolates the rightmost bit.
// The whole method is much faster than calling log2i, and very comparable to using ScanBitForward/Reverse intrinsic,
// which should be one CPU instruction, but is not portable.
- size_t rightmost_pos(const block_type value) const
- {
- return 64 - 1 - debrujin_magic_table[((value & (-(int64_t)value))*0x07EDD5E59A4E28C2) >> 58];
+ size_t rightmost_pos( const block_type value ) const {
+ return 64 - 1 - debrujin_magic_table[ ( (value & (-(int64_t)value) ) * 0x07EDD5E59A4E28C2 ) >> 58 ];
}
- public:
+ public:
- void init(index num_cols)
- {
+ void init( index num_cols ) {
int64_t n = 1; // in case of overflow
- int64_t bottom_blocks_needed = (num_cols+block_size_in_bits-1)/block_size_in_bits;
+ int64_t bottom_blocks_needed = ( num_cols + block_size_in_bits - 1 ) / block_size_in_bits;
int64_t upper_blocks = 1;
// How many blocks/nodes of index needed to index the whole bitset?
- while(n * block_size_in_bits < bottom_blocks_needed)
- {
+ while( n * block_size_in_bits < bottom_blocks_needed ) {
n *= block_size_in_bits;
upper_blocks += n;
}
offset = upper_blocks;
- data.resize(upper_blocks + bottom_blocks_needed, 0);
+ data.resize( upper_blocks + bottom_blocks_needed, 0 );
}
- index get_max_index() const
- {
- if (!data[0])
+ index get_max_index() const {
+ if( !data[ 0 ] )
return -1;
- const size_t size = data.size();
size_t n = 0;
-
- while(true)
- {
- const block_type val = data[n];
- const size_t index = rightmost_pos(val);
- const size_t newn = (n << block_shift) + index + 1;
-
- if (newn >= size)
- {
- const size_t bottom_index = n - offset;
- return (bottom_index << block_shift) + index;
- }
-
+ size_t newn = 0;
+ size_t index = 0;
+ while( newn < data.size() ) {
n = newn;
- }
+ index = rightmost_pos( data[ n ] );
+ newn = ( n << block_shift ) + index + 1;
+ }
- return -1;
+ return ( ( n - offset ) << block_shift ) + index;
}
- bool is_empty() const
- {
- return data[0] == 0;
+ bool is_empty() const {
+ return data[ 0 ] == 0;
}
- void add_index(const size_t entry)
- {
+ void add_index( const size_t entry ) {
const block_type ONE = 1;
- const block_type block_modulo_mask = ((ONE << block_shift) - 1);
+ const block_type block_modulo_mask = ( ONE << block_shift ) - 1;
size_t index_in_level = entry >> block_shift;
size_t address = index_in_level + offset;
size_t index_in_block = entry & block_modulo_mask;
- block_type mask = (ONE << (block_size_in_bits - index_in_block - 1));
-
- while(true)
- {
- data[address]^=mask;
+ block_type mask = ( ONE << ( block_size_in_bits - index_in_block - 1 ) );
- // First we check if we reached the root.
- // Also, if anyone else was in this block, we don't need to update the path up.
- if (!address || (data[address] & ~mask))
- return;
+ data[ address ] ^= mask;
+ // Check if we reached the root. Also, if anyone else was in this block, we don't need to update the path up.
+ while( address && !( data[ address ] & ~mask ) ) {
index_in_block = index_in_level & block_modulo_mask;
index_in_level >>= block_shift;
--address;
address >>= block_shift;
- mask = (ONE << (block_size_in_bits - index_in_block - 1));
+ mask = ( ONE << ( block_size_in_bits - index_in_block - 1 ) );
+ data[ address ] ^= mask;
}
}
- void get_col_and_clear(column &out)
- {
- out.clear();
- while(true)
- {
- index mx = this->get_max_index();
- if (mx == -1)
- break;
- out.push_back(mx);
- add_index(mx);
+ void get_col_and_clear( column &out ) {
+ index mx = this->get_max_index();
+ while( mx != -1 ) {
+ out.push_back( mx );
+ add_index( mx );
+ mx = this->get_max_index();
}
- std::reverse(out.begin(), out.end());
+ std::reverse( out.begin(), out.end() );
}
- void add_col(const column &col)
- {
- for (size_t i = 0; i < col.size(); ++i)
- {
+ void add_col(const column &col) {
+ for( size_t i = 0; i < col.size(); ++i )
add_index(col[i]);
- }
}
void clear() {
- while(true)
- {
- index mx = this->get_max_index();
- if (mx == -1)
- break;
- add_index(mx);
+ index mx = this->get_max_index();
+ while( mx != -1 ) {
+ add_index( mx );
+ mx = this->get_max_index();
}
}
@@ -164,19 +138,18 @@ namespace phat {
add_index( get_max_index() );
}
- void set_col( const column& col ) {
+ void set_col( const column& col ) {
clear();
add_col( col );
}
- void get_col( column& col ) {
- col.clear();
+ void get_col( column& col ) {
get_col_and_clear( col );
add_col( col );
}
};
- const size_t bit_tree_column::debrujin_magic_table[64] = {
+ const size_t bit_tree_column::debrujin_magic_table[ 64 ] = {
63, 0, 58, 1, 59, 47, 53, 2,
60, 39, 48, 27, 54, 33, 42, 3,
61, 51, 37, 40, 49, 18, 28, 20,
diff --git a/include/phat/representations/full_pivot_column.h b/include/phat/representations/full_pivot_column.h
index b83683f..c2e9e3c 100644
--- a/include/phat/representations/full_pivot_column.h
+++ b/include/phat/representations/full_pivot_column.h
@@ -25,14 +25,14 @@ namespace phat {
class full_column {
protected:
- std::priority_queue< index > m_history;
- std::vector< char > m_isInHistory;
- std::vector< char > m_data;
+ std::priority_queue< index > history;
+ std::vector< char > is_in_history;
+ std::vector< char > col_bit_field;
public:
void init( const index total_size ) {
- m_data.resize( total_size, false );
- m_isInHistory.resize( total_size, false );
+ col_bit_field.resize( total_size, false );
+ is_in_history.resize( total_size, false );
}
void add_col( const column& col ) {
@@ -40,23 +40,24 @@ namespace phat {
add_index( col[ idx ] );
}
}
+
void add_index( const index idx ) {
- if( !m_isInHistory[ idx ] ) {
- m_history.push( idx );
- m_isInHistory[ idx ] = true;
+ if( !is_in_history[ idx ] ) {
+ history.push( idx );
+ is_in_history[ idx ] = true;
}
- m_data[ idx ] = !m_data[ idx ];
+ col_bit_field[ idx ] = !col_bit_field[ idx ];
}
index get_max_index() {
- while( m_history.size() > 0 ) {
- index topIndex = m_history.top();
- if( m_data[ topIndex ] ) {
+ while( history.size() > 0 ) {
+ index topIndex = history.top();
+ if( col_bit_field[ topIndex ] ) {
return topIndex;
} else {
- m_history.pop();
- m_isInHistory[ topIndex ] = false;
+ history.pop();
+ is_in_history[ topIndex ] = false;
}
}
@@ -64,7 +65,6 @@ namespace phat {
}
void get_col_and_clear( column& col ) {
- col.clear();
while( !is_empty() ) {
col.push_back( get_max_index() );
add_index( get_max_index() );
@@ -91,7 +91,6 @@ namespace phat {
}
void get_col( column& col ) {
- col.clear();
get_col_and_clear( col );
add_col( col );
}
diff --git a/include/phat/representations/sparse_pivot_column.h b/include/phat/representations/sparse_pivot_column.h
index 9e39950..390fd91 100644
--- a/include/phat/representations/sparse_pivot_column.h
+++ b/include/phat/representations/sparse_pivot_column.h
@@ -25,17 +25,17 @@ namespace phat {
class sparse_column {
protected:
- std::set< index > m_data;
+ std::set< index > data;
void add_index( const index idx ) {
- std::pair< std::set< index >::iterator, bool > result = m_data.insert( idx );
+ std::pair< std::set< index >::iterator, bool > result = data.insert( idx );
if( result.second == false )
- m_data.erase( result.first );
+ data.erase( result.first );
}
public:
void init( const index total_size ) {
- m_data.clear();
+ data.clear();
}
void add_col( const column& col ) {
@@ -44,21 +44,20 @@ namespace phat {
}
index get_max_index() {
- return m_data.empty() ? -1 : *m_data.rbegin();
+ return data.empty() ? -1 : *data.rbegin();
}
void get_col_and_clear( column& col ) {
- col.clear();
- col.assign( m_data.begin(), m_data.end() );
- m_data.clear();
+ col.assign( data.begin(), data.end() );
+ data.clear();
}
bool is_empty() {
- return m_data.empty();
+ return data.empty();
}
void clear() {
- m_data.clear();
+ data.clear();
}
void remove_max() {
@@ -71,7 +70,6 @@ namespace phat {
}
void get_col( column& col ) {
- col.clear();
get_col_and_clear( col );
add_col( col );
}