#ifndef LLVM_ADT_DENSEMAP_H
#define LLVM_ADT_DENSEMAP_H
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/EpochTracker.h"
#include "llvm/Support/AlignOf.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemAlloc.h"
#include "llvm/Support/ReverseIteration.h"
#include "llvm/Support/type_traits.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstring>
#include <initializer_list>
#include <iterator>
#include <new>
#include <type_traits>
#include <utility>
namespace llvm {
namespace detail {
template <typename KeyT, typename ValueT>
struct DenseMapPair : public std::pair<KeyT, ValueT> { … };
}
template <typename KeyT, typename ValueT,
typename KeyInfoT = DenseMapInfo<KeyT>,
typename Bucket = llvm::detail::DenseMapPair<KeyT, ValueT>,
bool IsConst = false>
class DenseMapIterator;
template <typename DerivedT, typename KeyT, typename ValueT, typename KeyInfoT,
typename BucketT>
class DenseMapBase : public DebugEpochBase { … };
template <typename DerivedT, typename KeyT, typename ValueT, typename KeyInfoT,
typename BucketT>
bool operator==(
const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &LHS,
const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &RHS) { … }
template <typename DerivedT, typename KeyT, typename ValueT, typename KeyInfoT,
typename BucketT>
bool operator!=(
const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &LHS,
const DenseMapBase<DerivedT, KeyT, ValueT, KeyInfoT, BucketT> &RHS) { … }
template <typename KeyT, typename ValueT,
typename KeyInfoT = DenseMapInfo<KeyT>,
typename BucketT = llvm::detail::DenseMapPair<KeyT, ValueT>>
class DenseMap : public DenseMapBase<DenseMap<KeyT, ValueT, KeyInfoT, BucketT>,
KeyT, ValueT, KeyInfoT, BucketT> {
friend class DenseMapBase<DenseMap, KeyT, ValueT, KeyInfoT, BucketT>;
using BaseT = DenseMapBase<DenseMap, KeyT, ValueT, KeyInfoT, BucketT>;
BucketT *Buckets;
unsigned NumEntries;
unsigned NumTombstones;
unsigned NumBuckets;
public:
explicit DenseMap(unsigned InitialReserve = 0) { … }
DenseMap(const DenseMap &other) : … { … }
DenseMap(DenseMap &&other) : … { … }
template <typename InputIt> DenseMap(const InputIt &I, const InputIt &E) { … }
DenseMap(std::initializer_list<typename BaseT::value_type> Vals) { … }
~DenseMap() { … }
void swap(DenseMap &RHS) { … }
DenseMap &operator=(const DenseMap &other) { … }
DenseMap &operator=(DenseMap &&other) { … }
void copyFrom(const DenseMap &other) { … }
void init(unsigned InitNumEntries) { … }
void grow(unsigned AtLeast) { … }
void shrink_and_clear() { … }
private:
unsigned getNumEntries() const { … }
void setNumEntries(unsigned Num) { … }
unsigned getNumTombstones() const { … }
void setNumTombstones(unsigned Num) { … }
BucketT *getBuckets() const { … }
unsigned getNumBuckets() const { … }
bool allocateBuckets(unsigned Num) { … }
};
template <typename KeyT, typename ValueT, unsigned InlineBuckets = 4,
typename KeyInfoT = DenseMapInfo<KeyT>,
typename BucketT = llvm::detail::DenseMapPair<KeyT, ValueT>>
class SmallDenseMap
: public DenseMapBase<
SmallDenseMap<KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT>, KeyT,
ValueT, KeyInfoT, BucketT> {
friend class DenseMapBase<SmallDenseMap, KeyT, ValueT, KeyInfoT, BucketT>;
using BaseT = DenseMapBase<SmallDenseMap, KeyT, ValueT, KeyInfoT, BucketT>;
static_assert(isPowerOf2_64(InlineBuckets),
"InlineBuckets must be a power of 2.");
unsigned Small : 1;
unsigned NumEntries : 31;
unsigned NumTombstones;
struct LargeRep {
BucketT *Buckets;
unsigned NumBuckets;
};
AlignedCharArrayUnion<BucketT[InlineBuckets], LargeRep> storage;
public:
explicit SmallDenseMap(unsigned NumInitBuckets = 0) { … }
SmallDenseMap(const SmallDenseMap &other) : … { … }
SmallDenseMap(SmallDenseMap &&other) : … { … }
template <typename InputIt>
SmallDenseMap(const InputIt &I, const InputIt &E) { … }
SmallDenseMap(std::initializer_list<typename BaseT::value_type> Vals)
: … { … }
~SmallDenseMap() { … }
void swap(SmallDenseMap &RHS) { … }
SmallDenseMap &operator=(const SmallDenseMap &other) { … }
SmallDenseMap &operator=(SmallDenseMap &&other) { … }
void copyFrom(const SmallDenseMap &other) { … }
void init(unsigned InitBuckets) { … }
void grow(unsigned AtLeast) { … }
void shrink_and_clear() { … }
private:
unsigned getNumEntries() const { … }
void setNumEntries(unsigned Num) { … }
unsigned getNumTombstones() const { … }
void setNumTombstones(unsigned Num) { … }
const BucketT *getInlineBuckets() const { … }
BucketT *getInlineBuckets() { … }
const LargeRep *getLargeRep() const { … }
LargeRep *getLargeRep() { … }
const BucketT *getBuckets() const { … }
BucketT *getBuckets() { … }
unsigned getNumBuckets() const { … }
void deallocateBuckets() { … }
LargeRep allocateBuckets(unsigned Num) { … }
};
template <typename KeyT, typename ValueT, typename KeyInfoT, typename Bucket,
bool IsConst>
class DenseMapIterator : DebugEpochBase::HandleBase { … };
template <typename KeyT, typename ValueT, typename KeyInfoT>
inline size_t capacity_in_bytes(const DenseMap<KeyT, ValueT, KeyInfoT> &X) { … }
}
#endif