diff options
Diffstat (limited to 'include/llvm/Support/OnDiskHashTable.h')
| -rw-r--r-- | include/llvm/Support/OnDiskHashTable.h | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/include/llvm/Support/OnDiskHashTable.h b/include/llvm/Support/OnDiskHashTable.h index e9c28daf03b9..912e2700d1a0 100644 --- a/include/llvm/Support/OnDiskHashTable.h +++ b/include/llvm/Support/OnDiskHashTable.h @@ -8,7 +8,7 @@ //===----------------------------------------------------------------------===// /// /// \file -/// \brief Defines facilities for reading and writing on-disk hash tables. +/// Defines facilities for reading and writing on-disk hash tables. /// //===----------------------------------------------------------------------===// #ifndef LLVM_SUPPORT_ONDISKHASHTABLE_H @@ -25,7 +25,7 @@ namespace llvm { -/// \brief Generates an on disk hash table. +/// Generates an on disk hash table. /// /// This needs an \c Info that handles storing values into the hash table's /// payload and computes the hash for a given key. This should provide the @@ -57,7 +57,7 @@ namespace llvm { /// }; /// \endcode template <typename Info> class OnDiskChainedHashTableGenerator { - /// \brief A single item in the hash table. + /// A single item in the hash table. class Item { public: typename Info::key_type Key; @@ -75,7 +75,7 @@ template <typename Info> class OnDiskChainedHashTableGenerator { offset_type NumEntries; llvm::SpecificBumpPtrAllocator<Item> BA; - /// \brief A linked list of values in a particular hash bucket. + /// A linked list of values in a particular hash bucket. struct Bucket { offset_type Off; unsigned Length; @@ -85,7 +85,7 @@ template <typename Info> class OnDiskChainedHashTableGenerator { Bucket *Buckets; private: - /// \brief Insert an item into the appropriate hash bucket. + /// Insert an item into the appropriate hash bucket. void insert(Bucket *Buckets, size_t Size, Item *E) { Bucket &B = Buckets[E->Hash & (Size - 1)]; E->Next = B.Head; @@ -93,9 +93,10 @@ private: B.Head = E; } - /// \brief Resize the hash table, moving the old entries into the new buckets. + /// Resize the hash table, moving the old entries into the new buckets. void resize(size_t NewSize) { - Bucket *NewBuckets = (Bucket *)std::calloc(NewSize, sizeof(Bucket)); + Bucket *NewBuckets = static_cast<Bucket *>( + safe_calloc(NewSize, sizeof(Bucket))); // Populate NewBuckets with the old entries. for (size_t I = 0; I < NumBuckets; ++I) for (Item *E = Buckets[I].Head; E;) { @@ -111,14 +112,14 @@ private: } public: - /// \brief Insert an entry into the table. + /// Insert an entry into the table. void insert(typename Info::key_type_ref Key, typename Info::data_type_ref Data) { Info InfoObj; insert(Key, Data, InfoObj); } - /// \brief Insert an entry into the table. + /// Insert an entry into the table. /// /// Uses the provided Info instead of a stack allocated one. void insert(typename Info::key_type_ref Key, @@ -129,7 +130,7 @@ public: insert(Buckets, NumBuckets, new (BA.Allocate()) Item(Key, Data, InfoObj)); } - /// \brief Determine whether an entry has been inserted. + /// Determine whether an entry has been inserted. bool contains(typename Info::key_type_ref Key, Info &InfoObj) { unsigned Hash = InfoObj.ComputeHash(Key); for (Item *I = Buckets[Hash & (NumBuckets - 1)].Head; I; I = I->Next) @@ -138,18 +139,18 @@ public: return false; } - /// \brief Emit the table to Out, which must not be at offset 0. + /// Emit the table to Out, which must not be at offset 0. offset_type Emit(raw_ostream &Out) { Info InfoObj; return Emit(Out, InfoObj); } - /// \brief Emit the table to Out, which must not be at offset 0. + /// Emit the table to Out, which must not be at offset 0. /// /// Uses the provided Info instead of a stack allocated one. offset_type Emit(raw_ostream &Out, Info &InfoObj) { using namespace llvm::support; - endian::Writer<little> LE(Out); + endian::Writer LE(Out, little); // Now we're done adding entries, resize the bucket list if it's // significantly too large. (This only happens if the number of @@ -226,13 +227,13 @@ public: NumBuckets = 64; // Note that we do not need to run the constructors of the individual // Bucket objects since 'calloc' returns bytes that are all 0. - Buckets = (Bucket *)std::calloc(NumBuckets, sizeof(Bucket)); + Buckets = static_cast<Bucket *>(safe_calloc(NumBuckets, sizeof(Bucket))); } ~OnDiskChainedHashTableGenerator() { std::free(Buckets); } }; -/// \brief Provides lookup on an on disk hash table. +/// Provides lookup on an on disk hash table. /// /// This needs an \c Info that handles reading values from the hash table's /// payload and computes the hash for a given key. This should provide the @@ -338,14 +339,14 @@ public: bool operator!=(const iterator &X) const { return X.Data != Data; } }; - /// \brief Look up the stored data for a particular key. + /// Look up the stored data for a particular key. iterator find(const external_key_type &EKey, Info *InfoPtr = nullptr) { const internal_key_type &IKey = InfoObj.GetInternalKey(EKey); hash_value_type KeyHash = InfoObj.ComputeHash(IKey); return find_hashed(IKey, KeyHash, InfoPtr); } - /// \brief Look up the stored data for a particular key with a known hash. + /// Look up the stored data for a particular key with a known hash. iterator find_hashed(const internal_key_type &IKey, hash_value_type KeyHash, Info *InfoPtr = nullptr) { using namespace llvm::support; @@ -403,7 +404,7 @@ public: Info &getInfoObj() { return InfoObj; } - /// \brief Create the hash table. + /// Create the hash table. /// /// \param Buckets is the beginning of the hash table itself, which follows /// the payload of entire structure. This is the value returned by @@ -423,7 +424,7 @@ public: } }; -/// \brief Provides lookup and iteration over an on disk hash table. +/// Provides lookup and iteration over an on disk hash table. /// /// \copydetails llvm::OnDiskChainedHashTable template <typename Info> @@ -439,7 +440,7 @@ public: typedef typename base_type::offset_type offset_type; private: - /// \brief Iterates over all of the keys in the table. + /// Iterates over all of the keys in the table. class iterator_base { const unsigned char *Ptr; offset_type NumItemsInBucketLeft; @@ -496,7 +497,7 @@ public: : base_type(NumBuckets, NumEntries, Buckets, Base, InfoObj), Payload(Payload) {} - /// \brief Iterates over all of the keys in the table. + /// Iterates over all of the keys in the table. class key_iterator : public iterator_base { Info *InfoObj; @@ -542,7 +543,7 @@ public: return make_range(key_begin(), key_end()); } - /// \brief Iterates over all the entries in the table, returning the data. + /// Iterates over all the entries in the table, returning the data. class data_iterator : public iterator_base { Info *InfoObj; @@ -585,7 +586,7 @@ public: return make_range(data_begin(), data_end()); } - /// \brief Create the hash table. + /// Create the hash table. /// /// \param Buckets is the beginning of the hash table itself, which follows /// the payload of entire structure. This is the value returned by |
