QNANO
Organize_Blocks.h
1 #ifndef QNANO_NEW_ORGANIZE_BLOCKS_DEFINED_H
2 #define QNANO_NEW_ORGANIZE_BLOCKS_DEFINED_H
3 
4 #include <vector>
5 #include <iostream>
6 #include <cstdlib>
7 #include "tools/Size_Provider.h"
8 
14 public:
15  virtual size_t get_block_size(size_t block) const = 0;
16  virtual size_t get_base_index(size_t block) const = 0;
17  virtual size_t get_nr_blocks() const = 0;
18  virtual size_t get_DIM()const{ return get_base_index(get_nr_blocks()-1)+get_block_size(get_nr_blocks()-1);}
19 
20  //Get sum of blocksizes for a range of 'nr_blocks' blocks starting from 'block_start'
21  size_t get_range_size(size_t block_start, size_t nr_blocks)const;
22 
23 
24 
25  virtual ~Organize_Blocks(){}
26 };
27 
28 class Organize_Blocks_Equal: virtual public Organize_Blocks{
29 protected:
30  size_t blocksize, nrblocks;
31 public:
32  void set_block_size(size_t bs){ blocksize=bs; }
33  void set_nr_blocks(size_t nr){ nrblocks=nr; }
34  virtual size_t get_block_size(size_t block=0)const{ return blocksize;}
35  virtual size_t get_base_index(size_t block) const{ return blocksize*block; }
36  virtual size_t get_nr_blocks()const{ return nrblocks;}
37  virtual size_t get_DIM()const{ return blocksize*nrblocks;}
38 
39  Organize_Blocks_Equal(size_t bs=1, size_t nr=0): blocksize(bs), nrblocks(nr) {}
40 };
41 
43 protected:
44  size_t nrblocks;
45 public:
46  void set_nr_blocks(size_t nr){ nrblocks=nr; }
47  virtual size_t get_block_size(size_t block=0)const{ return 1;}
48  virtual size_t get_base_index(size_t block) const{ return block; }
49  virtual size_t get_nr_blocks()const{ return nrblocks;}
50  virtual size_t get_DIM()const{ return nrblocks;}
51 
52  Organize_Blocks_Single(size_t nr=0): nrblocks(nr) {}
53 };
54 
56 public:
57  Size_Provider *provider;
58 public:
59 
60  virtual size_t get_block_size(size_t block=0)const{ return 1;}
61  virtual size_t get_base_index(size_t block) const{ return block; }
62  virtual size_t get_nr_blocks()const{ return provider->size();}
63  virtual size_t get_DIM()const{ return provider->size();}
64 
65  virtual void set_provider(Size_Provider *prov){
66  provider=prov;
67  }
68  virtual void copy(const Organize_Blocks_Single_Forward &other){
69  provider=other.provider;
70  }
72  copy(other);
73  return *this;
74  }
76  copy(other);
77  }
79  provider=&Size_Provider_Zero_Instance;
80  }
82  provider=prov;
83  }
84 };
85 
87 public:
88  std::vector<size_t> blocksizes;
89  std::vector<size_t> baseindices;
90 
91  virtual size_t get_block_size(size_t block)const;
92  virtual size_t get_base_index(size_t block)const;
93  virtual size_t get_nr_blocks()const;
94  virtual void calculate_base_indices();
95 
96 
98  Organize_Blocks_By_List(const std::vector<size_t> &blocksizes_)
99  : blocksizes(blocksizes_) {
100  calculate_base_indices();
101  }
102 
103 };
104 
105 
106 #endif
Definition: Organize_Blocks.h:42
Definition: Size_Provider.h:11
Definition: Organize_Blocks.h:13
Definition: Organize_Blocks.h:55
Definition: Organize_Blocks.h:86
Definition: Organize_Blocks.h:28