SparseLibrary  Version 1.6.0
U2.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_U2
35 #define _H_U2
36 
37 #include "BlockOrderer.hpp"
38 
40 template< typename T >
41 class U2: public BlockOrderer< T > {
42  protected:
43 
45  virtual void pre_readout ( const unsigned long int index ) {
46  //switch between internal nodes and external nodes
47  if( this->tree->isLeaf( index ) ) {
48  //immediately add everything in range
49  this->output->push_back( this->items[ index ] );
50  if( this->datatype != NULL )
51  this->datatype->push_back( NORMAL_DS );
52  }
53  }
54 
56  virtual void in_readout ( const unsigned long int index ) {
57  //skip leaf node
58  if( this->tree->isLeaf( index ) ) return;
59  //initialise
60  typename std::vector< Triplet< T > >::iterator it = this->items[ index ].begin();
61  std::vector< Triplet< T > > cur1;
62  std::vector< Triplet< T > > cur2;
63  std::vector< Triplet< T > > cur3;
64  std::vector< Triplet< T > > cur4;
65  std::vector< Triplet< T > > rep;
66  //loop over this node's triplets
67  for( ; it != this->items[ index ].end(); ++it ) {
68  //now the 3 vertical separators (incl middle) in row order
69  if( this->left_horizontal( index, *it ) )
70  cur1.push_back( *it );
71  else if( this->middle( index, *it ) )
72  cur2.push_back( *it );
73  else if( this->upper_vertical( index, *it ) )
74  cur3.push_back( *it );
75  else if( this->lower_vertical( index, *it ) )
76  cur4.push_back( *it );
77  else
78  rep.push_back( *it );
79  }
80  if( cur1.size() + cur2.size() + cur3.size() + cur4.size() > 0 )
81  this->items[ index ] = rep; //replace with smaller vector
82  this->output->push_back( cur1 );
83  this->output->push_back( cur2 );
84  this->output->push_back( cur3 );
85  this->output->push_back( cur4 );
86  if( this->datatype != NULL ) {
87  this->datatype->push_back( HORIZONTAL_DS );
88  this->datatype->push_back( NORMAL_DS );
89  this->datatype->push_back( VERTICAL_DS );
90  this->datatype->push_back( VERTICAL_DS );
91  }
92  }
93 
95  virtual void post_readout( const unsigned long int index ) {
96  //skip leaf node
97  if( this->tree->isLeaf( index ) ) return;
98  //initialise
99  typename std::vector< Triplet< T > >::iterator it = this->items[ index ].begin();
100  std::vector< Triplet< T > > cur;
101  std::vector< Triplet< T > > rep;
102  //loop over this node's triplets
103  for( ; it != this->items[ index ].end(); ++it ) {
104  //right horizontal separator last
105  if( this->right_horizontal( index, *it ) )
106  cur.push_back( *it );
107  else
108  rep.push_back( *it );
109  }
110  if( cur.size() > 0 )
111  this->items[ index ] = rep; //replace with smaller vector
112  assert( rep.size() == 0 );
113  this->output->push_back( cur );
114  if( this->datatype != NULL )
115  this->datatype->push_back( HORIZONTAL_DS );
116  }
117 
118  public:
119  //(de)constructor of superclass gets called automagically
120 };
121 
122 #endif
123 
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 post_readout(const unsigned long int index)
Postfix operations during SBD tree traversal.
Definition: U2.hpp:95
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
Codes the Minimal CCS block order.
Definition: U2.hpp:41
virtual void pre_readout(const unsigned long int index)
Prefix operations during SBD tree traversal.
Definition: U2.hpp:45
virtual void in_readout(const unsigned long int index)
Infix operations during SBD tree traversal.
Definition: U2.hpp:56
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
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