From: Richard Smith Date: Mon, 31 Aug 2015 22:17:24 +0000 (+0000) Subject: Infrastructure changes for Clang r246497. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=faeb2028b0d6ea1676621f8ad660a85fb911a0e1;p=oota-llvm.git Infrastructure changes for Clang r246497. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@246498 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/OnDiskHashTable.h b/include/llvm/Support/OnDiskHashTable.h index cc40efc5c0c..48ec40ffbaf 100644 --- a/include/llvm/Support/OnDiskHashTable.h +++ b/include/llvm/Support/OnDiskHashTable.h @@ -53,6 +53,8 @@ namespace llvm { /// /// Write Data to Out. DataLen is the length from EmitKeyDataLength. /// static void EmitData(raw_ostream &Out, key_type_ref Key, /// data_type_ref Data, offset_type DataLen); +/// /// Determine if two keys are equal. Optional, only needed by contains. +/// static bool EqualKey(key_type_ref Key1, key_type_ref Key2); /// }; /// \endcode template class OnDiskChainedHashTableGenerator { @@ -122,13 +124,21 @@ public: /// Uses the provided Info instead of a stack allocated one. void insert(typename Info::key_type_ref Key, typename Info::data_type_ref Data, Info &InfoObj) { - ++NumEntries; if (4 * NumEntries >= 3 * NumBuckets) resize(NumBuckets * 2); insert(Buckets, NumBuckets, new (BA.Allocate()) Item(Key, Data, InfoObj)); } + /// \brief 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) + if (I->Hash == Hash && InfoObj.EqualKey(I->Key, Key)) + return true; + return false; + } + /// \brief Emit the table to Out, which must not be at offset 0. offset_type Emit(raw_ostream &Out) { Info InfoObj; @@ -290,6 +300,10 @@ public: : Key(K), Data(D), Len(L), InfoObj(InfoObj) {} data_type operator*() const { return InfoObj->ReadData(Key, Data, Len); } + + const unsigned char *getDataPtr() const { return Data; } + offset_type getDataLen() const { return Len; } + bool operator==(const iterator &X) const { return X.Data == Data; } bool operator!=(const iterator &X) const { return X.Data != Data; } };