mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-14 17:34:41 +00:00
add a version of insert that takes the key and value.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33856 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6734b57d1b
commit
28f72279f5
@ -111,6 +111,16 @@ public:
|
|||||||
return end();
|
return end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool insert(const std::pair<KeyT, ValueT> &KV) {
|
||||||
|
BucketT *TheBucket;
|
||||||
|
if (LookupBucketFor(KV.first, TheBucket))
|
||||||
|
return false; // Already in map.
|
||||||
|
|
||||||
|
// Otherwise, insert the new element.
|
||||||
|
InsertIntoBucket(KV.first, KV.second, TheBucket);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool erase(const KeyT &Val) {
|
bool erase(const KeyT &Val) {
|
||||||
BucketT *TheBucket;
|
BucketT *TheBucket;
|
||||||
if (!LookupBucketFor(Val, TheBucket))
|
if (!LookupBucketFor(Val, TheBucket))
|
||||||
@ -129,23 +139,28 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueT &operator[](const KeyT &Val) {
|
ValueT &operator[](const KeyT &Key) {
|
||||||
BucketT *TheBucket;
|
BucketT *TheBucket;
|
||||||
if (LookupBucketFor(Val, TheBucket))
|
if (LookupBucketFor(Key, TheBucket))
|
||||||
return TheBucket->second;
|
return TheBucket->second;
|
||||||
|
|
||||||
// If the load of the hash table is more than 3/4, grow it.
|
return InsertIntoBucket(Key, ValueT(), TheBucket)->second;
|
||||||
if (NumEntries*4 >= NumBuckets*3) {
|
|
||||||
this->grow();
|
|
||||||
LookupBucketFor(Val, TheBucket);
|
|
||||||
}
|
|
||||||
++NumEntries;
|
|
||||||
TheBucket->first = Val;
|
|
||||||
new (&TheBucket->second) ValueT();
|
|
||||||
return TheBucket->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BucketT *InsertIntoBucket(const KeyT &Key, const ValueT &Value,
|
||||||
|
BucketT *TheBucket) {
|
||||||
|
// If the load of the hash table is more than 3/4, grow it.
|
||||||
|
if (NumEntries*4 >= NumBuckets*3) {
|
||||||
|
this->grow();
|
||||||
|
LookupBucketFor(Key, TheBucket);
|
||||||
|
}
|
||||||
|
++NumEntries;
|
||||||
|
TheBucket->first = Key;
|
||||||
|
new (&TheBucket->second) ValueT(Value);
|
||||||
|
return TheBucket;
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned getHashValue(const KeyT &Val) {
|
static unsigned getHashValue(const KeyT &Val) {
|
||||||
return DenseMapKeyInfo<KeyT>::getHashValue(Val);
|
return DenseMapKeyInfo<KeyT>::getHashValue(Val);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user