SparseLibrary  Version 1.6.0
SepLast.hpp
1 /*
2  * Copyright (c) 2007-2014, A. N. Yzelman, Utrecht University 2007-2011;
3  * KU Leuven 2011-2014.
4  * R. H. Bisseling, Utrecht University 2007-2014.
5  *
6  * This file is part of the Sparse Library.
7  *
8  * This library was developed under supervision of Prof. dr. Rob H. Bisseling at
9  * Utrecht University, from 2007 until 2011. From 2011-2014, development continued
10  * at KU Leuven, where Prof. dr. Dirk Roose contributed significantly to the ideas
11  * behind the newer parts of the library code.
12  *
13  * The Sparse Library is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by the
15  * Free Software Foundation, either version 3 of the License, or (at your
16  * option) any later version.
17  *
18  * The Sparse Library is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with the Sparse Library. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 
28 /*
29  * File created by:
30  * A. N. Yzelman, Dept. of Mathematics, Utrecht University, 2010.
31  */
32 
33 
34 #ifndef _H_SEPLAST
35 #define _H_SEPLAST
36 
37 #include "BlockOrderer.hpp"
38 
40 template< typename T >
41 class SepLast: public BlockOrderer< T > {
42  protected:
43  virtual void pre_readout ( const unsigned long int index ) {
44  //switch between internal nodes and external nodes
45  if( this->tree->isLeaf( index ) ) {
46  //immediately add everything in range
47  this->output->push_back( this->items[ index ] );
48  if( this->datatype != NULL )
49  this->datatype->push_back( NORMAL_DS );
50  }
51  }
52 
53  virtual void in_readout ( const unsigned long int index ) {
54  //do nothing
55  }
56 
57  virtual void post_readout( const unsigned long int index ) {
58  //skip leaf node
59  if( this->tree->isLeaf( index ) ) return;
60 
61  //initialise
62  typename std::vector< Triplet< T > >::iterator it = this->items[ index ].begin();
63  std::vector< Triplet< T > > cur1;
64  std::vector< Triplet< T > > cur2;
65  std::vector< Triplet< T > > cur3;
66  std::vector< Triplet< T > > cur4;
67  std::vector< Triplet< T > > cur5;
68  std::vector< Triplet< T > > rep;
69  //loop over this node's triplets
70  for( ; it != this->items[ index ].end(); ++it ) {
71  //now the 3 vertical separators (incl middle) in row order
72  if( this->right_horizontal( index, *it ) )
73  cur1.push_back( *it );
74  else if( this->middle( index, *it ) )
75  cur2.push_back( *it );
76  else if( this->upper_vertical( index, *it ) )
77  cur3.push_back( *it );
78  else if( this->lower_vertical( index, *it ) )
79  cur4.push_back( *it );
80  else if( this->left_horizontal( index, *it ) )
81  cur5.push_back( *it );
82  else
83  rep.push_back( *it );
84  }
85  if( cur1.size() + cur2.size() + cur3.size() + cur4.size() + cur5.size() > 0 )
86  this->items[ index ] = rep; //replace with smaller vector
87  this->output->push_back( cur1 );
88  this->output->push_back( cur2 );
89  this->output->push_back( cur3 );
90  this->output->push_back( cur4 );
91  this->output->push_back( cur5 );
92  if( this->datatype != NULL ) {
93  this->datatype->push_back( HORIZONTAL_DS );
94  this->datatype->push_back( NORMAL_DS );
95  this->datatype->push_back( VERTICAL_DS );
96  this->datatype->push_back( VERTICAL_DS );
97  this->datatype->push_back( HORIZONTAL_DS );
98  }
99 
100 
101  }
102 
103  public:
104  //(de)constructor of superclass gets called automagically
105 };
106 
107 #endif
108 
Induces a block order by fully traversing an SBDTree.
Definition: BlockOrderer.hpp:48
SBDTree * tree
The SBD tree to order the blocks of.
Definition: BlockOrderer.hpp:53
virtual void pre_readout(const unsigned long int index)
Prefix traversal code.
Definition: SepLast.hpp:43
char isLeaf(const unsigned long int index)
Whether the given node is a leaf node.
Definition: SBDTree.cpp:214
bool left_horizontal(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:203
bool upper_vertical(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:221
virtual void in_readout(const unsigned long int index)
Infix traversal code.
Definition: SepLast.hpp:53
virtual void post_readout(const unsigned long int index)
Postfix traversal code.
Definition: SepLast.hpp:57
bool right_horizontal(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:212
Codes the Minimal CCS block order.
Definition: SepLast.hpp:41
bool lower_vertical(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:230
std::vector< std::vector< Triplet< T > > > * output
Output structure after SBD readout (series of blocks in the correct order).
Definition: BlockOrderer.hpp:197
bool middle(const unsigned long int index, const Triplet< T > triplet)
Helper function for determining place of a nonzero within a separator cross.
Definition: BlockOrderer.hpp:239
std::vector< signed char > * datatype
The data type of each block.
Definition: BlockOrderer.hpp:200
std::vector< Triplet< T > > * items
Nonzero storage at each node.
Definition: BlockOrderer.hpp:194