2007-02-01 07:49:59 +00:00
|
|
|
//===- llvm/ADT/DenseMap.h - Dense probed hash table ------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-02-01 07:49:59 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the DenseMap class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_ADT_DENSEMAP_H
|
|
|
|
#define LLVM_ADT_DENSEMAP_H
|
|
|
|
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/ADT/DenseMapInfo.h"
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
#include "llvm/Support/AlignOf.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2007-07-20 18:56:46 +00:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2009-11-10 01:02:17 +00:00
|
|
|
#include "llvm/Support/PointerLikeTypeTraits.h"
|
|
|
|
#include "llvm/Support/type_traits.h"
|
2010-12-19 20:43:38 +00:00
|
|
|
#include <algorithm>
|
2007-02-01 07:49:59 +00:00
|
|
|
#include <cassert>
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
#include <climits>
|
2010-06-10 10:13:58 +00:00
|
|
|
#include <cstddef>
|
2009-07-21 18:01:37 +00:00
|
|
|
#include <cstring>
|
2012-12-03 17:02:12 +00:00
|
|
|
#include <iterator>
|
|
|
|
#include <new>
|
|
|
|
#include <utility>
|
2007-02-01 07:49:59 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2009-01-09 19:25:42 +00:00
|
|
|
|
|
|
|
template<typename KeyT, typename ValueT,
|
2007-09-17 18:34:04 +00:00
|
|
|
typename KeyInfoT = DenseMapInfo<KeyT>,
|
2012-04-06 10:43:44 +00:00
|
|
|
bool IsConst = false>
|
2007-02-02 19:27:13 +00:00
|
|
|
class DenseMapIterator;
|
2007-02-01 07:49:59 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
template<typename DerivedT,
|
|
|
|
typename KeyT, typename ValueT, typename KeyInfoT>
|
|
|
|
class DenseMapBase {
|
|
|
|
protected:
|
2007-02-02 19:27:13 +00:00
|
|
|
typedef std::pair<KeyT, ValueT> BucketT;
|
2012-06-16 01:05:01 +00:00
|
|
|
|
2007-02-01 07:49:59 +00:00
|
|
|
public:
|
2014-06-20 10:26:56 +00:00
|
|
|
typedef size_t size_type;
|
2008-10-27 18:15:15 +00:00
|
|
|
typedef KeyT key_type;
|
|
|
|
typedef ValueT mapped_type;
|
2007-11-01 00:54:57 +00:00
|
|
|
typedef BucketT value_type;
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-02-10 06:34:58 +00:00
|
|
|
typedef DenseMapIterator<KeyT, ValueT, KeyInfoT> iterator;
|
2009-11-10 01:02:17 +00:00
|
|
|
typedef DenseMapIterator<KeyT, ValueT,
|
2012-04-06 10:43:44 +00:00
|
|
|
KeyInfoT, true> const_iterator;
|
2007-02-02 20:34:32 +00:00
|
|
|
inline iterator begin() {
|
2010-05-17 20:01:24 +00:00
|
|
|
// When the map is empty, avoid the overhead of AdvancePastEmptyBuckets().
|
2012-06-16 01:05:01 +00:00
|
|
|
return empty() ? end() : iterator(getBuckets(), getBucketsEnd());
|
2007-02-02 20:34:32 +00:00
|
|
|
}
|
|
|
|
inline iterator end() {
|
2012-06-16 01:05:01 +00:00
|
|
|
return iterator(getBucketsEnd(), getBucketsEnd(), true);
|
2007-02-02 20:34:32 +00:00
|
|
|
}
|
|
|
|
inline const_iterator begin() const {
|
2012-06-16 01:05:01 +00:00
|
|
|
return empty() ? end() : const_iterator(getBuckets(), getBucketsEnd());
|
2007-02-02 20:34:32 +00:00
|
|
|
}
|
|
|
|
inline const_iterator end() const {
|
2012-06-16 01:05:01 +00:00
|
|
|
return const_iterator(getBucketsEnd(), getBucketsEnd(), true);
|
2007-02-02 20:34:32 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2013-09-13 17:33:24 +00:00
|
|
|
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const {
|
|
|
|
return getNumEntries() == 0;
|
|
|
|
}
|
2012-06-16 01:18:07 +00:00
|
|
|
unsigned size() const { return getNumEntries(); }
|
2007-09-24 19:45:49 +00:00
|
|
|
|
|
|
|
/// Grow the densemap so that it has at least Size buckets. Does not shrink
|
2014-06-20 10:26:56 +00:00
|
|
|
void resize(size_type Size) {
|
2012-06-16 01:05:01 +00:00
|
|
|
if (Size > getNumBuckets())
|
2011-03-05 16:43:41 +00:00
|
|
|
grow(Size);
|
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-02-01 07:49:59 +00:00
|
|
|
void clear() {
|
2012-06-16 01:18:07 +00:00
|
|
|
if (getNumEntries() == 0 && getNumTombstones() == 0) return;
|
2013-01-05 05:16:53 +00:00
|
|
|
|
2007-08-05 07:32:14 +00:00
|
|
|
// If the capacity of the array is huge, and the # elements used is small,
|
|
|
|
// shrink the array.
|
2012-06-16 01:18:07 +00:00
|
|
|
if (getNumEntries() * 4 < getNumBuckets() && getNumBuckets() > 64) {
|
2007-07-20 16:15:24 +00:00
|
|
|
shrink_and_clear();
|
|
|
|
return;
|
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-02-01 07:49:59 +00:00
|
|
|
const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
|
2012-06-16 01:05:01 +00:00
|
|
|
for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P) {
|
2007-10-09 05:42:12 +00:00
|
|
|
if (!KeyInfoT::isEqual(P->first, EmptyKey)) {
|
|
|
|
if (!KeyInfoT::isEqual(P->first, TombstoneKey)) {
|
2007-08-05 08:43:36 +00:00
|
|
|
P->second.~ValueT();
|
2012-06-16 01:18:07 +00:00
|
|
|
decrementNumEntries();
|
2007-08-05 08:43:36 +00:00
|
|
|
}
|
2007-02-02 19:27:13 +00:00
|
|
|
P->first = EmptyKey;
|
2007-02-01 07:49:59 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-16 01:18:07 +00:00
|
|
|
assert(getNumEntries() == 0 && "Node count imbalance!");
|
|
|
|
setNumTombstones(0);
|
2007-02-01 07:49:59 +00:00
|
|
|
}
|
2007-07-20 16:15:24 +00:00
|
|
|
|
2014-06-20 10:26:56 +00:00
|
|
|
/// Return 1 if the specified key is in the map, 0 otherwise.
|
|
|
|
size_type count(const KeyT &Val) const {
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
const BucketT *TheBucket;
|
2014-06-20 10:26:56 +00:00
|
|
|
return LookupBucketFor(Val, TheBucket) ? 1 : 0;
|
2007-02-01 07:49:59 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-02-10 06:58:17 +00:00
|
|
|
iterator find(const KeyT &Val) {
|
2007-02-02 20:34:32 +00:00
|
|
|
BucketT *TheBucket;
|
|
|
|
if (LookupBucketFor(Val, TheBucket))
|
2012-06-16 01:05:01 +00:00
|
|
|
return iterator(TheBucket, getBucketsEnd(), true);
|
2007-02-02 20:34:32 +00:00
|
|
|
return end();
|
|
|
|
}
|
2007-02-10 06:58:17 +00:00
|
|
|
const_iterator find(const KeyT &Val) const {
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
const BucketT *TheBucket;
|
2007-02-10 06:58:17 +00:00
|
|
|
if (LookupBucketFor(Val, TheBucket))
|
2012-06-16 01:05:01 +00:00
|
|
|
return const_iterator(TheBucket, getBucketsEnd(), true);
|
2007-02-10 06:58:17 +00:00
|
|
|
return end();
|
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2012-01-30 06:55:43 +00:00
|
|
|
/// Alternate version of find() which allows a different, and possibly
|
|
|
|
/// less expensive, key type.
|
|
|
|
/// The DenseMapInfo is responsible for supplying methods
|
|
|
|
/// getHashValue(LookupKeyT) and isEqual(LookupKeyT, KeyT) for each key
|
|
|
|
/// type used.
|
|
|
|
template<class LookupKeyT>
|
|
|
|
iterator find_as(const LookupKeyT &Val) {
|
|
|
|
BucketT *TheBucket;
|
|
|
|
if (LookupBucketFor(Val, TheBucket))
|
2012-06-16 01:05:01 +00:00
|
|
|
return iterator(TheBucket, getBucketsEnd(), true);
|
2012-01-30 06:55:43 +00:00
|
|
|
return end();
|
|
|
|
}
|
|
|
|
template<class LookupKeyT>
|
|
|
|
const_iterator find_as(const LookupKeyT &Val) const {
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
const BucketT *TheBucket;
|
2012-01-30 06:55:43 +00:00
|
|
|
if (LookupBucketFor(Val, TheBucket))
|
2012-06-16 01:05:01 +00:00
|
|
|
return const_iterator(TheBucket, getBucketsEnd(), true);
|
2012-01-30 06:55:43 +00:00
|
|
|
return end();
|
|
|
|
}
|
|
|
|
|
2008-08-29 00:48:44 +00:00
|
|
|
/// lookup - Return the entry for the specified key, or a default
|
|
|
|
/// constructed value if no such entry exists.
|
|
|
|
ValueT lookup(const KeyT &Val) const {
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
const BucketT *TheBucket;
|
2008-08-29 00:48:44 +00:00
|
|
|
if (LookupBucketFor(Val, TheBucket))
|
|
|
|
return TheBucket->second;
|
|
|
|
return ValueT();
|
|
|
|
}
|
|
|
|
|
2009-10-07 09:23:56 +00:00
|
|
|
// Inserts key,value pair into the map if the key isn't already in the map.
|
|
|
|
// If the key is already in the map, it returns false and doesn't update the
|
|
|
|
// value.
|
2008-07-07 17:46:23 +00:00
|
|
|
std::pair<iterator, bool> insert(const std::pair<KeyT, ValueT> &KV) {
|
2007-02-04 00:42:41 +00:00
|
|
|
BucketT *TheBucket;
|
|
|
|
if (LookupBucketFor(KV.first, TheBucket))
|
2012-06-16 01:05:01 +00:00
|
|
|
return std::make_pair(iterator(TheBucket, getBucketsEnd(), true),
|
2008-07-07 17:46:23 +00:00
|
|
|
false); // Already in map.
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-02-04 00:42:41 +00:00
|
|
|
// Otherwise, insert the new element.
|
2008-07-07 17:46:23 +00:00
|
|
|
TheBucket = InsertIntoBucket(KV.first, KV.second, TheBucket);
|
2012-06-16 01:05:01 +00:00
|
|
|
return std::make_pair(iterator(TheBucket, getBucketsEnd(), true), true);
|
2007-02-04 00:42:41 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2013-01-14 19:24:15 +00:00
|
|
|
// Inserts key,value pair into the map if the key isn't already in the map.
|
|
|
|
// If the key is already in the map, it returns false and doesn't update the
|
|
|
|
// value.
|
|
|
|
std::pair<iterator, bool> insert(std::pair<KeyT, ValueT> &&KV) {
|
|
|
|
BucketT *TheBucket;
|
|
|
|
if (LookupBucketFor(KV.first, TheBucket))
|
|
|
|
return std::make_pair(iterator(TheBucket, getBucketsEnd(), true),
|
|
|
|
false); // Already in map.
|
|
|
|
|
|
|
|
// Otherwise, insert the new element.
|
|
|
|
TheBucket = InsertIntoBucket(std::move(KV.first),
|
|
|
|
std::move(KV.second),
|
|
|
|
TheBucket);
|
|
|
|
return std::make_pair(iterator(TheBucket, getBucketsEnd(), true), true);
|
|
|
|
}
|
2014-03-01 09:27:28 +00:00
|
|
|
|
2008-12-02 06:08:04 +00:00
|
|
|
/// insert - Range insertion of pairs.
|
|
|
|
template<typename InputIt>
|
|
|
|
void insert(InputIt I, InputIt E) {
|
|
|
|
for (; I != E; ++I)
|
|
|
|
insert(*I);
|
|
|
|
}
|
|
|
|
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-02-02 20:34:32 +00:00
|
|
|
bool erase(const KeyT &Val) {
|
|
|
|
BucketT *TheBucket;
|
|
|
|
if (!LookupBucketFor(Val, TheBucket))
|
|
|
|
return false; // not in map.
|
|
|
|
|
|
|
|
TheBucket->second.~ValueT();
|
|
|
|
TheBucket->first = getTombstoneKey();
|
2012-06-16 01:18:07 +00:00
|
|
|
decrementNumEntries();
|
|
|
|
incrementNumTombstones();
|
2007-02-02 20:34:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2010-09-01 14:00:35 +00:00
|
|
|
void erase(iterator I) {
|
2007-02-02 20:34:32 +00:00
|
|
|
BucketT *TheBucket = &*I;
|
|
|
|
TheBucket->second.~ValueT();
|
|
|
|
TheBucket->first = getTombstoneKey();
|
2012-06-16 01:18:07 +00:00
|
|
|
decrementNumEntries();
|
|
|
|
incrementNumTombstones();
|
2007-02-02 20:34:32 +00:00
|
|
|
}
|
2007-11-01 00:54:57 +00:00
|
|
|
|
|
|
|
value_type& FindAndConstruct(const KeyT &Key) {
|
2007-02-01 07:49:59 +00:00
|
|
|
BucketT *TheBucket;
|
2007-02-04 00:42:41 +00:00
|
|
|
if (LookupBucketFor(Key, TheBucket))
|
2007-11-01 00:54:57 +00:00
|
|
|
return *TheBucket;
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-11-01 00:54:57 +00:00
|
|
|
return *InsertIntoBucket(Key, ValueT(), TheBucket);
|
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-11-01 00:54:57 +00:00
|
|
|
ValueT &operator[](const KeyT &Key) {
|
|
|
|
return FindAndConstruct(Key).second;
|
2007-02-04 00:42:41 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2012-05-27 17:38:30 +00:00
|
|
|
value_type& FindAndConstruct(KeyT &&Key) {
|
|
|
|
BucketT *TheBucket;
|
|
|
|
if (LookupBucketFor(Key, TheBucket))
|
|
|
|
return *TheBucket;
|
|
|
|
|
2013-06-01 16:37:55 +00:00
|
|
|
return *InsertIntoBucket(std::move(Key), ValueT(), TheBucket);
|
2012-05-27 17:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ValueT &operator[](KeyT &&Key) {
|
2013-06-01 16:37:55 +00:00
|
|
|
return FindAndConstruct(std::move(Key)).second;
|
2012-05-27 17:38:30 +00:00
|
|
|
}
|
|
|
|
|
2009-03-31 20:57:23 +00:00
|
|
|
/// isPointerIntoBucketsArray - Return true if the specified pointer points
|
|
|
|
/// somewhere into the DenseMap's array of buckets (i.e. either to a key or
|
|
|
|
/// value in the DenseMap).
|
|
|
|
bool isPointerIntoBucketsArray(const void *Ptr) const {
|
2012-06-16 01:05:01 +00:00
|
|
|
return Ptr >= getBuckets() && Ptr < getBucketsEnd();
|
2009-03-31 20:57:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// getPointerIntoBucketsArray() - Return an opaque pointer into the buckets
|
|
|
|
/// array. In conjunction with the previous method, this can be used to
|
|
|
|
/// determine whether an insertion caused the DenseMap to reallocate.
|
2012-06-16 01:05:01 +00:00
|
|
|
const void *getPointerIntoBucketsArray() const { return getBuckets(); }
|
2009-03-31 20:57:23 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
protected:
|
2012-06-16 01:18:07 +00:00
|
|
|
DenseMapBase() {}
|
2012-06-16 01:05:01 +00:00
|
|
|
|
|
|
|
void destroyAll() {
|
|
|
|
if (getNumBuckets() == 0) // Nothing to do.
|
2012-05-27 22:53:10 +00:00
|
|
|
return;
|
|
|
|
|
2012-05-27 17:38:18 +00:00
|
|
|
const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
|
2012-06-16 01:05:01 +00:00
|
|
|
for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P) {
|
2012-05-27 17:38:18 +00:00
|
|
|
if (!KeyInfoT::isEqual(P->first, EmptyKey) &&
|
|
|
|
!KeyInfoT::isEqual(P->first, TombstoneKey))
|
|
|
|
P->second.~ValueT();
|
|
|
|
P->first.~KeyT();
|
2007-08-16 00:18:32 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2009-07-21 18:01:37 +00:00
|
|
|
#ifndef NDEBUG
|
2012-06-16 01:05:01 +00:00
|
|
|
memset((void*)getBuckets(), 0x5a, sizeof(BucketT)*getNumBuckets());
|
2009-07-21 18:01:37 +00:00
|
|
|
#endif
|
2012-05-27 17:38:18 +00:00
|
|
|
}
|
2011-03-05 22:00:28 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
void initEmpty() {
|
2012-06-16 01:18:07 +00:00
|
|
|
setNumEntries(0);
|
|
|
|
setNumTombstones(0);
|
2012-06-16 01:05:01 +00:00
|
|
|
|
|
|
|
assert((getNumBuckets() & (getNumBuckets()-1)) == 0 &&
|
|
|
|
"# initial buckets must be a power of two!");
|
|
|
|
const KeyT EmptyKey = getEmptyKey();
|
|
|
|
for (BucketT *B = getBuckets(), *E = getBucketsEnd(); B != E; ++B)
|
|
|
|
new (&B->first) KeyT(EmptyKey);
|
|
|
|
}
|
2012-05-27 17:38:18 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
void moveFromOldBuckets(BucketT *OldBucketsBegin, BucketT *OldBucketsEnd) {
|
|
|
|
initEmpty();
|
2011-03-05 22:00:28 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
// Insert all the old elements.
|
|
|
|
const KeyT EmptyKey = getEmptyKey();
|
|
|
|
const KeyT TombstoneKey = getTombstoneKey();
|
|
|
|
for (BucketT *B = OldBucketsBegin, *E = OldBucketsEnd; B != E; ++B) {
|
|
|
|
if (!KeyInfoT::isEqual(B->first, EmptyKey) &&
|
|
|
|
!KeyInfoT::isEqual(B->first, TombstoneKey)) {
|
|
|
|
// Insert the key/value into the new table.
|
|
|
|
BucketT *DestBucket;
|
|
|
|
bool FoundVal = LookupBucketFor(B->first, DestBucket);
|
|
|
|
(void)FoundVal; // silence warning.
|
|
|
|
assert(!FoundVal && "Key already in new map?");
|
2014-03-02 04:08:41 +00:00
|
|
|
DestBucket->first = std::move(B->first);
|
|
|
|
new (&DestBucket->second) ValueT(std::move(B->second));
|
2012-06-16 01:18:07 +00:00
|
|
|
incrementNumEntries();
|
2012-06-16 01:05:01 +00:00
|
|
|
|
|
|
|
// Free the value.
|
|
|
|
B->second.~ValueT();
|
|
|
|
}
|
|
|
|
B->first.~KeyT();
|
2011-03-05 22:00:28 +00:00
|
|
|
}
|
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
if (OldBucketsBegin != OldBucketsEnd)
|
|
|
|
memset((void*)OldBucketsBegin, 0x5a,
|
|
|
|
sizeof(BucketT) * (OldBucketsEnd - OldBucketsBegin));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename OtherBaseT>
|
|
|
|
void copyFrom(const DenseMapBase<OtherBaseT, KeyT, ValueT, KeyInfoT>& other) {
|
|
|
|
assert(getNumBuckets() == other.getNumBuckets());
|
|
|
|
|
2012-06-16 01:18:07 +00:00
|
|
|
setNumEntries(other.getNumEntries());
|
|
|
|
setNumTombstones(other.getNumTombstones());
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2012-04-06 10:43:44 +00:00
|
|
|
if (isPodLike<KeyT>::value && isPodLike<ValueT>::value)
|
2012-06-16 01:05:01 +00:00
|
|
|
memcpy(getBuckets(), other.getBuckets(),
|
|
|
|
getNumBuckets() * sizeof(BucketT));
|
2007-09-11 03:48:08 +00:00
|
|
|
else
|
2012-06-16 01:05:01 +00:00
|
|
|
for (size_t i = 0; i < getNumBuckets(); ++i) {
|
|
|
|
new (&getBuckets()[i].first) KeyT(other.getBuckets()[i].first);
|
|
|
|
if (!KeyInfoT::isEqual(getBuckets()[i].first, getEmptyKey()) &&
|
|
|
|
!KeyInfoT::isEqual(getBuckets()[i].first, getTombstoneKey()))
|
|
|
|
new (&getBuckets()[i].second) ValueT(other.getBuckets()[i].second);
|
2007-09-11 03:48:08 +00:00
|
|
|
}
|
2007-08-16 00:18:32 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
void swap(DenseMapBase& RHS) {
|
2012-06-16 01:18:07 +00:00
|
|
|
std::swap(getNumEntries(), RHS.getNumEntries());
|
|
|
|
std::swap(getNumTombstones(), RHS.getNumTombstones());
|
2012-06-16 01:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned getHashValue(const KeyT &Val) {
|
|
|
|
return KeyInfoT::getHashValue(Val);
|
|
|
|
}
|
|
|
|
template<typename LookupKeyT>
|
|
|
|
static unsigned getHashValue(const LookupKeyT &Val) {
|
|
|
|
return KeyInfoT::getHashValue(Val);
|
|
|
|
}
|
|
|
|
static const KeyT getEmptyKey() {
|
|
|
|
return KeyInfoT::getEmptyKey();
|
|
|
|
}
|
|
|
|
static const KeyT getTombstoneKey() {
|
|
|
|
return KeyInfoT::getTombstoneKey();
|
|
|
|
}
|
|
|
|
|
2012-06-17 10:33:51 +00:00
|
|
|
private:
|
2012-06-16 01:18:07 +00:00
|
|
|
unsigned getNumEntries() const {
|
|
|
|
return static_cast<const DerivedT *>(this)->getNumEntries();
|
|
|
|
}
|
|
|
|
void setNumEntries(unsigned Num) {
|
|
|
|
static_cast<DerivedT *>(this)->setNumEntries(Num);
|
|
|
|
}
|
|
|
|
void incrementNumEntries() {
|
|
|
|
setNumEntries(getNumEntries() + 1);
|
|
|
|
}
|
|
|
|
void decrementNumEntries() {
|
|
|
|
setNumEntries(getNumEntries() - 1);
|
|
|
|
}
|
|
|
|
unsigned getNumTombstones() const {
|
|
|
|
return static_cast<const DerivedT *>(this)->getNumTombstones();
|
|
|
|
}
|
|
|
|
void setNumTombstones(unsigned Num) {
|
|
|
|
static_cast<DerivedT *>(this)->setNumTombstones(Num);
|
|
|
|
}
|
|
|
|
void incrementNumTombstones() {
|
|
|
|
setNumTombstones(getNumTombstones() + 1);
|
|
|
|
}
|
|
|
|
void decrementNumTombstones() {
|
|
|
|
setNumTombstones(getNumTombstones() - 1);
|
|
|
|
}
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
const BucketT *getBuckets() const {
|
2012-06-16 01:05:01 +00:00
|
|
|
return static_cast<const DerivedT *>(this)->getBuckets();
|
|
|
|
}
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
BucketT *getBuckets() {
|
|
|
|
return static_cast<DerivedT *>(this)->getBuckets();
|
|
|
|
}
|
2012-06-16 01:05:01 +00:00
|
|
|
unsigned getNumBuckets() const {
|
|
|
|
return static_cast<const DerivedT *>(this)->getNumBuckets();
|
|
|
|
}
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
BucketT *getBucketsEnd() {
|
|
|
|
return getBuckets() + getNumBuckets();
|
|
|
|
}
|
|
|
|
const BucketT *getBucketsEnd() const {
|
2012-06-16 01:05:01 +00:00
|
|
|
return getBuckets() + getNumBuckets();
|
|
|
|
}
|
|
|
|
|
|
|
|
void grow(unsigned AtLeast) {
|
|
|
|
static_cast<DerivedT *>(this)->grow(AtLeast);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shrink_and_clear() {
|
|
|
|
static_cast<DerivedT *>(this)->shrink_and_clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-04 00:42:41 +00:00
|
|
|
BucketT *InsertIntoBucket(const KeyT &Key, const ValueT &Value,
|
|
|
|
BucketT *TheBucket) {
|
2012-05-27 17:38:30 +00:00
|
|
|
TheBucket = InsertIntoBucketImpl(Key, TheBucket);
|
|
|
|
|
|
|
|
TheBucket->first = Key;
|
|
|
|
new (&TheBucket->second) ValueT(Value);
|
|
|
|
return TheBucket;
|
|
|
|
}
|
|
|
|
|
|
|
|
BucketT *InsertIntoBucket(const KeyT &Key, ValueT &&Value,
|
|
|
|
BucketT *TheBucket) {
|
|
|
|
TheBucket = InsertIntoBucketImpl(Key, TheBucket);
|
|
|
|
|
|
|
|
TheBucket->first = Key;
|
|
|
|
new (&TheBucket->second) ValueT(std::move(Value));
|
|
|
|
return TheBucket;
|
|
|
|
}
|
|
|
|
|
|
|
|
BucketT *InsertIntoBucket(KeyT &&Key, ValueT &&Value, BucketT *TheBucket) {
|
|
|
|
TheBucket = InsertIntoBucketImpl(Key, TheBucket);
|
|
|
|
|
|
|
|
TheBucket->first = std::move(Key);
|
|
|
|
new (&TheBucket->second) ValueT(std::move(Value));
|
|
|
|
return TheBucket;
|
|
|
|
}
|
|
|
|
|
|
|
|
BucketT *InsertIntoBucketImpl(const KeyT &Key, BucketT *TheBucket) {
|
2007-02-07 00:55:59 +00:00
|
|
|
// If the load of the hash table is more than 3/4, or if fewer than 1/8 of
|
|
|
|
// the buckets are empty (meaning that many are filled with tombstones),
|
|
|
|
// grow the table.
|
|
|
|
//
|
|
|
|
// The later case is tricky. For example, if we had one empty bucket with
|
|
|
|
// tons of tombstones, failing lookups (e.g. for insertion) would have to
|
|
|
|
// probe almost the entire table until it found the empty bucket. If the
|
|
|
|
// table completely filled with tombstones, no lookup would ever succeed,
|
|
|
|
// causing infinite loops in lookup.
|
2012-06-16 01:18:07 +00:00
|
|
|
unsigned NewNumEntries = getNumEntries() + 1;
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
unsigned NumBuckets = getNumBuckets();
|
|
|
|
if (NewNumEntries*4 >= NumBuckets*3) {
|
|
|
|
this->grow(NumBuckets * 2);
|
2007-02-04 00:42:41 +00:00
|
|
|
LookupBucketFor(Key, TheBucket);
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
NumBuckets = getNumBuckets();
|
2013-10-30 15:10:54 +00:00
|
|
|
} else if (NumBuckets-(NewNumEntries+getNumTombstones()) <= NumBuckets/8) {
|
|
|
|
this->grow(NumBuckets);
|
2011-03-30 18:32:41 +00:00
|
|
|
LookupBucketFor(Key, TheBucket);
|
|
|
|
}
|
2012-09-22 01:24:16 +00:00
|
|
|
assert(TheBucket);
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
// Only update the state after we've grown our bucket space appropriately
|
|
|
|
// so that when growing buckets we have self-consistent entry count.
|
2012-06-16 01:18:07 +00:00
|
|
|
incrementNumEntries();
|
2012-06-16 01:05:01 +00:00
|
|
|
|
2007-02-07 00:55:59 +00:00
|
|
|
// If we are writing over a tombstone, remember this.
|
2013-01-05 05:14:23 +00:00
|
|
|
const KeyT EmptyKey = getEmptyKey();
|
|
|
|
if (!KeyInfoT::isEqual(TheBucket->first, EmptyKey))
|
2012-06-16 01:18:07 +00:00
|
|
|
decrementNumTombstones();
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-02-04 00:42:41 +00:00
|
|
|
return TheBucket;
|
2007-02-01 07:49:59 +00:00
|
|
|
}
|
2007-02-04 00:42:41 +00:00
|
|
|
|
2007-02-01 07:49:59 +00:00
|
|
|
/// LookupBucketFor - Lookup the appropriate bucket for Val, returning it in
|
|
|
|
/// FoundBucket. If the bucket contains the key and a value, this returns
|
|
|
|
/// true, otherwise it returns a bucket with an empty marker or tombstone and
|
|
|
|
/// returns false.
|
2012-01-30 06:55:43 +00:00
|
|
|
template<typename LookupKeyT>
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
bool LookupBucketFor(const LookupKeyT &Val,
|
|
|
|
const BucketT *&FoundBucket) const {
|
|
|
|
const BucketT *BucketsPtr = getBuckets();
|
2012-07-03 07:16:13 +00:00
|
|
|
const unsigned NumBuckets = getNumBuckets();
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2012-07-03 07:16:13 +00:00
|
|
|
if (NumBuckets == 0) {
|
2014-04-07 04:17:22 +00:00
|
|
|
FoundBucket = nullptr;
|
2011-03-05 16:43:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-02-01 07:49:59 +00:00
|
|
|
// FoundTombstone - Keep track of whether we find a tombstone while probing.
|
2014-04-07 04:17:22 +00:00
|
|
|
const BucketT *FoundTombstone = nullptr;
|
2007-02-01 07:49:59 +00:00
|
|
|
const KeyT EmptyKey = getEmptyKey();
|
|
|
|
const KeyT TombstoneKey = getTombstoneKey();
|
2007-10-09 05:42:12 +00:00
|
|
|
assert(!KeyInfoT::isEqual(Val, EmptyKey) &&
|
|
|
|
!KeyInfoT::isEqual(Val, TombstoneKey) &&
|
2007-02-01 07:49:59 +00:00
|
|
|
"Empty/Tombstone value shouldn't be inserted into map!");
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2012-07-03 07:16:13 +00:00
|
|
|
unsigned BucketNo = getHashValue(Val) & (NumBuckets-1);
|
|
|
|
unsigned ProbeAmt = 1;
|
2007-02-01 07:49:59 +00:00
|
|
|
while (1) {
|
2012-07-03 07:16:13 +00:00
|
|
|
const BucketT *ThisBucket = BucketsPtr + BucketNo;
|
2007-02-01 07:49:59 +00:00
|
|
|
// Found Val's bucket? If so, return it.
|
2012-01-30 06:55:43 +00:00
|
|
|
if (KeyInfoT::isEqual(Val, ThisBucket->first)) {
|
2007-02-01 07:49:59 +00:00
|
|
|
FoundBucket = ThisBucket;
|
|
|
|
return true;
|
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-02-01 07:49:59 +00:00
|
|
|
// If we found an empty bucket, the key doesn't exist in the set.
|
|
|
|
// Insert it and return the default value.
|
2007-09-17 18:34:04 +00:00
|
|
|
if (KeyInfoT::isEqual(ThisBucket->first, EmptyKey)) {
|
2007-02-01 07:49:59 +00:00
|
|
|
// If we've already seen a tombstone while probing, fill it in instead
|
|
|
|
// of the empty bucket we eventually probed to.
|
|
|
|
FoundBucket = FoundTombstone ? FoundTombstone : ThisBucket;
|
|
|
|
return false;
|
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-02-01 07:49:59 +00:00
|
|
|
// If this is a tombstone, remember it. If Val ends up not in the map, we
|
|
|
|
// prefer to return it than something that would require more probing.
|
2007-09-17 18:34:04 +00:00
|
|
|
if (KeyInfoT::isEqual(ThisBucket->first, TombstoneKey) && !FoundTombstone)
|
2007-02-01 07:49:59 +00:00
|
|
|
FoundTombstone = ThisBucket; // Remember the first tombstone found.
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-02-01 07:49:59 +00:00
|
|
|
// Otherwise, it's a hash collision or a tombstone, continue quadratic
|
|
|
|
// probing.
|
|
|
|
BucketNo += ProbeAmt++;
|
2012-07-03 07:16:13 +00:00
|
|
|
BucketNo &= (NumBuckets-1);
|
2007-02-01 07:49:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
template <typename LookupKeyT>
|
|
|
|
bool LookupBucketFor(const LookupKeyT &Val, BucketT *&FoundBucket) {
|
2012-06-18 22:31:28 +00:00
|
|
|
const BucketT *ConstFoundBucket;
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
bool Result = const_cast<const DenseMapBase *>(this)
|
|
|
|
->LookupBucketFor(Val, ConstFoundBucket);
|
|
|
|
FoundBucket = const_cast<BucketT *>(ConstFoundBucket);
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
public:
|
|
|
|
/// Return the approximate size (in bytes) of the actual map.
|
|
|
|
/// This is just the raw memory used by DenseMap.
|
|
|
|
/// If entries are pointers to objects, the size of the referenced objects
|
|
|
|
/// are not included.
|
|
|
|
size_t getMemorySize() const {
|
|
|
|
return getNumBuckets() * sizeof(BucketT);
|
|
|
|
}
|
|
|
|
};
|
2011-03-05 16:43:41 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
template<typename KeyT, typename ValueT,
|
|
|
|
typename KeyInfoT = DenseMapInfo<KeyT> >
|
|
|
|
class DenseMap
|
|
|
|
: public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT>,
|
|
|
|
KeyT, ValueT, KeyInfoT> {
|
|
|
|
// Lift some types from the dependent base class into this class for
|
|
|
|
// simplicity of referring to them.
|
|
|
|
typedef DenseMapBase<DenseMap, KeyT, ValueT, KeyInfoT> BaseT;
|
|
|
|
typedef typename BaseT::BucketT BucketT;
|
|
|
|
friend class DenseMapBase<DenseMap, KeyT, ValueT, KeyInfoT>;
|
2011-03-05 16:43:41 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
BucketT *Buckets;
|
2012-06-16 01:18:07 +00:00
|
|
|
unsigned NumEntries;
|
|
|
|
unsigned NumTombstones;
|
2012-06-16 01:05:01 +00:00
|
|
|
unsigned NumBuckets;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit DenseMap(unsigned NumInitBuckets = 0) {
|
|
|
|
init(NumInitBuckets);
|
2007-02-01 07:49:59 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2013-01-05 00:21:12 +00:00
|
|
|
DenseMap(const DenseMap &other) : BaseT() {
|
2012-06-16 01:05:01 +00:00
|
|
|
init(0);
|
|
|
|
copyFrom(other);
|
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2013-01-05 00:21:12 +00:00
|
|
|
DenseMap(DenseMap &&other) : BaseT() {
|
2012-06-16 01:05:01 +00:00
|
|
|
init(0);
|
|
|
|
swap(other);
|
|
|
|
}
|
2011-03-05 16:43:41 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
template<typename InputIt>
|
|
|
|
DenseMap(const InputIt &I, const InputIt &E) {
|
|
|
|
init(NextPowerOf2(std::distance(I, E)));
|
|
|
|
this->insert(I, E);
|
|
|
|
}
|
2007-02-01 07:49:59 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
~DenseMap() {
|
|
|
|
this->destroyAll();
|
|
|
|
operator delete(Buckets);
|
|
|
|
}
|
2007-02-01 07:49:59 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
void swap(DenseMap& RHS) {
|
|
|
|
std::swap(Buckets, RHS.Buckets);
|
2012-06-16 01:18:07 +00:00
|
|
|
std::swap(NumEntries, RHS.NumEntries);
|
|
|
|
std::swap(NumTombstones, RHS.NumTombstones);
|
|
|
|
std::swap(NumBuckets, RHS.NumBuckets);
|
2012-06-16 01:05:01 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
DenseMap& operator=(const DenseMap& other) {
|
|
|
|
copyFrom(other);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
DenseMap& operator=(DenseMap &&other) {
|
|
|
|
this->destroyAll();
|
|
|
|
operator delete(Buckets);
|
|
|
|
init(0);
|
|
|
|
swap(other);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void copyFrom(const DenseMap& other) {
|
|
|
|
this->destroyAll();
|
|
|
|
operator delete(Buckets);
|
2012-06-16 01:18:07 +00:00
|
|
|
if (allocateBuckets(other.NumBuckets)) {
|
2012-06-16 01:05:01 +00:00
|
|
|
this->BaseT::copyFrom(other);
|
2012-06-16 01:18:07 +00:00
|
|
|
} else {
|
|
|
|
NumEntries = 0;
|
|
|
|
NumTombstones = 0;
|
|
|
|
}
|
2007-02-01 07:49:59 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
void init(unsigned InitBuckets) {
|
2012-06-16 01:18:07 +00:00
|
|
|
if (allocateBuckets(InitBuckets)) {
|
2012-06-16 01:05:01 +00:00
|
|
|
this->BaseT::initEmpty();
|
2012-06-16 01:18:07 +00:00
|
|
|
} else {
|
|
|
|
NumEntries = 0;
|
|
|
|
NumTombstones = 0;
|
|
|
|
}
|
2012-06-16 01:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void grow(unsigned AtLeast) {
|
2007-07-20 16:15:24 +00:00
|
|
|
unsigned OldNumBuckets = NumBuckets;
|
|
|
|
BucketT *OldBuckets = Buckets;
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2013-05-01 14:07:02 +00:00
|
|
|
allocateBuckets(std::max<unsigned>(64, static_cast<unsigned>(NextPowerOf2(AtLeast-1))));
|
2012-06-16 01:05:01 +00:00
|
|
|
assert(Buckets);
|
|
|
|
if (!OldBuckets) {
|
|
|
|
this->BaseT::initEmpty();
|
|
|
|
return;
|
2007-07-20 16:15:24 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
this->moveFromOldBuckets(OldBuckets, OldBuckets+OldNumBuckets);
|
|
|
|
|
2007-07-20 16:15:24 +00:00
|
|
|
// Free the old table.
|
2008-07-03 00:59:36 +00:00
|
|
|
operator delete(OldBuckets);
|
2012-06-16 01:05:01 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
void shrink_and_clear() {
|
2012-06-16 01:18:07 +00:00
|
|
|
unsigned OldNumEntries = NumEntries;
|
2012-06-16 01:05:01 +00:00
|
|
|
this->destroyAll();
|
|
|
|
|
|
|
|
// Reduce the number of buckets.
|
2012-08-14 02:56:51 +00:00
|
|
|
unsigned NewNumBuckets = 0;
|
|
|
|
if (OldNumEntries)
|
|
|
|
NewNumBuckets = std::max(64, 1 << (Log2_32_Ceil(OldNumEntries) + 1));
|
2012-06-16 01:05:01 +00:00
|
|
|
if (NewNumBuckets == NumBuckets) {
|
|
|
|
this->BaseT::initEmpty();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
operator delete(Buckets);
|
|
|
|
init(NewNumBuckets);
|
2007-07-20 16:15:24 +00:00
|
|
|
}
|
2012-06-16 01:05:01 +00:00
|
|
|
|
|
|
|
private:
|
2012-06-16 01:18:07 +00:00
|
|
|
unsigned getNumEntries() const {
|
|
|
|
return NumEntries;
|
|
|
|
}
|
|
|
|
void setNumEntries(unsigned Num) {
|
|
|
|
NumEntries = Num;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumTombstones() const {
|
|
|
|
return NumTombstones;
|
|
|
|
}
|
|
|
|
void setNumTombstones(unsigned Num) {
|
|
|
|
NumTombstones = Num;
|
|
|
|
}
|
|
|
|
|
2012-06-16 01:05:01 +00:00
|
|
|
BucketT *getBuckets() const {
|
|
|
|
return Buckets;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumBuckets() const {
|
|
|
|
return NumBuckets;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool allocateBuckets(unsigned Num) {
|
|
|
|
NumBuckets = Num;
|
|
|
|
if (NumBuckets == 0) {
|
2014-04-07 04:17:22 +00:00
|
|
|
Buckets = nullptr;
|
2012-06-16 01:05:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Buckets = static_cast<BucketT*>(operator new(sizeof(BucketT) * NumBuckets));
|
|
|
|
return true;
|
2011-04-28 04:52:57 +00:00
|
|
|
}
|
2007-02-01 07:49:59 +00:00
|
|
|
};
|
|
|
|
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
template<typename KeyT, typename ValueT,
|
|
|
|
unsigned InlineBuckets = 4,
|
|
|
|
typename KeyInfoT = DenseMapInfo<KeyT> >
|
|
|
|
class SmallDenseMap
|
|
|
|
: public DenseMapBase<SmallDenseMap<KeyT, ValueT, InlineBuckets, KeyInfoT>,
|
|
|
|
KeyT, ValueT, KeyInfoT> {
|
|
|
|
// Lift some types from the dependent base class into this class for
|
|
|
|
// simplicity of referring to them.
|
|
|
|
typedef DenseMapBase<SmallDenseMap, KeyT, ValueT, KeyInfoT> BaseT;
|
|
|
|
typedef typename BaseT::BucketT BucketT;
|
|
|
|
friend class DenseMapBase<SmallDenseMap, KeyT, ValueT, KeyInfoT>;
|
|
|
|
|
|
|
|
unsigned Small : 1;
|
|
|
|
unsigned NumEntries : 31;
|
|
|
|
unsigned NumTombstones;
|
|
|
|
|
|
|
|
struct LargeRep {
|
|
|
|
BucketT *Buckets;
|
|
|
|
unsigned NumBuckets;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// A "union" of an inline bucket array and the struct representing
|
|
|
|
/// a large bucket. This union will be discriminated by the 'Small' bit.
|
2012-08-17 01:47:25 +00:00
|
|
|
AlignedCharArrayUnion<BucketT[InlineBuckets], LargeRep> storage;
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit SmallDenseMap(unsigned NumInitBuckets = 0) {
|
|
|
|
init(NumInitBuckets);
|
|
|
|
}
|
|
|
|
|
2013-08-16 02:56:43 +00:00
|
|
|
SmallDenseMap(const SmallDenseMap &other) : BaseT() {
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
init(0);
|
|
|
|
copyFrom(other);
|
|
|
|
}
|
|
|
|
|
2013-08-16 02:56:43 +00:00
|
|
|
SmallDenseMap(SmallDenseMap &&other) : BaseT() {
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
init(0);
|
|
|
|
swap(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename InputIt>
|
|
|
|
SmallDenseMap(const InputIt &I, const InputIt &E) {
|
|
|
|
init(NextPowerOf2(std::distance(I, E)));
|
|
|
|
this->insert(I, E);
|
|
|
|
}
|
|
|
|
|
|
|
|
~SmallDenseMap() {
|
|
|
|
this->destroyAll();
|
|
|
|
deallocateBuckets();
|
|
|
|
}
|
|
|
|
|
|
|
|
void swap(SmallDenseMap& RHS) {
|
2012-06-17 11:28:13 +00:00
|
|
|
unsigned TmpNumEntries = RHS.NumEntries;
|
|
|
|
RHS.NumEntries = NumEntries;
|
|
|
|
NumEntries = TmpNumEntries;
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
std::swap(NumTombstones, RHS.NumTombstones);
|
2012-06-17 11:28:13 +00:00
|
|
|
|
|
|
|
const KeyT EmptyKey = this->getEmptyKey();
|
|
|
|
const KeyT TombstoneKey = this->getTombstoneKey();
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
if (Small && RHS.Small) {
|
2012-06-17 11:28:13 +00:00
|
|
|
// If we're swapping inline bucket arrays, we have to cope with some of
|
|
|
|
// the tricky bits of DenseMap's storage system: the buckets are not
|
|
|
|
// fully initialized. Thus we swap every key, but we may have
|
|
|
|
// a one-directional move of the value.
|
|
|
|
for (unsigned i = 0, e = InlineBuckets; i != e; ++i) {
|
|
|
|
BucketT *LHSB = &getInlineBuckets()[i],
|
|
|
|
*RHSB = &RHS.getInlineBuckets()[i];
|
|
|
|
bool hasLHSValue = (!KeyInfoT::isEqual(LHSB->first, EmptyKey) &&
|
|
|
|
!KeyInfoT::isEqual(LHSB->first, TombstoneKey));
|
|
|
|
bool hasRHSValue = (!KeyInfoT::isEqual(RHSB->first, EmptyKey) &&
|
|
|
|
!KeyInfoT::isEqual(RHSB->first, TombstoneKey));
|
|
|
|
if (hasLHSValue && hasRHSValue) {
|
|
|
|
// Swap together if we can...
|
|
|
|
std::swap(*LHSB, *RHSB);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Swap separately and handle any assymetry.
|
|
|
|
std::swap(LHSB->first, RHSB->first);
|
|
|
|
if (hasLHSValue) {
|
2014-03-02 04:08:41 +00:00
|
|
|
new (&RHSB->second) ValueT(std::move(LHSB->second));
|
2012-06-17 11:28:13 +00:00
|
|
|
LHSB->second.~ValueT();
|
|
|
|
} else if (hasRHSValue) {
|
2014-03-02 04:08:41 +00:00
|
|
|
new (&LHSB->second) ValueT(std::move(RHSB->second));
|
2012-06-17 11:28:13 +00:00
|
|
|
RHSB->second.~ValueT();
|
|
|
|
}
|
|
|
|
}
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!Small && !RHS.Small) {
|
|
|
|
std::swap(getLargeRep()->Buckets, RHS.getLargeRep()->Buckets);
|
|
|
|
std::swap(getLargeRep()->NumBuckets, RHS.getLargeRep()->NumBuckets);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallDenseMap &SmallSide = Small ? *this : RHS;
|
|
|
|
SmallDenseMap &LargeSide = Small ? RHS : *this;
|
|
|
|
|
|
|
|
// First stash the large side's rep and move the small side across.
|
2014-03-02 04:08:41 +00:00
|
|
|
LargeRep TmpRep = std::move(*LargeSide.getLargeRep());
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
LargeSide.getLargeRep()->~LargeRep();
|
|
|
|
LargeSide.Small = true;
|
|
|
|
// This is similar to the standard move-from-old-buckets, but the bucket
|
2012-06-17 11:28:13 +00:00
|
|
|
// count hasn't actually rotated in this case. So we have to carefully
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
// move construct the keys and values into their new locations, but there
|
|
|
|
// is no need to re-hash things.
|
|
|
|
for (unsigned i = 0, e = InlineBuckets; i != e; ++i) {
|
|
|
|
BucketT *NewB = &LargeSide.getInlineBuckets()[i],
|
|
|
|
*OldB = &SmallSide.getInlineBuckets()[i];
|
2014-03-02 04:08:41 +00:00
|
|
|
new (&NewB->first) KeyT(std::move(OldB->first));
|
2012-06-17 11:28:13 +00:00
|
|
|
OldB->first.~KeyT();
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
if (!KeyInfoT::isEqual(NewB->first, EmptyKey) &&
|
|
|
|
!KeyInfoT::isEqual(NewB->first, TombstoneKey)) {
|
2014-03-02 04:08:41 +00:00
|
|
|
new (&NewB->second) ValueT(std::move(OldB->second));
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
OldB->second.~ValueT();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The hard part of moving the small buckets across is done, just move
|
|
|
|
// the TmpRep into its new home.
|
|
|
|
SmallSide.Small = false;
|
2014-03-02 04:08:41 +00:00
|
|
|
new (SmallSide.getLargeRep()) LargeRep(std::move(TmpRep));
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SmallDenseMap& operator=(const SmallDenseMap& other) {
|
|
|
|
copyFrom(other);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
SmallDenseMap& operator=(SmallDenseMap &&other) {
|
|
|
|
this->destroyAll();
|
|
|
|
deallocateBuckets();
|
|
|
|
init(0);
|
|
|
|
swap(other);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void copyFrom(const SmallDenseMap& other) {
|
|
|
|
this->destroyAll();
|
|
|
|
deallocateBuckets();
|
|
|
|
Small = true;
|
|
|
|
if (other.getNumBuckets() > InlineBuckets) {
|
|
|
|
Small = false;
|
2014-02-25 23:35:13 +00:00
|
|
|
new (getLargeRep()) LargeRep(allocateBuckets(other.getNumBuckets()));
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
}
|
|
|
|
this->BaseT::copyFrom(other);
|
|
|
|
}
|
|
|
|
|
|
|
|
void init(unsigned InitBuckets) {
|
|
|
|
Small = true;
|
|
|
|
if (InitBuckets > InlineBuckets) {
|
|
|
|
Small = false;
|
|
|
|
new (getLargeRep()) LargeRep(allocateBuckets(InitBuckets));
|
|
|
|
}
|
|
|
|
this->BaseT::initEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
void grow(unsigned AtLeast) {
|
2012-10-24 18:50:44 +00:00
|
|
|
if (AtLeast >= InlineBuckets)
|
|
|
|
AtLeast = std::max<unsigned>(64, NextPowerOf2(AtLeast-1));
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
|
|
|
|
if (Small) {
|
2012-10-23 18:47:35 +00:00
|
|
|
if (AtLeast < InlineBuckets)
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
return; // Nothing to do.
|
|
|
|
|
2012-06-17 10:33:51 +00:00
|
|
|
// First move the inline buckets into a temporary storage.
|
2012-08-17 01:47:25 +00:00
|
|
|
AlignedCharArrayUnion<BucketT[InlineBuckets]> TmpStorage;
|
2012-06-17 10:33:51 +00:00
|
|
|
BucketT *TmpBegin = reinterpret_cast<BucketT *>(TmpStorage.buffer);
|
|
|
|
BucketT *TmpEnd = TmpBegin;
|
|
|
|
|
|
|
|
// Loop over the buckets, moving non-empty, non-tombstones into the
|
|
|
|
// temporary storage. Have the loop move the TmpEnd forward as it goes.
|
|
|
|
const KeyT EmptyKey = this->getEmptyKey();
|
|
|
|
const KeyT TombstoneKey = this->getTombstoneKey();
|
|
|
|
for (BucketT *P = getBuckets(), *E = P + InlineBuckets; P != E; ++P) {
|
|
|
|
if (!KeyInfoT::isEqual(P->first, EmptyKey) &&
|
|
|
|
!KeyInfoT::isEqual(P->first, TombstoneKey)) {
|
2012-06-30 10:02:08 +00:00
|
|
|
assert(size_t(TmpEnd - TmpBegin) < InlineBuckets &&
|
2012-06-17 10:33:51 +00:00
|
|
|
"Too many inline buckets!");
|
2014-03-02 04:08:41 +00:00
|
|
|
new (&TmpEnd->first) KeyT(std::move(P->first));
|
|
|
|
new (&TmpEnd->second) ValueT(std::move(P->second));
|
2012-06-17 10:33:51 +00:00
|
|
|
++TmpEnd;
|
|
|
|
P->second.~ValueT();
|
|
|
|
}
|
|
|
|
P->first.~KeyT();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now make this map use the large rep, and move all the entries back
|
|
|
|
// into it.
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
Small = false;
|
2012-06-17 10:33:51 +00:00
|
|
|
new (getLargeRep()) LargeRep(allocateBuckets(AtLeast));
|
|
|
|
this->moveFromOldBuckets(TmpBegin, TmpEnd);
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-02 04:08:41 +00:00
|
|
|
LargeRep OldRep = std::move(*getLargeRep());
|
Introduce a SmallDenseMap container that re-uses the existing DenseMap
implementation.
This type includes an inline bucket array which is used initially. Once
it is exceeded, an array of 64 buckets is allocated on the heap. The
bucket count grows from there as needed. Some highlights of this
implementation:
- The inline buffer is very carefully aligned, and so supports types
with alignment constraints.
- It works hard to avoid aliasing issues.
- Supports types with non-trivial constructors, destructors, copy
constructions, etc. It works reasonably hard to minimize copies and
unnecessary initialization. The most common initialization is to set
keys to the empty key, and so that should be fast if at all possible.
This class has a performance / space trade-off. It tries to optimize for
relatively small maps, and so packs the inline bucket array densely into
the object. It will be marginally slower than a normal DenseMap in a few
use patterns, so it isn't appropriate everywhere.
The unit tests for DenseMap have been generalized a bit to support
running over different map implementations in addition to different
key/value types. They've then been automatically extended to cover the
new container through the magic of GoogleTest's typed tests.
All of this is still a bit rough though. I'm going to be cleaning up
some aspects of the implementation, documenting things better, and
adding tests which include non-trivial types. As soon as I'm comfortable
with the correctness, I plan to switch existing users of SmallMap over
to this class as it is already more correct w.r.t. construction and
destruction of objects iin the map.
Thanks to Benjamin Kramer for all the reviews of this and the lead-up
patches. That said, more review on this would really be appreciated. As
I've noted a few times, I'm quite surprised how hard it is to get the
semantics for a hashtable-based map container with a small buffer
optimization correct. =]
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158638 91177308-0d34-0410-b5e6-96231b3b80d8
2012-06-17 09:05:09 +00:00
|
|
|
getLargeRep()->~LargeRep();
|
|
|
|
if (AtLeast <= InlineBuckets) {
|
|
|
|
Small = true;
|
|
|
|
} else {
|
|
|
|
new (getLargeRep()) LargeRep(allocateBuckets(AtLeast));
|
|
|
|
}
|
|
|
|
|
|
|
|
this->moveFromOldBuckets(OldRep.Buckets, OldRep.Buckets+OldRep.NumBuckets);
|
|
|
|
|
|
|
|
// Free the old table.
|
|
|
|
operator delete(OldRep.Buckets);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shrink_and_clear() {
|
|
|
|
unsigned OldSize = this->size();
|
|
|
|
this->destroyAll();
|
|
|
|
|
|
|
|
// Reduce the number of buckets.
|
|
|
|
unsigned NewNumBuckets = 0;
|
|
|
|
if (OldSize) {
|
|
|
|
NewNumBuckets = 1 << (Log2_32_Ceil(OldSize) + 1);
|
|
|
|
if (NewNumBuckets > InlineBuckets && NewNumBuckets < 64u)
|
|
|
|
NewNumBuckets = 64;
|
|
|
|
}
|
|
|
|
if ((Small && NewNumBuckets <= InlineBuckets) ||
|
|
|
|
(!Small && NewNumBuckets == getLargeRep()->NumBuckets)) {
|
|
|
|
this->BaseT::initEmpty();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
deallocateBuckets();
|
|
|
|
init(NewNumBuckets);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned getNumEntries() const {
|
|
|
|
return NumEntries;
|
|
|
|
}
|
|
|
|
void setNumEntries(unsigned Num) {
|
|
|
|
assert(Num < INT_MAX && "Cannot support more than INT_MAX entries");
|
|
|
|
NumEntries = Num;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumTombstones() const {
|
|
|
|
return NumTombstones;
|
|
|
|
}
|
|
|
|
void setNumTombstones(unsigned Num) {
|
|
|
|
NumTombstones = Num;
|
|
|
|
}
|
|
|
|
|
|
|
|
const BucketT *getInlineBuckets() const {
|
|
|
|
assert(Small);
|
|
|
|
// Note that this cast does not violate aliasing rules as we assert that
|
|
|
|
// the memory's dynamic type is the small, inline bucket buffer, and the
|
|
|
|
// 'storage.buffer' static type is 'char *'.
|
|
|
|
return reinterpret_cast<const BucketT *>(storage.buffer);
|
|
|
|
}
|
|
|
|
BucketT *getInlineBuckets() {
|
|
|
|
return const_cast<BucketT *>(
|
|
|
|
const_cast<const SmallDenseMap *>(this)->getInlineBuckets());
|
|
|
|
}
|
|
|
|
const LargeRep *getLargeRep() const {
|
|
|
|
assert(!Small);
|
|
|
|
// Note, same rule about aliasing as with getInlineBuckets.
|
|
|
|
return reinterpret_cast<const LargeRep *>(storage.buffer);
|
|
|
|
}
|
|
|
|
LargeRep *getLargeRep() {
|
|
|
|
return const_cast<LargeRep *>(
|
|
|
|
const_cast<const SmallDenseMap *>(this)->getLargeRep());
|
|
|
|
}
|
|
|
|
|
|
|
|
const BucketT *getBuckets() const {
|
|
|
|
return Small ? getInlineBuckets() : getLargeRep()->Buckets;
|
|
|
|
}
|
|
|
|
BucketT *getBuckets() {
|
|
|
|
return const_cast<BucketT *>(
|
|
|
|
const_cast<const SmallDenseMap *>(this)->getBuckets());
|
|
|
|
}
|
|
|
|
unsigned getNumBuckets() const {
|
|
|
|
return Small ? InlineBuckets : getLargeRep()->NumBuckets;
|
|
|
|
}
|
|
|
|
|
|
|
|
void deallocateBuckets() {
|
|
|
|
if (Small)
|
|
|
|
return;
|
|
|
|
|
|
|
|
operator delete(getLargeRep()->Buckets);
|
|
|
|
getLargeRep()->~LargeRep();
|
|
|
|
}
|
|
|
|
|
|
|
|
LargeRep allocateBuckets(unsigned Num) {
|
|
|
|
assert(Num > InlineBuckets && "Must allocate more buckets than are inline");
|
|
|
|
LargeRep Rep = {
|
|
|
|
static_cast<BucketT*>(operator new(sizeof(BucketT) * Num)), Num
|
|
|
|
};
|
|
|
|
return Rep;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-11-10 01:02:17 +00:00
|
|
|
template<typename KeyT, typename ValueT,
|
2012-04-06 10:43:44 +00:00
|
|
|
typename KeyInfoT, bool IsConst>
|
2009-11-10 01:02:17 +00:00
|
|
|
class DenseMapIterator {
|
|
|
|
typedef std::pair<KeyT, ValueT> Bucket;
|
|
|
|
typedef DenseMapIterator<KeyT, ValueT,
|
2012-04-06 10:43:44 +00:00
|
|
|
KeyInfoT, true> ConstIterator;
|
|
|
|
friend class DenseMapIterator<KeyT, ValueT, KeyInfoT, true>;
|
2009-11-10 01:02:17 +00:00
|
|
|
public:
|
|
|
|
typedef ptrdiff_t difference_type;
|
2014-03-07 14:42:25 +00:00
|
|
|
typedef typename std::conditional<IsConst, const Bucket, Bucket>::type
|
|
|
|
value_type;
|
2009-11-10 01:02:17 +00:00
|
|
|
typedef value_type *pointer;
|
|
|
|
typedef value_type &reference;
|
|
|
|
typedef std::forward_iterator_tag iterator_category;
|
|
|
|
private:
|
|
|
|
pointer Ptr, End;
|
2007-02-02 19:27:13 +00:00
|
|
|
public:
|
2014-04-09 06:08:46 +00:00
|
|
|
DenseMapIterator() : Ptr(nullptr), End(nullptr) {}
|
2008-10-27 18:15:15 +00:00
|
|
|
|
2012-01-07 13:12:07 +00:00
|
|
|
DenseMapIterator(pointer Pos, pointer E, bool NoAdvance = false)
|
|
|
|
: Ptr(Pos), End(E) {
|
|
|
|
if (!NoAdvance) AdvancePastEmptyBuckets();
|
2007-02-02 19:27:13 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2009-11-10 01:02:17 +00:00
|
|
|
// If IsConst is true this is a converting constructor from iterator to
|
|
|
|
// const_iterator and the default copy constructor is used.
|
|
|
|
// Otherwise this is a copy constructor for iterator.
|
|
|
|
DenseMapIterator(const DenseMapIterator<KeyT, ValueT,
|
2012-04-06 10:43:44 +00:00
|
|
|
KeyInfoT, false>& I)
|
2009-11-10 01:02:17 +00:00
|
|
|
: Ptr(I.Ptr), End(I.End) {}
|
|
|
|
|
|
|
|
reference operator*() const {
|
|
|
|
return *Ptr;
|
2007-02-02 19:27:13 +00:00
|
|
|
}
|
2009-11-10 01:02:17 +00:00
|
|
|
pointer operator->() const {
|
|
|
|
return Ptr;
|
2007-02-02 19:27:13 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2009-11-10 01:02:17 +00:00
|
|
|
bool operator==(const ConstIterator &RHS) const {
|
|
|
|
return Ptr == RHS.operator->();
|
2007-02-02 19:27:13 +00:00
|
|
|
}
|
2009-11-10 01:02:17 +00:00
|
|
|
bool operator!=(const ConstIterator &RHS) const {
|
|
|
|
return Ptr != RHS.operator->();
|
2007-02-02 19:27:13 +00:00
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2009-10-23 20:54:00 +00:00
|
|
|
inline DenseMapIterator& operator++() { // Preincrement
|
2007-02-02 19:27:13 +00:00
|
|
|
++Ptr;
|
|
|
|
AdvancePastEmptyBuckets();
|
|
|
|
return *this;
|
|
|
|
}
|
2009-10-23 20:54:00 +00:00
|
|
|
DenseMapIterator operator++(int) { // Postincrement
|
2007-02-02 19:27:13 +00:00
|
|
|
DenseMapIterator tmp = *this; ++*this; return tmp;
|
|
|
|
}
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2007-02-02 19:27:13 +00:00
|
|
|
private:
|
|
|
|
void AdvancePastEmptyBuckets() {
|
2007-02-10 06:34:58 +00:00
|
|
|
const KeyT Empty = KeyInfoT::getEmptyKey();
|
|
|
|
const KeyT Tombstone = KeyInfoT::getTombstoneKey();
|
2007-02-02 19:27:13 +00:00
|
|
|
|
2009-01-09 19:25:42 +00:00
|
|
|
while (Ptr != End &&
|
2007-09-17 18:34:04 +00:00
|
|
|
(KeyInfoT::isEqual(Ptr->first, Empty) ||
|
|
|
|
KeyInfoT::isEqual(Ptr->first, Tombstone)))
|
2007-02-02 19:27:13 +00:00
|
|
|
++Ptr;
|
|
|
|
}
|
|
|
|
};
|
2013-01-05 05:16:53 +00:00
|
|
|
|
2012-04-06 10:43:44 +00:00
|
|
|
template<typename KeyT, typename ValueT, typename KeyInfoT>
|
2011-07-27 18:40:45 +00:00
|
|
|
static inline size_t
|
2012-04-06 10:43:44 +00:00
|
|
|
capacity_in_bytes(const DenseMap<KeyT, ValueT, KeyInfoT> &X) {
|
2011-07-27 18:40:45 +00:00
|
|
|
return X.getMemorySize();
|
|
|
|
}
|
2007-02-02 19:27:13 +00:00
|
|
|
|
2007-02-01 07:49:59 +00:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif
|