OnDiskHashTable.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. //===--- OnDiskHashTable.h - On-Disk Hash Table Implementation --*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. ///
  10. /// \file
  11. /// \brief Defines facilities for reading and writing on-disk hash tables.
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_SUPPORT_ONDISKHASHTABLE_H
  15. #define LLVM_SUPPORT_ONDISKHASHTABLE_H
  16. #include "llvm/Support/AlignOf.h"
  17. #include "llvm/Support/Allocator.h"
  18. #include "llvm/Support/DataTypes.h"
  19. #include "llvm/Support/EndianStream.h"
  20. #include "llvm/Support/Host.h"
  21. #include "llvm/Support/MathExtras.h"
  22. #include "llvm/Support/raw_ostream.h"
  23. #include <cassert>
  24. #include <cstdlib>
  25. namespace llvm {
  26. /// \brief Generates an on disk hash table.
  27. ///
  28. /// This needs an \c Info that handles storing values into the hash table's
  29. /// payload and computes the hash for a given key. This should provide the
  30. /// following interface:
  31. ///
  32. /// \code
  33. /// class ExampleInfo {
  34. /// public:
  35. /// typedef ExampleKey key_type; // Must be copy constructible
  36. /// typedef ExampleKey &key_type_ref;
  37. /// typedef ExampleData data_type; // Must be copy constructible
  38. /// typedef ExampleData &data_type_ref;
  39. /// typedef uint32_t hash_value_type; // The type the hash function returns.
  40. /// typedef uint32_t offset_type; // The type for offsets into the table.
  41. ///
  42. /// /// Calculate the hash for Key
  43. /// static hash_value_type ComputeHash(key_type_ref Key);
  44. /// /// Return the lengths, in bytes, of the given Key/Data pair.
  45. /// static std::pair<offset_type, offset_type>
  46. /// EmitKeyDataLength(raw_ostream &Out, key_type_ref Key, data_type_ref Data);
  47. /// /// Write Key to Out. KeyLen is the length from EmitKeyDataLength.
  48. /// static void EmitKey(raw_ostream &Out, key_type_ref Key,
  49. /// offset_type KeyLen);
  50. /// /// Write Data to Out. DataLen is the length from EmitKeyDataLength.
  51. /// static void EmitData(raw_ostream &Out, key_type_ref Key,
  52. /// data_type_ref Data, offset_type DataLen);
  53. /// };
  54. /// \endcode
  55. template <typename Info> class OnDiskChainedHashTableGenerator {
  56. /// \brief A single item in the hash table.
  57. class Item {
  58. public:
  59. typename Info::key_type Key;
  60. typename Info::data_type Data;
  61. Item *Next;
  62. const typename Info::hash_value_type Hash;
  63. Item(typename Info::key_type_ref Key, typename Info::data_type_ref Data,
  64. Info &InfoObj)
  65. : Key(Key), Data(Data), Next(nullptr), Hash(InfoObj.ComputeHash(Key)) {}
  66. };
  67. typedef typename Info::offset_type offset_type;
  68. offset_type NumBuckets;
  69. offset_type NumEntries;
  70. llvm::SpecificBumpPtrAllocator<Item> BA;
  71. /// \brief A linked list of values in a particular hash bucket.
  72. struct Bucket {
  73. offset_type Off;
  74. unsigned Length;
  75. Item *Head;
  76. };
  77. Bucket *Buckets;
  78. private:
  79. /// \brief Insert an item into the appropriate hash bucket.
  80. void insert(Bucket *Buckets, size_t Size, Item *E) {
  81. Bucket &B = Buckets[E->Hash & (Size - 1)];
  82. E->Next = B.Head;
  83. ++B.Length;
  84. B.Head = E;
  85. }
  86. /// \brief Resize the hash table, moving the old entries into the new buckets.
  87. void resize(size_t NewSize) {
  88. Bucket *NewBuckets = (Bucket *)std::calloc(NewSize, sizeof(Bucket));
  89. if (NewBuckets == nullptr) throw std::bad_alloc(); // HLSL Change
  90. // Populate NewBuckets with the old entries.
  91. for (size_t I = 0; I < NumBuckets; ++I)
  92. for (Item *E = Buckets[I].Head; E;) {
  93. Item *N = E->Next;
  94. E->Next = nullptr;
  95. insert(NewBuckets, NewSize, E);
  96. E = N;
  97. }
  98. free(Buckets);
  99. NumBuckets = NewSize;
  100. Buckets = NewBuckets;
  101. }
  102. public:
  103. /// \brief Insert an entry into the table.
  104. void insert(typename Info::key_type_ref Key,
  105. typename Info::data_type_ref Data) {
  106. Info InfoObj;
  107. insert(Key, Data, InfoObj);
  108. }
  109. /// \brief Insert an entry into the table.
  110. ///
  111. /// Uses the provided Info instead of a stack allocated one.
  112. void insert(typename Info::key_type_ref Key,
  113. typename Info::data_type_ref Data, Info &InfoObj) {
  114. ++NumEntries;
  115. if (4 * NumEntries >= 3 * NumBuckets)
  116. resize(NumBuckets * 2);
  117. insert(Buckets, NumBuckets, new (BA.Allocate()) Item(Key, Data, InfoObj));
  118. }
  119. /// \brief Emit the table to Out, which must not be at offset 0.
  120. offset_type Emit(raw_ostream &Out) {
  121. Info InfoObj;
  122. return Emit(Out, InfoObj);
  123. }
  124. /// \brief Emit the table to Out, which must not be at offset 0.
  125. ///
  126. /// Uses the provided Info instead of a stack allocated one.
  127. offset_type Emit(raw_ostream &Out, Info &InfoObj) {
  128. using namespace llvm::support;
  129. endian::Writer<little> LE(Out);
  130. // Emit the payload of the table.
  131. for (offset_type I = 0; I < NumBuckets; ++I) {
  132. Bucket &B = Buckets[I];
  133. if (!B.Head)
  134. continue;
  135. // Store the offset for the data of this bucket.
  136. B.Off = Out.tell();
  137. assert(B.Off && "Cannot write a bucket at offset 0. Please add padding.");
  138. // Write out the number of items in the bucket.
  139. LE.write<uint16_t>(B.Length);
  140. assert(B.Length != 0 && "Bucket has a head but zero length?");
  141. // Write out the entries in the bucket.
  142. for (Item *I = B.Head; I; I = I->Next) {
  143. LE.write<typename Info::hash_value_type>(I->Hash);
  144. const std::pair<offset_type, offset_type> &Len =
  145. InfoObj.EmitKeyDataLength(Out, I->Key, I->Data);
  146. InfoObj.EmitKey(Out, I->Key, Len.first);
  147. InfoObj.EmitData(Out, I->Key, I->Data, Len.second);
  148. }
  149. }
  150. // Pad with zeros so that we can start the hashtable at an aligned address.
  151. offset_type TableOff = Out.tell();
  152. uint64_t N = llvm::OffsetToAlignment(TableOff, alignOf<offset_type>());
  153. TableOff += N;
  154. while (N--)
  155. LE.write<uint8_t>(0);
  156. // Emit the hashtable itself.
  157. LE.write<offset_type>(NumBuckets);
  158. LE.write<offset_type>(NumEntries);
  159. for (offset_type I = 0; I < NumBuckets; ++I)
  160. LE.write<offset_type>(Buckets[I].Off);
  161. return TableOff;
  162. }
  163. OnDiskChainedHashTableGenerator() {
  164. NumEntries = 0;
  165. NumBuckets = 64;
  166. // Note that we do not need to run the constructors of the individual
  167. // Bucket objects since 'calloc' returns bytes that are all 0.
  168. Buckets = (Bucket *)std::calloc(NumBuckets, sizeof(Bucket));
  169. if (Buckets == nullptr) throw std::bad_alloc(); // HLSL Change
  170. }
  171. ~OnDiskChainedHashTableGenerator() { std::free(Buckets); }
  172. };
  173. /// \brief Provides lookup on an on disk hash table.
  174. ///
  175. /// This needs an \c Info that handles reading values from the hash table's
  176. /// payload and computes the hash for a given key. This should provide the
  177. /// following interface:
  178. ///
  179. /// \code
  180. /// class ExampleLookupInfo {
  181. /// public:
  182. /// typedef ExampleData data_type;
  183. /// typedef ExampleInternalKey internal_key_type; // The stored key type.
  184. /// typedef ExampleKey external_key_type; // The type to pass to find().
  185. /// typedef uint32_t hash_value_type; // The type the hash function returns.
  186. /// typedef uint32_t offset_type; // The type for offsets into the table.
  187. ///
  188. /// /// Compare two keys for equality.
  189. /// static bool EqualKey(internal_key_type &Key1, internal_key_type &Key2);
  190. /// /// Calculate the hash for the given key.
  191. /// static hash_value_type ComputeHash(internal_key_type &IKey);
  192. /// /// Translate from the semantic type of a key in the hash table to the
  193. /// /// type that is actually stored and used for hashing and comparisons.
  194. /// /// The internal and external types are often the same, in which case this
  195. /// /// can simply return the passed in value.
  196. /// static const internal_key_type &GetInternalKey(external_key_type &EKey);
  197. /// /// Read the key and data length from Buffer, leaving it pointing at the
  198. /// /// following byte.
  199. /// static std::pair<offset_type, offset_type>
  200. /// ReadKeyDataLength(const unsigned char *&Buffer);
  201. /// /// Read the key from Buffer, given the KeyLen as reported from
  202. /// /// ReadKeyDataLength.
  203. /// const internal_key_type &ReadKey(const unsigned char *Buffer,
  204. /// offset_type KeyLen);
  205. /// /// Read the data for Key from Buffer, given the DataLen as reported from
  206. /// /// ReadKeyDataLength.
  207. /// data_type ReadData(StringRef Key, const unsigned char *Buffer,
  208. /// offset_type DataLen);
  209. /// };
  210. /// \endcode
  211. template <typename Info> class OnDiskChainedHashTable {
  212. const typename Info::offset_type NumBuckets;
  213. const typename Info::offset_type NumEntries;
  214. const unsigned char *const Buckets;
  215. const unsigned char *const Base;
  216. Info InfoObj;
  217. public:
  218. typedef typename Info::internal_key_type internal_key_type;
  219. typedef typename Info::external_key_type external_key_type;
  220. typedef typename Info::data_type data_type;
  221. typedef typename Info::hash_value_type hash_value_type;
  222. typedef typename Info::offset_type offset_type;
  223. OnDiskChainedHashTable(offset_type NumBuckets, offset_type NumEntries,
  224. const unsigned char *Buckets,
  225. const unsigned char *Base,
  226. const Info &InfoObj = Info())
  227. : NumBuckets(NumBuckets), NumEntries(NumEntries), Buckets(Buckets),
  228. Base(Base), InfoObj(InfoObj) {
  229. assert((reinterpret_cast<uintptr_t>(Buckets) & 0x3) == 0 &&
  230. "'buckets' must have a 4-byte alignment");
  231. }
  232. offset_type getNumBuckets() const { return NumBuckets; }
  233. offset_type getNumEntries() const { return NumEntries; }
  234. const unsigned char *getBase() const { return Base; }
  235. const unsigned char *getBuckets() const { return Buckets; }
  236. bool isEmpty() const { return NumEntries == 0; }
  237. class iterator {
  238. internal_key_type Key;
  239. const unsigned char *const Data;
  240. const offset_type Len;
  241. Info *InfoObj;
  242. public:
  243. iterator() : Data(nullptr), Len(0) {}
  244. iterator(const internal_key_type K, const unsigned char *D, offset_type L,
  245. Info *InfoObj)
  246. : Key(K), Data(D), Len(L), InfoObj(InfoObj) {}
  247. data_type operator*() const { return InfoObj->ReadData(Key, Data, Len); }
  248. bool operator==(const iterator &X) const { return X.Data == Data; }
  249. bool operator!=(const iterator &X) const { return X.Data != Data; }
  250. };
  251. /// \brief Look up the stored data for a particular key.
  252. iterator find(const external_key_type &EKey, Info *InfoPtr = nullptr) {
  253. const internal_key_type &IKey = InfoObj.GetInternalKey(EKey);
  254. hash_value_type KeyHash = InfoObj.ComputeHash(IKey);
  255. return find_hashed(IKey, KeyHash, InfoPtr);
  256. }
  257. /// \brief Look up the stored data for a particular key with a known hash.
  258. iterator find_hashed(const internal_key_type &IKey, hash_value_type KeyHash,
  259. Info *InfoPtr = nullptr) {
  260. using namespace llvm::support;
  261. if (!InfoPtr)
  262. InfoPtr = &InfoObj;
  263. // Each bucket is just an offset into the hash table file.
  264. offset_type Idx = KeyHash & (NumBuckets - 1);
  265. const unsigned char *Bucket = Buckets + sizeof(offset_type) * Idx;
  266. offset_type Offset = endian::readNext<offset_type, little, aligned>(Bucket);
  267. if (Offset == 0)
  268. return iterator(); // Empty bucket.
  269. const unsigned char *Items = Base + Offset;
  270. // 'Items' starts with a 16-bit unsigned integer representing the
  271. // number of items in this bucket.
  272. unsigned Len = endian::readNext<uint16_t, little, unaligned>(Items);
  273. for (unsigned i = 0; i < Len; ++i) {
  274. // Read the hash.
  275. hash_value_type ItemHash =
  276. endian::readNext<hash_value_type, little, unaligned>(Items);
  277. // Determine the length of the key and the data.
  278. const std::pair<offset_type, offset_type> &L =
  279. Info::ReadKeyDataLength(Items);
  280. offset_type ItemLen = L.first + L.second;
  281. // Compare the hashes. If they are not the same, skip the entry entirely.
  282. if (ItemHash != KeyHash) {
  283. Items += ItemLen;
  284. continue;
  285. }
  286. // Read the key.
  287. const internal_key_type &X =
  288. InfoPtr->ReadKey((const unsigned char *const)Items, L.first);
  289. // If the key doesn't match just skip reading the value.
  290. if (!InfoPtr->EqualKey(X, IKey)) {
  291. Items += ItemLen;
  292. continue;
  293. }
  294. // The key matches!
  295. return iterator(X, Items + L.first, L.second, InfoPtr);
  296. }
  297. return iterator();
  298. }
  299. iterator end() const { return iterator(); }
  300. Info &getInfoObj() { return InfoObj; }
  301. /// \brief Create the hash table.
  302. ///
  303. /// \param Buckets is the beginning of the hash table itself, which follows
  304. /// the payload of entire structure. This is the value returned by
  305. /// OnDiskHashTableGenerator::Emit.
  306. ///
  307. /// \param Base is the point from which all offsets into the structure are
  308. /// based. This is offset 0 in the stream that was used when Emitting the
  309. /// table.
  310. static OnDiskChainedHashTable *Create(const unsigned char *Buckets,
  311. const unsigned char *const Base,
  312. const Info &InfoObj = Info()) {
  313. using namespace llvm::support;
  314. assert(Buckets > Base);
  315. assert((reinterpret_cast<uintptr_t>(Buckets) & 0x3) == 0 &&
  316. "buckets should be 4-byte aligned.");
  317. offset_type NumBuckets =
  318. endian::readNext<offset_type, little, aligned>(Buckets);
  319. offset_type NumEntries =
  320. endian::readNext<offset_type, little, aligned>(Buckets);
  321. return new OnDiskChainedHashTable<Info>(NumBuckets, NumEntries, Buckets,
  322. Base, InfoObj);
  323. }
  324. };
  325. /// \brief Provides lookup and iteration over an on disk hash table.
  326. ///
  327. /// \copydetails llvm::OnDiskChainedHashTable
  328. template <typename Info>
  329. class OnDiskIterableChainedHashTable : public OnDiskChainedHashTable<Info> {
  330. const unsigned char *Payload;
  331. public:
  332. typedef OnDiskChainedHashTable<Info> base_type;
  333. typedef typename base_type::internal_key_type internal_key_type;
  334. typedef typename base_type::external_key_type external_key_type;
  335. typedef typename base_type::data_type data_type;
  336. typedef typename base_type::hash_value_type hash_value_type;
  337. typedef typename base_type::offset_type offset_type;
  338. OnDiskIterableChainedHashTable(offset_type NumBuckets, offset_type NumEntries,
  339. const unsigned char *Buckets,
  340. const unsigned char *Payload,
  341. const unsigned char *Base,
  342. const Info &InfoObj = Info())
  343. : base_type(NumBuckets, NumEntries, Buckets, Base, InfoObj),
  344. Payload(Payload) {}
  345. /// \brief Iterates over all of the keys in the table.
  346. class key_iterator {
  347. const unsigned char *Ptr;
  348. offset_type NumItemsInBucketLeft;
  349. offset_type NumEntriesLeft;
  350. Info *InfoObj;
  351. public:
  352. typedef external_key_type value_type;
  353. key_iterator(const unsigned char *const Ptr, offset_type NumEntries,
  354. Info *InfoObj)
  355. : Ptr(Ptr), NumItemsInBucketLeft(0), NumEntriesLeft(NumEntries),
  356. InfoObj(InfoObj) {}
  357. key_iterator()
  358. : Ptr(nullptr), NumItemsInBucketLeft(0), NumEntriesLeft(0),
  359. InfoObj(0) {}
  360. friend bool operator==(const key_iterator &X, const key_iterator &Y) {
  361. return X.NumEntriesLeft == Y.NumEntriesLeft;
  362. }
  363. friend bool operator!=(const key_iterator &X, const key_iterator &Y) {
  364. return X.NumEntriesLeft != Y.NumEntriesLeft;
  365. }
  366. key_iterator &operator++() { // Preincrement
  367. using namespace llvm::support;
  368. if (!NumItemsInBucketLeft) {
  369. // 'Items' starts with a 16-bit unsigned integer representing the
  370. // number of items in this bucket.
  371. NumItemsInBucketLeft =
  372. endian::readNext<uint16_t, little, unaligned>(Ptr);
  373. }
  374. Ptr += sizeof(hash_value_type); // Skip the hash.
  375. // Determine the length of the key and the data.
  376. const std::pair<offset_type, offset_type> &L =
  377. Info::ReadKeyDataLength(Ptr);
  378. Ptr += L.first + L.second;
  379. assert(NumItemsInBucketLeft);
  380. --NumItemsInBucketLeft;
  381. assert(NumEntriesLeft);
  382. --NumEntriesLeft;
  383. return *this;
  384. }
  385. key_iterator operator++(int) { // Postincrement
  386. key_iterator tmp = *this; ++*this; return tmp;
  387. }
  388. value_type operator*() const {
  389. const unsigned char *LocalPtr = Ptr;
  390. if (!NumItemsInBucketLeft)
  391. LocalPtr += 2; // number of items in bucket
  392. LocalPtr += sizeof(hash_value_type); // Skip the hash.
  393. // Determine the length of the key and the data.
  394. const std::pair<offset_type, offset_type> &L =
  395. Info::ReadKeyDataLength(LocalPtr);
  396. // Read the key.
  397. const internal_key_type &Key = InfoObj->ReadKey(LocalPtr, L.first);
  398. return InfoObj->GetExternalKey(Key);
  399. }
  400. };
  401. key_iterator key_begin() {
  402. return key_iterator(Payload, this->getNumEntries(), &this->getInfoObj());
  403. }
  404. key_iterator key_end() { return key_iterator(); }
  405. iterator_range<key_iterator> keys() {
  406. return make_range(key_begin(), key_end());
  407. }
  408. /// \brief Iterates over all the entries in the table, returning the data.
  409. class data_iterator {
  410. const unsigned char *Ptr;
  411. offset_type NumItemsInBucketLeft;
  412. offset_type NumEntriesLeft;
  413. Info *InfoObj;
  414. public:
  415. typedef data_type value_type;
  416. data_iterator(const unsigned char *const Ptr, offset_type NumEntries,
  417. Info *InfoObj)
  418. : Ptr(Ptr), NumItemsInBucketLeft(0), NumEntriesLeft(NumEntries),
  419. InfoObj(InfoObj) {}
  420. data_iterator()
  421. : Ptr(nullptr), NumItemsInBucketLeft(0), NumEntriesLeft(0),
  422. InfoObj(nullptr) {}
  423. bool operator==(const data_iterator &X) const {
  424. return X.NumEntriesLeft == NumEntriesLeft;
  425. }
  426. bool operator!=(const data_iterator &X) const {
  427. return X.NumEntriesLeft != NumEntriesLeft;
  428. }
  429. data_iterator &operator++() { // Preincrement
  430. using namespace llvm::support;
  431. if (!NumItemsInBucketLeft) {
  432. // 'Items' starts with a 16-bit unsigned integer representing the
  433. // number of items in this bucket.
  434. NumItemsInBucketLeft =
  435. endian::readNext<uint16_t, little, unaligned>(Ptr);
  436. }
  437. Ptr += sizeof(hash_value_type); // Skip the hash.
  438. // Determine the length of the key and the data.
  439. const std::pair<offset_type, offset_type> &L =
  440. Info::ReadKeyDataLength(Ptr);
  441. Ptr += L.first + L.second;
  442. assert(NumItemsInBucketLeft);
  443. --NumItemsInBucketLeft;
  444. assert(NumEntriesLeft);
  445. --NumEntriesLeft;
  446. return *this;
  447. }
  448. data_iterator operator++(int) { // Postincrement
  449. data_iterator tmp = *this; ++*this; return tmp;
  450. }
  451. value_type operator*() const {
  452. const unsigned char *LocalPtr = Ptr;
  453. if (!NumItemsInBucketLeft)
  454. LocalPtr += 2; // number of items in bucket
  455. LocalPtr += sizeof(hash_value_type); // Skip the hash.
  456. // Determine the length of the key and the data.
  457. const std::pair<offset_type, offset_type> &L =
  458. Info::ReadKeyDataLength(LocalPtr);
  459. // Read the key.
  460. const internal_key_type &Key = InfoObj->ReadKey(LocalPtr, L.first);
  461. return InfoObj->ReadData(Key, LocalPtr + L.first, L.second);
  462. }
  463. };
  464. data_iterator data_begin() {
  465. return data_iterator(Payload, this->getNumEntries(), &this->getInfoObj());
  466. }
  467. data_iterator data_end() { return data_iterator(); }
  468. iterator_range<data_iterator> data() {
  469. return make_range(data_begin(), data_end());
  470. }
  471. /// \brief Create the hash table.
  472. ///
  473. /// \param Buckets is the beginning of the hash table itself, which follows
  474. /// the payload of entire structure. This is the value returned by
  475. /// OnDiskHashTableGenerator::Emit.
  476. ///
  477. /// \param Payload is the beginning of the data contained in the table. This
  478. /// is Base plus any padding or header data that was stored, ie, the offset
  479. /// that the stream was at when calling Emit.
  480. ///
  481. /// \param Base is the point from which all offsets into the structure are
  482. /// based. This is offset 0 in the stream that was used when Emitting the
  483. /// table.
  484. static OnDiskIterableChainedHashTable *
  485. Create(const unsigned char *Buckets, const unsigned char *const Payload,
  486. const unsigned char *const Base, const Info &InfoObj = Info()) {
  487. using namespace llvm::support;
  488. assert(Buckets > Base);
  489. assert((reinterpret_cast<uintptr_t>(Buckets) & 0x3) == 0 &&
  490. "buckets should be 4-byte aligned.");
  491. offset_type NumBuckets =
  492. endian::readNext<offset_type, little, aligned>(Buckets);
  493. offset_type NumEntries =
  494. endian::readNext<offset_type, little, aligned>(Buckets);
  495. return new OnDiskIterableChainedHashTable<Info>(
  496. NumBuckets, NumEntries, Buckets, Payload, Base, InfoObj);
  497. }
  498. };
  499. } // end namespace llvm
  500. #endif