LoAdSG
multiDepthHashGrid.h
1#ifndef MULTIDEPTHHASHGRID_H
2#define MULTIDEPTHHASHGRID_H
3
4#include "depth.h"
5#include "../primes/prime.h"
6
7#include <vector>
8#include <unordered_map>
9#include "simpleMultiHash.h"
10#include <algorithm>
11
12
14class MultiDepthHashGrid;
15class MultiLevelVector;
16
17
18class SingleDepthHashGrid{
19
20#ifndef BENCHMARKING
21 private:
22#else
23public:
24#endif
25 friend MultiDepthHashGrid;
26 friend MultiLevelVector;
27 // std::unordered_multimap<unsigned long,unsigned long> _map;// = std::unordered_multimap<unsigned,unsigned>(100); // maps hash -> position in sparseGrid second table
29 const Depth _depth;
30 // std::unordered_multimap<size_t,size_t>::const_iterator _occupied(unsigned long &indexOfData, const IndexDimension &I);
31 public:
33
34 vector<unsigned long> _mapPosToGridPos;
35
36 SingleDepthHashGrid(Depth depth, AdaptiveSparseGrid_Base &grid);//:_grid(grid),_depth(depth){}
37
38
39
40 bool addPoint(const IndexDimension &key, unsigned long pos);
41
42 // bool addPoint(const unsigned long hash, unsigned long pos);
43
44 bool occupied(unsigned long &indexOfData, const IndexDimension &I) const;
45
46 bool occupied(unsigned long &indexOfData, const IndexDimension &I, Depth& T) const;
47
48 Depth getDepth() const {return _depth;}
49
50 bool isDepth(const Depth & depth) const {return _depth == depth;}
51
52 size_t getNumberOfEntries() const { return _map.size();}
53
54 friend std::ostream& operator<< (std::ostream& stream, const SingleDepthHashGrid& grid){
55 stream << "SingleDepthHashGrid: Depth(";
56 for (size_t i = 0; i < DimensionSparseGrid-1; i++)
57 {
58 stream << grid._depth.at(i) << ", ";
59 }
60 stream << grid._depth.at(DimensionSparseGrid-1) << ") with " << grid.getNumberOfEntries() << " entries";
61 return stream;
62 }
63};
64
65
66class MultiDepthHashGrid{
67#ifndef BENCHMARKING
68 private:
69#else
70public:
71#endif
72 std::unordered_multimap<unsigned long,SingleDepthHashGrid> _map;// = std::unordered_multimap<unsigned,unsigned>(100); // maps hash -> position in sparseGrid second table
74 // std::unordered_multimap<size_t,size_t>::const_iterator _occupied(unsigned long &indexOfData, const IndexDimension &I);
86 public:
87 bool addPoint(const IndexDimension &key, unsigned long pos);
88 bool addPoint(const IndexDimension &key, unsigned long pos, Depth D);
96 std::vector<unsigned long> reorder(bool collision = false);
97 MultiDepthHashGrid(AdaptiveSparseGrid_Base &grid): _grid(grid){}
104 SingleDepthHashGrid& getGridForDepth(const Depth &D);
111 SingleDepthHashGrid* tryGetGridForDepth(const Depth &D);
119 vector<SingleDepthHashGrid*> getGridsForDepthInDirection(const Depth &D, int d);
126 SingleDepthHashGrid& getGridForDepth(const IndexDimension &I);
127 // bool addPoint( unsigned long hash, unsigned long pos);
128 // bool occupied(unsigned long &indexOfData, const IndexDimension &I) const;
129 unsigned long hash(Depth D);
130
131 vector<SingleDepthHashGrid*> getAllGrids();
132 // unsigned long hash(Depth D){
133 // unsigned long value = D.at(0);
134 // for (int d = 1; d < DimensionSparseGrid; ++d) {
135 // value = value + D.at(d) * PrimeNumbers::getPrimeForHash(d);
136 // }
137 // return value;
138 // }
139 void printSizes(){
140 for (auto it = _map.begin(); it != _map.end(); ++it) {
141 SingleDepthHashGrid& res = it->second;
142 // res.getDepth().Print();
143 // cout << "with " << res.getNumberOfEntries() << " entries."<<endl;
144 cout << res << endl;
145 }
146 }
147};
148/*
149bool MultiDepthHashGrid::addPoint(const IndexDimension &key, unsigned long pos){
150 Depth D(key);
151 SingleDepthHashGrid& sgrid = getGridForDepth(D);
152 return sgrid.addPoint(key,pos);;
153}
154
155SingleDepthHashGrid& MultiDepthHashGrid::getGridForDepth(const Depth &D){
156 unsigned long hashVal = hash(D);
157
158 auto its = _map.equal_range(hashVal);
159
160 for (auto it = its.first; it != its.second; ++it) {
161 if(it->second.isDepth(D)){
162 return it->second;
163 }
164 }
165 // SingleDepthHashGrid* grid = new SingleDepthHashGrid(D,this->_grid);
166
167 SingleDepthHashGrid grid(D,this->_grid);
168 auto iter = _map.insert({hashVal,grid});
169
170 return iter->second;
171}
172*/
173#endif // MULTIDEPTHHASHGRID_H
Definition sparseGrid.h:86
A simple multihash implementation. Is able to store multiple elements with the same hash.
Definition simpleMultiHash.h:154