/// static std::pair<offset_type, offset_type>
/// EmitKeyDataLength(raw_ostream &Out, key_type_ref Key, data_type_ref Data);
/// /// Write Key to Out. KeyLen is the length from EmitKeyDataLength.
-/// static void EmitKey(raw_ostream &Out, key_type_ref Key, unsigned KeyLen);
+/// static void EmitKey(raw_ostream &Out, key_type_ref Key,
+/// offset_type KeyLen);
/// /// Write Data to Out. DataLen is the length from EmitKeyDataLength.
/// static void EmitData(raw_ostream &Out, key_type_ref Key,
-/// data_type_ref Data, unsigned DataLen);
+/// data_type_ref Data, offset_type DataLen);
/// };
/// \endcode
template <typename Info> class OnDiskChainedHashTableGenerator {
- typedef typename Info::offset_type offset_type;
- offset_type NumBuckets;
- offset_type NumEntries;
- llvm::BumpPtrAllocator BA;
-
/// \brief A single item in the hash table.
class Item {
public:
Item(typename Info::key_type_ref Key, typename Info::data_type_ref Data,
Info &InfoObj)
- : Key(Key), Data(Data), Next(0), Hash(InfoObj.ComputeHash(Key)) {}
+ : Key(Key), Data(Data), Next(nullptr), Hash(InfoObj.ComputeHash(Key)) {}
};
+ typedef typename Info::offset_type offset_type;
+ offset_type NumBuckets;
+ offset_type NumEntries;
+ llvm::SpecificBumpPtrAllocator<Item> BA;
+
/// \brief A linked list of values in a particular hash bucket.
class Bucket {
public:
for (size_t I = 0; I < NumBuckets; ++I)
for (Item *E = Buckets[I].Head; E;) {
Item *N = E->Next;
- E->Next = 0;
+ E->Next = nullptr;
insert(NewBuckets, NewSize, E);
E = N;
}
++NumEntries;
if (4 * NumEntries >= 3 * NumBuckets)
resize(NumBuckets * 2);
- insert(Buckets, NumBuckets,
- new (BA.Allocate<Item>()) Item(Key, Data, InfoObj));
+ insert(Buckets, NumBuckets, new (BA.Allocate()) Item(Key, Data, InfoObj));
}
/// \brief Emit the table to Out, which must not be at offset 0.
/// /// Read the key from Buffer, given the KeyLen as reported from
/// /// ReadKeyDataLength.
/// const internal_key_type &ReadKey(const unsigned char *Buffer,
-/// unsigned KeyLen);
+/// offset_type KeyLen);
/// /// Read the data for Key from Buffer, given the DataLen as reported from
/// /// ReadKeyDataLength.
/// data_type ReadData(StringRef Key, const unsigned char *Buffer,
-/// unsigned DataLen);
+/// offset_type DataLen);
/// };
/// \endcode
template <typename Info> class OnDiskChainedHashTable {
class iterator {
internal_key_type Key;
const unsigned char *const Data;
- const unsigned Len;
+ const offset_type Len;
Info *InfoObj;
public:
- iterator() : Data(0), Len(0) {}
- iterator(const internal_key_type K, const unsigned char *D, unsigned L,
+ iterator() : Data(nullptr), Len(0) {}
+ iterator(const internal_key_type K, const unsigned char *D, offset_type L,
Info *InfoObj)
: Key(K), Data(D), Len(L), InfoObj(InfoObj) {}
: Ptr(Ptr), NumItemsInBucketLeft(0), NumEntriesLeft(NumEntries),
InfoObj(InfoObj) {}
key_iterator()
- : Ptr(0), NumItemsInBucketLeft(0), NumEntriesLeft(0), InfoObj(0) {}
+ : Ptr(nullptr), NumItemsInBucketLeft(0), NumEntriesLeft(0),
+ InfoObj(0) {}
friend bool operator==(const key_iterator &X, const key_iterator &Y) {
return X.NumEntriesLeft == Y.NumEntriesLeft;
: Ptr(Ptr), NumItemsInBucketLeft(0), NumEntriesLeft(NumEntries),
InfoObj(InfoObj) {}
data_iterator()
- : Ptr(0), NumItemsInBucketLeft(0), NumEntriesLeft(0), InfoObj(0) {}
+ : Ptr(nullptr), NumItemsInBucketLeft(0), NumEntriesLeft(0),
+ InfoObj(nullptr) {}
bool operator==(const data_iterator &X) const {
return X.NumEntriesLeft == NumEntriesLeft;