diff options
author | rdivacky <rdivacky@FreeBSD.org> | 2010-03-03 17:27:15 +0000 |
---|---|---|
committer | rdivacky <rdivacky@FreeBSD.org> | 2010-03-03 17:27:15 +0000 |
commit | 8230c40430a1325b5cc5bc0221931487b4bd573c (patch) | |
tree | 836a05cff50ca46176117b86029f061fa4db54f0 /include/llvm/ADT/ScopedHashTable.h | |
parent | f25ddd991a5601d0101602c4c263a58c7af4b8a2 (diff) | |
download | FreeBSD-src-8230c40430a1325b5cc5bc0221931487b4bd573c.zip FreeBSD-src-8230c40430a1325b5cc5bc0221931487b4bd573c.tar.gz |
Update LLVM to 97654.
Diffstat (limited to 'include/llvm/ADT/ScopedHashTable.h')
-rw-r--r-- | include/llvm/ADT/ScopedHashTable.h | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/include/llvm/ADT/ScopedHashTable.h b/include/llvm/ADT/ScopedHashTable.h index d538295..f325e2b 100644 --- a/include/llvm/ADT/ScopedHashTable.h +++ b/include/llvm/ADT/ScopedHashTable.h @@ -36,10 +36,10 @@ namespace llvm { -template <typename K, typename V> +template <typename K, typename V, typename KInfo = DenseMapInfo<K> > class ScopedHashTable; -template <typename K, typename V> +template <typename K, typename V, typename KInfo = DenseMapInfo<K> > class ScopedHashTableVal { ScopedHashTableVal *NextInScope; ScopedHashTableVal *NextForKey; @@ -61,35 +61,39 @@ public: ScopedHashTableVal *getNextInScope() { return NextInScope; } }; -template <typename K, typename V> +template <typename K, typename V, typename KInfo = DenseMapInfo<K> > class ScopedHashTableScope { /// HT - The hashtable that we are active for. - ScopedHashTable<K, V> &HT; + ScopedHashTable<K, V, KInfo> &HT; /// PrevScope - This is the scope that we are shadowing in HT. ScopedHashTableScope *PrevScope; /// LastValInScope - This is the last value that was inserted for this scope /// or null if none have been inserted yet. - ScopedHashTableVal<K,V> *LastValInScope; + ScopedHashTableVal<K, V, KInfo> *LastValInScope; void operator=(ScopedHashTableScope&); // DO NOT IMPLEMENT ScopedHashTableScope(ScopedHashTableScope&); // DO NOT IMPLEMENT public: - ScopedHashTableScope(ScopedHashTable<K, V> &HT); + ScopedHashTableScope(ScopedHashTable<K, V, KInfo> &HT); ~ScopedHashTableScope(); private: - friend class ScopedHashTable<K, V>; - ScopedHashTableVal<K, V> *getLastValInScope() { return LastValInScope; } - void setLastValInScope(ScopedHashTableVal<K,V> *Val) { LastValInScope = Val; } + friend class ScopedHashTable<K, V, KInfo>; + ScopedHashTableVal<K, V, KInfo> *getLastValInScope() { + return LastValInScope; + } + void setLastValInScope(ScopedHashTableVal<K, V, KInfo> *Val) { + LastValInScope = Val; + } }; -template <typename K, typename V> +template <typename K, typename V, typename KInfo = DenseMapInfo<K> > class ScopedHashTableIterator { - ScopedHashTableVal<K,V> *Node; + ScopedHashTableVal<K, V, KInfo> *Node; public: - ScopedHashTableIterator(ScopedHashTableVal<K,V> *node) : Node(node){} + ScopedHashTableIterator(ScopedHashTableVal<K, V, KInfo> *node) : Node(node) {} V &operator*() const { assert(Node && "Dereference end()"); @@ -117,35 +121,43 @@ public: }; -template <typename K, typename V> +template <typename K, typename V, typename KInfo> class ScopedHashTable { - DenseMap<K, ScopedHashTableVal<K,V>*> TopLevelMap; - ScopedHashTableScope<K, V> *CurScope; + DenseMap<K, ScopedHashTableVal<K, V, KInfo>*, KInfo> TopLevelMap; + ScopedHashTableScope<K, V, KInfo> *CurScope; ScopedHashTable(const ScopedHashTable&); // NOT YET IMPLEMENTED void operator=(const ScopedHashTable&); // NOT YET IMPLEMENTED - friend class ScopedHashTableScope<K, V>; + friend class ScopedHashTableScope<K, V, KInfo>; public: ScopedHashTable() : CurScope(0) {} ~ScopedHashTable() { assert(CurScope == 0 && TopLevelMap.empty() && "Scope imbalance!"); } + bool count(const K &Key) const { + return TopLevelMap.count(Key); + } + + V lookup(const K &Key) { + return TopLevelMap[Key].getValue(); + } + void insert(const K &Key, const V &Val) { assert(CurScope && "No scope active!"); - ScopedHashTableVal<K,V> *&KeyEntry = TopLevelMap[Key]; + ScopedHashTableVal<K, V, KInfo> *&KeyEntry = TopLevelMap[Key]; - KeyEntry = new ScopedHashTableVal<K,V>(CurScope->getLastValInScope(), - KeyEntry, Key, Val); + KeyEntry= new ScopedHashTableVal<K, V, KInfo>(CurScope->getLastValInScope(), + KeyEntry, Key, Val); CurScope->setLastValInScope(KeyEntry); } - typedef ScopedHashTableIterator<K, V> iterator; + typedef ScopedHashTableIterator<K, V, KInfo> iterator; iterator end() { return iterator(0); } iterator begin(const K &Key) { - typename DenseMap<K, ScopedHashTableVal<K,V>*>::iterator I = + typename DenseMap<K, ScopedHashTableVal<K, V, KInfo>*, KInfo>::iterator I = TopLevelMap.find(Key); if (I == TopLevelMap.end()) return end(); return iterator(I->second); @@ -154,28 +166,29 @@ public: /// ScopedHashTableScope ctor - Install this as the current scope for the hash /// table. -template <typename K, typename V> -ScopedHashTableScope<K, V>::ScopedHashTableScope(ScopedHashTable<K, V> &ht) - : HT(ht) { +template <typename K, typename V, typename KInfo> +ScopedHashTableScope<K, V, KInfo>:: + ScopedHashTableScope(ScopedHashTable<K, V, KInfo> &ht) : HT(ht) { PrevScope = HT.CurScope; HT.CurScope = this; LastValInScope = 0; } -template <typename K, typename V> -ScopedHashTableScope<K, V>::~ScopedHashTableScope() { +template <typename K, typename V, typename KInfo> +ScopedHashTableScope<K, V, KInfo>::~ScopedHashTableScope() { assert(HT.CurScope == this && "Scope imbalance!"); HT.CurScope = PrevScope; // Pop and delete all values corresponding to this scope. - while (ScopedHashTableVal<K, V> *ThisEntry = LastValInScope) { + while (ScopedHashTableVal<K, V, KInfo> *ThisEntry = LastValInScope) { // Pop this value out of the TopLevelMap. if (ThisEntry->getNextForKey() == 0) { assert(HT.TopLevelMap[ThisEntry->getKey()] == ThisEntry && "Scope imbalance!"); HT.TopLevelMap.erase(ThisEntry->getKey()); } else { - ScopedHashTableVal<K,V> *&KeyEntry = HT.TopLevelMap[ThisEntry->getKey()]; + ScopedHashTableVal<K, V, KInfo> *&KeyEntry = + HT.TopLevelMap[ThisEntry->getKey()]; assert(KeyEntry == ThisEntry && "Scope imbalance!"); KeyEntry = ThisEntry->getNextForKey(); } |