[ARMTargetParser] Adding a few more CPUs for Clang CPU detection. NFC.
[oota-llvm.git] / include / llvm / Support / OnDiskHashTable.h
index 289f7922f2a6090d566fbe1119681c26c56fca5e..0f097f28728640ceaa4c170a52dd721c0f361d94 100644 (file)
 /// \brief Defines facilities for reading and writing on-disk hash tables.
 ///
 //===----------------------------------------------------------------------===//
-#ifndef LLVM_SUPPORT_ON_DISK_HASH_TABLE_H
-#define LLVM_SUPPORT_ON_DISK_HASH_TABLE_H
+#ifndef LLVM_SUPPORT_ONDISKHASHTABLE_H
+#define LLVM_SUPPORT_ONDISKHASHTABLE_H
 
-#include "llvm/Support/Allocator.h"
 #include "llvm/Support/AlignOf.h"
+#include "llvm/Support/Allocator.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/EndianStream.h"
 #include "llvm/Support/Host.h"
@@ -48,18 +48,14 @@ namespace llvm {
 ///   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:
@@ -70,17 +66,19 @@ template <typename Info> class OnDiskChainedHashTableGenerator {
 
     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:
+  struct Bucket {
     offset_type Off;
-    Item *Head;
     unsigned Length;
-
-    Bucket() {}
+    Item *Head;
   };
 
   Bucket *Buckets;
@@ -101,7 +99,7 @@ private:
     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;
       }
@@ -128,8 +126,7 @@ public:
     ++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.
@@ -227,11 +224,11 @@ public:
 ///   /// 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 {
@@ -268,12 +265,12 @@ public:
   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) {}
 
@@ -405,7 +402,8 @@ public:
         : 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;
@@ -477,7 +475,8 @@ public:
         : 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;
@@ -566,4 +565,4 @@ public:
 
 } // end namespace llvm
 
-#endif // LLVM_SUPPORT_ON_DISK_HASH_TABLE_H
+#endif