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