llvm.org GIT mirror llvm / 015e0c4
[PBQP] Tidy up CostAllocator.h: fix variable case, rename CostPool to ValuePool. No functional change. This just brings things more in-line with coding standards, and makes ValuePool's functionality clearer (it's not tied to pooling costs, and we may want to use it to hold other things in the future). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220641 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 5 years ago
1 changed file(s) with 37 addition(s) and 37 deletion(s). Raw diff Collapse all Expand all
2424 namespace llvm {
2525 namespace PBQP {
2626
27 template
28 class CostPool {
27 template
28 class ValuePool {
2929 public:
30 typedef std::shared_ptr<CostT> PoolRef;
30 typedef std::shared_ptr<ValueT> PoolRef;
3131
3232 private:
3333
3434 class PoolEntry : public std::enable_shared_from_this {
3535 public:
36 template
37 PoolEntry(CostPool &pool, CostKeyT cost)
38 : pool(pool), cost(std::move(cost)) {}
39 ~PoolEntry() { pool.removeEntry(this); }
40 CostT& getCost() { return cost; }
41 const CostT& getCost() const { return cost; }
36 template
37 PoolEntry(ValuePool &Pool, ValueKeyT Value)
38 : Pool(Pool), Value(std::move(Value)) {}
39 ~PoolEntry() { Pool.removeEntry(this); }
40 ValueT& getValue() { return Value; }
41 const ValueT& getValue() const { return Value; }
4242 private:
43 CostPool &pool;
44 CostT cost;
43 ValuePool &Pool;
44 ValueT Value;
4545 };
4646
4747 class PoolEntryDSInfo {
5252 return reinterpret_cast(static_cast(1));
5353 }
5454
55 template
56 static unsigned getHashValue(const CostKeyT &C) {
55 template
56 static unsigned getHashValue(const ValueKeyT &C) {
5757 return hash_value(C);
5858 }
5959
6060 static unsigned getHashValue(PoolEntry *P) {
61 return getHashValue(P->getCost());
61 return getHashValue(P->getValue());
6262 }
6363
6464 static unsigned getHashValue(const PoolEntry *P) {
65 return getHashValue(P->getCost());
65 return getHashValue(P->getValue());
6666 }
6767
68 template CostKeyT1, typename CostKeyT2>
68 template ValueKeyT1, typename ValueKeyT2>
6969 static
70 bool isEqual(const CostKeyT1 &C1, const CostKeyT2 &C2) {
70 bool isEqual(const ValueKeyT1 &C1, const ValueKeyT2 &C2) {
7171 return C1 == C2;
7272 }
7373
74 template
75 static bool isEqual(const CostKeyT &C, PoolEntry *P) {
74 template
75 static bool isEqual(const ValueKeyT &C, PoolEntry *P) {
7676 if (P == getEmptyKey() || P == getTombstoneKey())
7777 return false;
78 return isEqual(C, P->getCost());
78 return isEqual(C, P->getValue());
7979 }
8080
8181 static bool isEqual(PoolEntry *P1, PoolEntry *P2) {
8282 if (P1 == getEmptyKey() || P1 == getTombstoneKey())
8383 return P1 == P2;
84 return isEqual(P1->getCost(), P2);
84 return isEqual(P1->getValue(), P2);
8585 }
8686
8787 };
8888
89 typedef DenseSet EntrySet;
89 typedef DenseSet EntrySetT;
9090
91 EntrySet entrySet;
91 EntrySetT EntrySet;
9292
93 void removeEntry(PoolEntry *p) { entrySet.erase(p); }
93 void removeEntry(PoolEntry *P) { EntrySet.erase(P); }
9494
9595 public:
96 template PoolRef getCost(CostKeyT costKey) {
97 typename EntrySet::iterator itr = entrySet.find_as(costKey);
96 template PoolRef getValue(ValueKeyT ValueKey) {
97 typename EntrySetT::iterator I = EntrySet.find_as(ValueKey);
9898
99 if (itr != entrySet.end())
100 return PoolRef((*itr)->shared_from_this(), &(*itr)->getCost());
99 if (I != EntrySet.end())
100 return PoolRef((*I)->shared_from_this(), &(*I)->getValue());
101101
102 auto p = std::make_shared(*this, std::move(costKey));
103 entrySet.insert(p.get());
104 return PoolRef(std::move(p), &p->getCost());
102 auto P = std::make_shared(*this, std::move(ValueKey));
103 EntrySet.insert(P.get());
104 return PoolRef(std::move(P), &P->getValue());
105105 }
106106 };
107107
108108 template
109109 class PoolCostAllocator {
110110 private:
111 typedef CostPool VectorCostPool;
112 typedef CostPool MatrixCostPool;
111 typedef ValuePool VectorCostPool;
112 typedef ValuePool MatrixCostPool;
113113 public:
114114 typedef VectorT Vector;
115115 typedef MatrixT Matrix;
117117 typedef typename MatrixCostPool::PoolRef MatrixPtr;
118118
119119 template
120 VectorPtr getVector(VectorKeyT v) { return vectorPool.getCost(std::move(v)); }
120 VectorPtr getVector(VectorKeyT v) { return VectorPool.getValue(std::move(v)); }
121121
122122 template
123 MatrixPtr getMatrix(MatrixKeyT m) { return matrixPool.getCost(std::move(m)); }
123 MatrixPtr getMatrix(MatrixKeyT m) { return MatrixPool.getValue(std::move(m)); }
124124 private:
125 VectorCostPool vectorPool;
126 MatrixCostPool matrixPool;
125 VectorCostPool VectorPool;
126 MatrixCostPool MatrixPool;
127127 };
128128
129129 } // namespace PBQP