[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
This commit is contained in:
Lang Hames 2014-10-26 18:16:27 +00:00
parent 9e19cf1ffd
commit 015e0c4bd3

View File

@ -25,24 +25,24 @@
namespace llvm {
namespace PBQP {
template <typename CostT>
class CostPool {
template <typename ValueT>
class ValuePool {
public:
typedef std::shared_ptr<CostT> PoolRef;
typedef std::shared_ptr<ValueT> PoolRef;
private:
class PoolEntry : public std::enable_shared_from_this<PoolEntry> {
public:
template <typename CostKeyT>
PoolEntry(CostPool &pool, CostKeyT cost)
: pool(pool), cost(std::move(cost)) {}
~PoolEntry() { pool.removeEntry(this); }
CostT& getCost() { return cost; }
const CostT& getCost() const { return cost; }
template <typename ValueKeyT>
PoolEntry(ValuePool &Pool, ValueKeyT Value)
: Pool(Pool), Value(std::move(Value)) {}
~PoolEntry() { Pool.removeEntry(this); }
ValueT& getValue() { return Value; }
const ValueT& getValue() const { return Value; }
private:
CostPool &pool;
CostT cost;
ValuePool &Pool;
ValueT Value;
};
class PoolEntryDSInfo {
@ -53,64 +53,64 @@ private:
return reinterpret_cast<PoolEntry*>(static_cast<uintptr_t>(1));
}
template <typename CostKeyT>
static unsigned getHashValue(const CostKeyT &C) {
template <typename ValueKeyT>
static unsigned getHashValue(const ValueKeyT &C) {
return hash_value(C);
}
static unsigned getHashValue(PoolEntry *P) {
return getHashValue(P->getCost());
return getHashValue(P->getValue());
}
static unsigned getHashValue(const PoolEntry *P) {
return getHashValue(P->getCost());
return getHashValue(P->getValue());
}
template <typename CostKeyT1, typename CostKeyT2>
template <typename ValueKeyT1, typename ValueKeyT2>
static
bool isEqual(const CostKeyT1 &C1, const CostKeyT2 &C2) {
bool isEqual(const ValueKeyT1 &C1, const ValueKeyT2 &C2) {
return C1 == C2;
}
template <typename CostKeyT>
static bool isEqual(const CostKeyT &C, PoolEntry *P) {
template <typename ValueKeyT>
static bool isEqual(const ValueKeyT &C, PoolEntry *P) {
if (P == getEmptyKey() || P == getTombstoneKey())
return false;
return isEqual(C, P->getCost());
return isEqual(C, P->getValue());
}
static bool isEqual(PoolEntry *P1, PoolEntry *P2) {
if (P1 == getEmptyKey() || P1 == getTombstoneKey())
return P1 == P2;
return isEqual(P1->getCost(), P2);
return isEqual(P1->getValue(), P2);
}
};
typedef DenseSet<PoolEntry*, PoolEntryDSInfo> EntrySet;
typedef DenseSet<PoolEntry*, PoolEntryDSInfo> EntrySetT;
EntrySet entrySet;
EntrySetT EntrySet;
void removeEntry(PoolEntry *p) { entrySet.erase(p); }
void removeEntry(PoolEntry *P) { EntrySet.erase(P); }
public:
template <typename CostKeyT> PoolRef getCost(CostKeyT costKey) {
typename EntrySet::iterator itr = entrySet.find_as(costKey);
template <typename ValueKeyT> PoolRef getValue(ValueKeyT ValueKey) {
typename EntrySetT::iterator I = EntrySet.find_as(ValueKey);
if (itr != entrySet.end())
return PoolRef((*itr)->shared_from_this(), &(*itr)->getCost());
if (I != EntrySet.end())
return PoolRef((*I)->shared_from_this(), &(*I)->getValue());
auto p = std::make_shared<PoolEntry>(*this, std::move(costKey));
entrySet.insert(p.get());
return PoolRef(std::move(p), &p->getCost());
auto P = std::make_shared<PoolEntry>(*this, std::move(ValueKey));
EntrySet.insert(P.get());
return PoolRef(std::move(P), &P->getValue());
}
};
template <typename VectorT, typename MatrixT>
class PoolCostAllocator {
private:
typedef CostPool<VectorT> VectorCostPool;
typedef CostPool<MatrixT> MatrixCostPool;
typedef ValuePool<VectorT> VectorCostPool;
typedef ValuePool<MatrixT> MatrixCostPool;
public:
typedef VectorT Vector;
typedef MatrixT Matrix;
@ -118,13 +118,13 @@ public:
typedef typename MatrixCostPool::PoolRef MatrixPtr;
template <typename VectorKeyT>
VectorPtr getVector(VectorKeyT v) { return vectorPool.getCost(std::move(v)); }
VectorPtr getVector(VectorKeyT v) { return VectorPool.getValue(std::move(v)); }
template <typename MatrixKeyT>
MatrixPtr getMatrix(MatrixKeyT m) { return matrixPool.getCost(std::move(m)); }
MatrixPtr getMatrix(MatrixKeyT m) { return MatrixPool.getValue(std::move(m)); }
private:
VectorCostPool vectorPool;
MatrixCostPool matrixPool;
VectorCostPool VectorPool;
MatrixCostPool MatrixPool;
};
} // namespace PBQP