OnDiskHashTable.h 21 KB

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