| 1 | /* |
| 2 | * PartitionWorkSpace.h |
| 3 | * |
| 4 | * Created on: Nov 24, 2010 |
| 5 | * Author: nikai |
| 6 | * Description: a preallocated memory space used in partitioning |
| 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include <vector> |
| 12 | #include <memory> |
| 13 | |
| 14 | namespace gtsam { namespace partition { |
| 15 | |
| 16 | typedef std::vector<int> PartitionTable; |
| 17 | |
| 18 | // the work space, preallocated memory |
| 19 | struct WorkSpace { |
| 20 | std::vector<int> dictionary; // a mapping from the integer key in the original graph to 0-based index in the subgraph, useful when handling a subset of keys and graphs |
| 21 | std::shared_ptr<std::vector<size_t> > dsf; // a block memory pre-allocated for DSFVector |
| 22 | PartitionTable partitionTable; // a mapping from a key to the submap index, 0 means the separator, i means the ith submap |
| 23 | |
| 24 | // constructor |
| 25 | WorkSpace(const size_t numNodes) : dictionary(numNodes,0), |
| 26 | dsf(new std::vector<size_t>(numNodes, 0)), partitionTable(numNodes, -1) { } |
| 27 | |
| 28 | // set up dictionary: -1: no such key, none-zero: the corresponding 0-based index |
| 29 | inline void prepareDictionary(const std::vector<size_t>& keys) { |
| 30 | int index = 0; |
| 31 | std::fill(first: dictionary.begin(), last: dictionary.end(), value: -1); |
| 32 | std::vector<size_t>::const_iterator it=keys.begin(), itLast=keys.end(); |
| 33 | while(it!=itLast) dictionary[*(it++)] = index++; |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | |
| 38 | // manually defined cuts |
| 39 | struct Cuts { |
| 40 | PartitionTable partitionTable; |
| 41 | std::vector<std::shared_ptr<Cuts> > children; |
| 42 | }; |
| 43 | |
| 44 | }} // namespace |
| 45 | |