| 16 | |
| 17 | |
| 18 | struct idxmap { |
| 19 | Table table; // grid_idx -> set of point_idx |
| 20 | // ray_idx -> set of grid_idx |
| 21 | |
| 22 | idxmap() {} |
| 23 | |
| 24 | // reserve n capacity in the table |
| 25 | idxmap(size_t n) { |
| 26 | table.reserve(n); |
| 27 | } |
| 28 | |
| 29 | // initialize with table |
| 30 | idxmap(const Table& t) { |
| 31 | table = t; |
| 32 | } |
| 33 | |
| 34 | // associate pidx with gidx |
| 35 | void insert(int64_t gidx, int64_t pidx) { |
| 36 | auto iter = table.find(gidx); |
| 37 | if (iter == table.end()) { |
| 38 | table[gidx] = std::unordered_set<int64_t>({pidx}); |
| 39 | } |
| 40 | else { |
| 41 | table[gidx].insert(pidx); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // get the pointer to the point index set |
| 46 | std::unordered_set<int64_t> * get_pidx(int64_t gidx) { |
| 47 | auto iter = table.find(gidx); |
| 48 | if (iter == table.end()) { |
| 49 | return nullptr; |
| 50 | } |
| 51 | else { |
| 52 | return &(table[gidx]); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | // get the underlying table |
| 57 | Table get_table() { |
| 58 | return table; |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | |
| 63 | |