<div dir="ltr"><div dir="ltr">Oops, thanks! This one always gets me.<div>I couldn't think of a good name either, but here qualifying the type (dex::Corpus) should work.</div><div>Re-landed as r343622</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 2, 2018 at 7:34 PM Reid Kleckner <<a href="mailto:rnk@google.com">rnk@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr">I reverted this in r343610 because I noticed many bots were failing to build after this change. Declaring the field `Corpus Corpus;` upsets GCC. I considered trying to pick a different field name, but I wasn't able to come up with one I liked, so I'm punting it back to you. =/</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Oct 2, 2018 at 6:46 AM Sam McCall via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: sammccall<br>
Date: Tue Oct 2 06:44:26 2018<br>
New Revision: 343589<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=343589&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=343589&view=rev</a><br>
Log:<br>
[clangd] Dex: add Corpus factory for iterators, rename, fold constant. NFC<br>
<br>
Summary:<br>
- Corpus avoids having to pass size to the true iterator, and (soon) any<br>
iterator that might optimize down to true.<br>
- Shorten names of factory functions now they're scoped to the Corpus.<br>
intersect() and unionOf() rather than createAnd() or createOr() as this<br>
seems to read better to me, and fits with other short names. Opinion wanted!<br>
- DEFAULT_BOOST_SCORE --> 1. This is a multiplier, don't obfuscate identity.<br>
- Simplify variadic templates in Iterator.h<br>
<br>
Reviewers: ioeric<br>
<br>
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D52711" rel="noreferrer" target="_blank">https://reviews.llvm.org/D52711</a><br>
<br>
Modified:<br>
clang-tools-extra/trunk/clangd/index/dex/Dex.cpp<br>
clang-tools-extra/trunk/clangd/index/dex/Dex.h<br>
clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp<br>
clang-tools-extra/trunk/clangd/index/dex/Iterator.h<br>
clang-tools-extra/trunk/clangd/index/dex/PostingList.cpp<br>
clang-tools-extra/trunk/unittests/clangd/DexTests.cpp<br>
<br>
Modified: clang-tools-extra/trunk/clangd/index/dex/Dex.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.cpp?rev=343589&r1=343588&r2=343589&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.cpp?rev=343589&r1=343588&r2=343589&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clangd/index/dex/Dex.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd/index/dex/Dex.cpp Tue Oct 2 06:44:26 2018<br>
@@ -56,7 +56,8 @@ std::vector<Token> generateSearchTokens(<br>
std::vector<std::unique_ptr<Iterator>> createFileProximityIterators(<br>
llvm::ArrayRef<std::string> ProximityPaths,<br>
llvm::ArrayRef<std::string> URISchemes,<br>
- const llvm::DenseMap<Token, PostingList> &InvertedIndex) {<br>
+ const llvm::DenseMap<Token, PostingList> &InvertedIndex,<br>
+ const Corpus &Corpus) {<br>
std::vector<std::unique_ptr<Iterator>> BoostingIterators;<br>
// Deduplicate parent URIs extracted from the ProximityPaths.<br>
llvm::StringSet<> ParentURIs;<br>
@@ -91,8 +92,8 @@ std::vector<std::unique_ptr<Iterator>> c<br>
if (It != InvertedIndex.end()) {<br>
// FIXME(kbobyrev): Append LIMIT on top of every BOOST iterator.<br>
PathProximitySignals.SymbolURI = ParentURI;<br>
- BoostingIterators.push_back(createBoost(It->second.iterator(&It->first),<br>
- PathProximitySignals.evaluate()));<br>
+ BoostingIterators.push_back(Corpus.boost(<br>
+ It->second.iterator(&It->first), PathProximitySignals.evaluate()));<br>
}<br>
}<br>
return BoostingIterators;<br>
@@ -101,6 +102,7 @@ std::vector<std::unique_ptr<Iterator>> c<br>
} // namespace<br>
<br>
void Dex::buildIndex() {<br>
+ this->Corpus = dex::Corpus(Symbols.size());<br>
std::vector<std::pair<float, const Symbol *>> ScoredSymbols(Symbols.size());<br>
<br>
for (size_t I = 0; I < Symbols.size(); ++I) {<br>
@@ -159,7 +161,7 @@ bool Dex::fuzzyFind(const FuzzyFindReque<br>
TrigramIterators.push_back(It->second.iterator(&It->first));<br>
}<br>
if (!TrigramIterators.empty())<br>
- TopLevelChildren.push_back(createAnd(move(TrigramIterators)));<br>
+ TopLevelChildren.push_back(Corpus.intersect(move(TrigramIterators)));<br>
<br>
// Generate scope tokens for search query.<br>
std::vector<std::unique_ptr<Iterator>> ScopeIterators;<br>
@@ -170,22 +172,22 @@ bool Dex::fuzzyFind(const FuzzyFindReque<br>
ScopeIterators.push_back(It->second.iterator(&It->first));<br>
}<br>
if (Req.AnyScope)<br>
- ScopeIterators.push_back(createBoost(createTrue(Symbols.size()),<br>
- ScopeIterators.empty() ? 1.0 : 0.2));<br>
+ ScopeIterators.push_back(<br>
+ Corpus.boost(Corpus.all(), ScopeIterators.empty() ? 1.0 : 0.2));<br>
<br>
// Add OR iterator for scopes if there are any Scope Iterators.<br>
if (!ScopeIterators.empty())<br>
- TopLevelChildren.push_back(createOr(move(ScopeIterators)));<br>
+ TopLevelChildren.push_back(Corpus.unionOf(move(ScopeIterators)));<br>
<br>
// Add proximity paths boosting.<br>
auto BoostingIterators = createFileProximityIterators(<br>
- Req.ProximityPaths, URISchemes, InvertedIndex);<br>
+ Req.ProximityPaths, URISchemes, InvertedIndex, Corpus);<br>
// Boosting iterators do not actually filter symbols. In order to preserve<br>
// the validity of resulting query, TRUE iterator should be added along<br>
// BOOSTs.<br>
if (!BoostingIterators.empty()) {<br>
- BoostingIterators.push_back(createTrue(Symbols.size()));<br>
- TopLevelChildren.push_back(createOr(move(BoostingIterators)));<br>
+ BoostingIterators.push_back(Corpus.all());<br>
+ TopLevelChildren.push_back(Corpus.unionOf(move(BoostingIterators)));<br>
}<br>
<br>
if (Req.RestrictForCodeCompletion)<br>
@@ -196,14 +198,14 @@ bool Dex::fuzzyFind(const FuzzyFindReque<br>
// Use TRUE iterator if both trigrams and scopes from the query are not<br>
// present in the symbol index.<br>
auto QueryIterator = TopLevelChildren.empty()<br>
- ? createTrue(Symbols.size())<br>
- : createAnd(move(TopLevelChildren));<br>
+ ? Corpus.all()<br>
+ : Corpus.intersect(move(TopLevelChildren));<br>
// Retrieve more items than it was requested: some of the items with high<br>
// final score might not be retrieved otherwise.<br>
// FIXME(kbobyrev): Pre-scoring retrieval threshold should be adjusted as<br>
// using 100x of the requested number might not be good in practice, e.g.<br>
// when the requested number of items is small.<br>
- auto Root = Req.Limit ? createLimit(move(QueryIterator), *Req.Limit * 100)<br>
+ auto Root = Req.Limit ? Corpus.limit(move(QueryIterator), *Req.Limit * 100)<br>
: move(QueryIterator);<br>
SPAN_ATTACH(Tracer, "query", llvm::to_string(*Root));<br>
vlog("Dex query tree: {0}", *Root);<br>
<br>
Modified: clang-tools-extra/trunk/clangd/index/dex/Dex.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.h?rev=343589&r1=343588&r2=343589&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Dex.h?rev=343589&r1=343588&r2=343589&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clangd/index/dex/Dex.h (original)<br>
+++ clang-tools-extra/trunk/clangd/index/dex/Dex.h Tue Oct 2 06:44:26 2018<br>
@@ -44,7 +44,7 @@ public:<br>
// All symbols must outlive this index.<br>
template <typename Range><br>
Dex(Range &&Symbols, llvm::ArrayRef<std::string> Schemes)<br>
- : URISchemes(Schemes) {<br>
+ : Corpus(0), URISchemes(Schemes) {<br>
// If Schemes don't contain any items, fall back to SymbolCollector's<br>
// default URI schemes.<br>
if (URISchemes.empty()) {<br>
@@ -101,6 +101,7 @@ private:<br>
/// std. Inverted index is used to retrieve posting lists which are processed<br>
/// during the fuzzyFind process.<br>
llvm::DenseMap<Token, PostingList> InvertedIndex;<br>
+ Corpus Corpus;<br>
std::shared_ptr<void> KeepAlive; // poor man's move-only std::any<br>
// Size of memory retained by KeepAlive.<br>
size_t BackingDataSize = 0;<br>
<br>
Modified: clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp?rev=343589&r1=343588&r2=343589&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp?rev=343589&r1=343588&r2=343589&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd/index/dex/Iterator.cpp Tue Oct 2 06:44:26 2018<br>
@@ -64,7 +64,7 @@ public:<br>
<br>
float consume() override {<br>
assert(!reachedEnd() && "AND iterator can't consume() at the end.");<br>
- float Boost = DEFAULT_BOOST_SCORE;<br>
+ float Boost = 1;<br>
for (const auto &Child : Children)<br>
Boost *= Child->consume();<br>
return Boost;<br>
@@ -175,12 +175,12 @@ public:<br>
return Result;<br>
}<br>
<br>
- // Returns the maximum boosting score among all Children when iterator is not<br>
- // exhausted and points to the given ID, DEFAULT_BOOST_SCORE otherwise.<br>
+ // Returns the maximum boosting score among all Children when iterator<br>
+ // points to the current ID.<br>
float consume() override {<br>
assert(!reachedEnd() && "OR iterator can't consume() at the end.");<br>
const DocID ID = peek();<br>
- float Boost = DEFAULT_BOOST_SCORE;<br>
+ float Boost = 1;<br>
for (const auto &Child : Children)<br>
if (!Child->reachedEnd() && Child->peek() == ID)<br>
Boost = std::max(Boost, Child->consume());<br>
@@ -236,7 +236,7 @@ public:<br>
<br>
float consume() override {<br>
assert(!reachedEnd() && "TRUE iterator can't consume() at the end.");<br>
- return DEFAULT_BOOST_SCORE;<br>
+ return 1;<br>
}<br>
<br>
size_t estimateSize() const override { return Size; }<br>
@@ -330,30 +330,30 @@ std::vector<std::pair<DocID, float>> con<br>
}<br>
<br>
std::unique_ptr<Iterator><br>
-createAnd(std::vector<std::unique_ptr<Iterator>> Children) {<br>
+Corpus::intersect(std::vector<std::unique_ptr<Iterator>> Children) const {<br>
// If there is exactly one child, pull it one level up: AND(Child) -> Child.<br>
return Children.size() == 1 ? std::move(Children.front())<br>
: llvm::make_unique<AndIterator>(move(Children));<br>
}<br>
<br>
std::unique_ptr<Iterator><br>
-createOr(std::vector<std::unique_ptr<Iterator>> Children) {<br>
+Corpus::unionOf(std::vector<std::unique_ptr<Iterator>> Children) const {<br>
// If there is exactly one child, pull it one level up: OR(Child) -> Child.<br>
return Children.size() == 1 ? std::move(Children.front())<br>
: llvm::make_unique<OrIterator>(move(Children));<br>
}<br>
<br>
-std::unique_ptr<Iterator> createTrue(DocID Size) {<br>
+std::unique_ptr<Iterator> Corpus::all() const {<br>
return llvm::make_unique<TrueIterator>(Size);<br>
}<br>
<br>
-std::unique_ptr<Iterator> createBoost(std::unique_ptr<Iterator> Child,<br>
- float Factor) {<br>
+std::unique_ptr<Iterator> Corpus::boost(std::unique_ptr<Iterator> Child,<br>
+ float Factor) const {<br>
return llvm::make_unique<BoostIterator>(move(Child), Factor);<br>
}<br>
<br>
-std::unique_ptr<Iterator> createLimit(std::unique_ptr<Iterator> Child,<br>
- size_t Limit) {<br>
+std::unique_ptr<Iterator> Corpus::limit(std::unique_ptr<Iterator> Child,<br>
+ size_t Limit) const {<br>
return llvm::make_unique<LimitIterator>(move(Child), Limit);<br>
}<br>
<br>
<br>
Modified: clang-tools-extra/trunk/clangd/index/dex/Iterator.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Iterator.h?rev=343589&r1=343588&r2=343589&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/Iterator.h?rev=343589&r1=343588&r2=343589&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clangd/index/dex/Iterator.h (original)<br>
+++ clang-tools-extra/trunk/clangd/index/dex/Iterator.h Tue Oct 2 06:44:26 2018<br>
@@ -101,8 +101,6 @@ public:<br>
return Iterator.dump(OS);<br>
}<br>
<br>
- constexpr static float DEFAULT_BOOST_SCORE = 1;<br>
-<br>
private:<br>
virtual llvm::raw_ostream &dump(llvm::raw_ostream &OS) const = 0;<br>
};<br>
@@ -117,69 +115,74 @@ private:<br>
/// to acquire preliminary scores of requested items.<br>
std::vector<std::pair<DocID, float>> consume(Iterator &It);<br>
<br>
-/// Returns AND Iterator which performs the intersection of the PostingLists of<br>
-/// its children.<br>
-///<br>
-/// consume(): AND Iterator returns the product of Childrens' boosting scores<br>
-/// when not exhausted and DEFAULT_BOOST_SCORE otherwise.<br>
-std::unique_ptr<Iterator><br>
-createAnd(std::vector<std::unique_ptr<Iterator>> Children);<br>
-<br>
-/// Returns OR Iterator which performs the union of the PostingLists of its<br>
-/// children.<br>
-///<br>
-/// consume(): OR Iterator returns the highest boost value among children<br>
-/// pointing to requested item when not exhausted and DEFAULT_BOOST_SCORE<br>
-/// otherwise.<br>
-std::unique_ptr<Iterator><br>
-createOr(std::vector<std::unique_ptr<Iterator>> Children);<br>
-<br>
-/// Returns TRUE Iterator which iterates over "virtual" PostingList containing<br>
-/// all items in range [0, Size) in an efficient manner.<br>
-///<br>
-/// TRUE returns DEFAULT_BOOST_SCORE for each processed item.<br>
-std::unique_ptr<Iterator> createTrue(DocID Size);<br>
-<br>
-/// Returns BOOST iterator which multiplies the score of each item by given<br>
-/// factor. Boosting can be used as a computationally inexpensive filtering.<br>
-/// Users can return significantly more items using consumeAndBoost() and then<br>
-/// trim Top K using retrieval score.<br>
-std::unique_ptr<Iterator> createBoost(std::unique_ptr<Iterator> Child,<br>
- float Factor);<br>
-<br>
-/// Returns LIMIT iterator, which yields up to N elements of its child iterator.<br>
-/// Elements only count towards the limit if they are part of the final result<br>
-/// set. Therefore the following iterator (AND (2) (LIMIT (1 2) 1)) yields (2),<br>
-/// not ().<br>
-std::unique_ptr<Iterator> createLimit(std::unique_ptr<Iterator> Child,<br>
- size_t Limit);<br>
-<br>
-/// This allows createAnd(create(...), create(...)) syntax.<br>
-template <typename... Args> std::unique_ptr<Iterator> createAnd(Args... args) {<br>
- std::vector<std::unique_ptr<Iterator>> Children;<br>
- populateChildren(Children, args...);<br>
- return createAnd(move(Children));<br>
-}<br>
-<br>
-/// This allows createOr(create(...), create(...)) syntax.<br>
-template <typename... Args> std::unique_ptr<Iterator> createOr(Args... args) {<br>
- std::vector<std::unique_ptr<Iterator>> Children;<br>
- populateChildren(Children, args...);<br>
- return createOr(move(Children));<br>
-}<br>
-<br>
-template <typename HeadT, typename... TailT><br>
+namespace detail {<br>
+// Variadic template machinery.<br>
+inline void populateChildren(std::vector<std::unique_ptr<Iterator>> &) {}<br>
+template <typename... TailT><br>
void populateChildren(std::vector<std::unique_ptr<Iterator>> &Children,<br>
- HeadT &Head, TailT &... Tail) {<br>
+ std::unique_ptr<Iterator> Head, TailT... Tail) {<br>
Children.push_back(move(Head));<br>
- populateChildren(Children, Tail...);<br>
+ populateChildren(Children, move(Tail)...);<br>
}<br>
+} // namespace detail<br>
<br>
-template <typename HeadT><br>
-void populateChildren(std::vector<std::unique_ptr<Iterator>> &Children,<br>
- HeadT &Head) {<br>
- Children.push_back(move(Head));<br>
-}<br>
+// A corpus is a set of documents, and a factory for iterators over them.<br>
+class Corpus {<br>
+ DocID Size;<br>
+<br>
+public:<br>
+ explicit Corpus(DocID Size) : Size(Size) {}<br>
+<br>
+ /// Returns AND Iterator which performs the intersection of the PostingLists<br>
+ /// of its children.<br>
+ ///<br>
+ /// consume(): AND Iterator returns the product of Childrens' boosting<br>
+ /// scores.<br>
+ std::unique_ptr<Iterator><br>
+ intersect(std::vector<std::unique_ptr<Iterator>> Children) const;<br>
+<br>
+ /// Returns OR Iterator which performs the union of the PostingLists of its<br>
+ /// children.<br>
+ ///<br>
+ /// consume(): OR Iterator returns the highest boost value among children<br>
+ /// containing the requested item.<br>
+ std::unique_ptr<Iterator><br>
+ unionOf(std::vector<std::unique_ptr<Iterator>> Children) const;<br>
+<br>
+ /// Returns TRUE Iterator which iterates over "virtual" PostingList<br>
+ /// containing all items in range [0, Size) in an efficient manner.<br>
+ std::unique_ptr<Iterator> all() const;<br>
+<br>
+ /// Returns BOOST iterator which multiplies the score of each item by given<br>
+ /// factor. Boosting can be used as a computationally inexpensive filtering.<br>
+ /// Users can return significantly more items using consumeAndBoost() and<br>
+ /// then trim Top K using retrieval score.<br>
+ std::unique_ptr<Iterator> boost(std::unique_ptr<Iterator> Child,<br>
+ float Factor) const;<br>
+<br>
+ /// Returns LIMIT iterator, which yields up to N elements of its child<br>
+ /// iterator. Elements only count towards the limit if they are part of the<br>
+ /// final result set. Therefore the following iterator (AND (2) (LIMIT (1 2)<br>
+ /// 1)) yields (2), not ().<br>
+ std::unique_ptr<Iterator> limit(std::unique_ptr<Iterator> Child,<br>
+ size_t Limit) const;<br>
+<br>
+ /// This allows intersect(create(...), create(...)) syntax.<br>
+ template <typename... Args><br>
+ std::unique_ptr<Iterator> intersect(Args... args) const {<br>
+ std::vector<std::unique_ptr<Iterator>> Children;<br>
+ detail::populateChildren(Children, std::forward<Args>(args)...);<br>
+ return intersect(move(Children));<br>
+ }<br>
+<br>
+ /// This allows unionOf(create(...), create(...)) syntax.<br>
+ template <typename... Args><br>
+ std::unique_ptr<Iterator> unionOf(Args... args) const {<br>
+ std::vector<std::unique_ptr<Iterator>> Children;<br>
+ detail::populateChildren(Children, std::forward<Args>(args)...);<br>
+ return unionOf(move(Children));<br>
+ }<br>
+};<br>
<br>
} // namespace dex<br>
} // namespace clangd<br>
<br>
Modified: clang-tools-extra/trunk/clangd/index/dex/PostingList.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/PostingList.cpp?rev=343589&r1=343588&r2=343589&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/dex/PostingList.cpp?rev=343589&r1=343588&r2=343589&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/clangd/index/dex/PostingList.cpp (original)<br>
+++ clang-tools-extra/trunk/clangd/index/dex/PostingList.cpp Tue Oct 2 06:44:26 2018<br>
@@ -63,7 +63,7 @@ public:<br>
float consume() override {<br>
assert(!reachedEnd() &&<br>
"Posting List iterator can't consume() at the end.");<br>
- return DEFAULT_BOOST_SCORE;<br>
+ return 1;<br>
}<br>
<br>
size_t estimateSize() const override {<br>
<br>
Modified: clang-tools-extra/trunk/unittests/clangd/DexTests.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/DexTests.cpp?rev=343589&r1=343588&r2=343589&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/DexTests.cpp?rev=343589&r1=343588&r2=343589&view=diff</a><br>
==============================================================================<br>
--- clang-tools-extra/trunk/unittests/clangd/DexTests.cpp (original)<br>
+++ clang-tools-extra/trunk/unittests/clangd/DexTests.cpp Tue Oct 2 06:44:26 2018<br>
@@ -70,15 +70,16 @@ TEST(DexIterators, DocumentIterator) {<br>
}<br>
<br>
TEST(DexIterators, AndTwoLists) {<br>
+ Corpus C{10000};<br>
const PostingList L0({0, 5, 7, 10, 42, 320, 9000});<br>
const PostingList L1({0, 4, 7, 10, 30, 60, 320, 9000});<br>
<br>
- auto And = createAnd(L1.iterator(), L0.iterator());<br>
+ auto And = C.intersect(L1.iterator(), L0.iterator());<br>
<br>
EXPECT_FALSE(And->reachedEnd());<br>
EXPECT_THAT(consumeIDs(*And), ElementsAre(0U, 7U, 10U, 320U, 9000U));<br>
<br>
- And = createAnd(L0.iterator(), L1.iterator());<br>
+ And = C.intersect(L0.iterator(), L1.iterator());<br>
<br>
And->advanceTo(0);<br>
EXPECT_EQ(And->peek(), 0U);<br>
@@ -94,11 +95,12 @@ TEST(DexIterators, AndTwoLists) {<br>
}<br>
<br>
TEST(DexIterators, AndThreeLists) {<br>
+ Corpus C{10000};<br>
const PostingList L0({0, 5, 7, 10, 42, 320, 9000});<br>
const PostingList L1({0, 4, 7, 10, 30, 60, 320, 9000});<br>
const PostingList L2({1, 4, 7, 11, 30, 60, 320, 9000});<br>
<br>
- auto And = createAnd(L0.iterator(), L1.iterator(), L2.iterator());<br>
+ auto And = C.intersect(L0.iterator(), L1.iterator(), L2.iterator());<br>
EXPECT_EQ(And->peek(), 7U);<br>
And->advanceTo(300);<br>
EXPECT_EQ(And->peek(), 320U);<br>
@@ -108,10 +110,11 @@ TEST(DexIterators, AndThreeLists) {<br>
}<br>
<br>
TEST(DexIterators, OrTwoLists) {<br>
+ Corpus C{10000};<br>
const PostingList L0({0, 5, 7, 10, 42, 320, 9000});<br>
const PostingList L1({0, 4, 7, 10, 30, 60, 320, 9000});<br>
<br>
- auto Or = createOr(L0.iterator(), L1.iterator());<br>
+ auto Or = C.unionOf(L0.iterator(), L1.iterator());<br>
<br>
EXPECT_FALSE(Or->reachedEnd());<br>
EXPECT_EQ(Or->peek(), 0U);<br>
@@ -134,18 +137,19 @@ TEST(DexIterators, OrTwoLists) {<br>
Or->advanceTo(9001);<br>
EXPECT_TRUE(Or->reachedEnd());<br>
<br>
- Or = createOr(L0.iterator(), L1.iterator());<br>
+ Or = C.unionOf(L0.iterator(), L1.iterator());<br>
<br>
EXPECT_THAT(consumeIDs(*Or),<br>
ElementsAre(0U, 4U, 5U, 7U, 10U, 30U, 42U, 60U, 320U, 9000U));<br>
}<br>
<br>
TEST(DexIterators, OrThreeLists) {<br>
+ Corpus C{10000};<br>
const PostingList L0({0, 5, 7, 10, 42, 320, 9000});<br>
const PostingList L1({0, 4, 7, 10, 30, 60, 320, 9000});<br>
const PostingList L2({1, 4, 7, 11, 30, 60, 320, 9000});<br>
<br>
- auto Or = createOr(L0.iterator(), L1.iterator(), L2.iterator());<br>
+ auto Or = C.unionOf(L0.iterator(), L1.iterator(), L2.iterator());<br>
<br>
EXPECT_FALSE(Or->reachedEnd());<br>
EXPECT_EQ(Or->peek(), 0U);<br>
@@ -194,17 +198,18 @@ TEST(DexIterators, QueryTree) {<br>
// |1, 5, 7, 9| |1, 5| |0, 3, 5|<br>
// +----------+ +----+ +-------+<br>
//<br>
+ Corpus C{10};<br>
const PostingList L0({1, 3, 5, 8, 9});<br>
const PostingList L1({1, 5, 7, 9});<br>
const PostingList L2({1, 5});<br>
const PostingList L3({0, 3, 5});<br>
<br>
// Root of the query tree: [1, 5]<br>
- auto Root = createAnd(<br>
+ auto Root = C.intersect(<br>
// Lower And Iterator: [1, 5, 9]<br>
- createAnd(L0.iterator(), createBoost(L1.iterator(), 2U)),<br>
+ C.intersect(L0.iterator(), C.boost(L1.iterator(), 2U)),<br>
// Lower Or Iterator: [0, 1, 5]<br>
- createOr(createBoost(L2.iterator(), 3U), createBoost(L3.iterator(), 4U)));<br>
+ C.unionOf(C.boost(L2.iterator(), 3U), C.boost(L3.iterator(), 4U)));<br>
<br>
EXPECT_FALSE(Root->reachedEnd());<br>
EXPECT_EQ(Root->peek(), 1U);<br>
@@ -226,6 +231,7 @@ TEST(DexIterators, QueryTree) {<br>
}<br>
<br>
TEST(DexIterators, StringRepresentation) {<br>
+ Corpus C{10};<br>
const PostingList L1({1, 3, 5});<br>
const PostingList L2({1, 7, 9});<br>
<br>
@@ -238,56 +244,60 @@ TEST(DexIterators, StringRepresentation)<br>
auto I2 = L1.iterator(&Tok);<br>
EXPECT_EQ(llvm::to_string(*I2), "T=L2");<br>
<br>
- auto Tree = createLimit(createAnd(move(I1), move(I2)), 10);<br>
+ auto Tree = C.limit(C.intersect(move(I1), move(I2)), 10);<br>
EXPECT_EQ(llvm::to_string(*Tree), "(LIMIT 10 (& [1 3 5] T=L2))");<br>
}<br>
<br>
TEST(DexIterators, Limit) {<br>
+ Corpus C{10000};<br>
const PostingList L0({3, 6, 7, 20, 42, 100});<br>
const PostingList L1({1, 3, 5, 6, 7, 30, 100});<br>
const PostingList L2({0, 3, 5, 7, 8, 100});<br>
<br>
- auto DocIterator = createLimit(L0.iterator(), 42);<br>
+ auto DocIterator = C.limit(L0.iterator(), 42);<br>
EXPECT_THAT(consumeIDs(*DocIterator), ElementsAre(3, 6, 7, 20, 42, 100));<br>
<br>
- DocIterator = createLimit(L0.iterator(), 3);<br>
+ DocIterator = C.limit(L0.iterator(), 3);<br>
EXPECT_THAT(consumeIDs(*DocIterator), ElementsAre(3, 6, 7));<br>
<br>
- DocIterator = createLimit(L0.iterator(), 0);<br>
+ DocIterator = C.limit(L0.iterator(), 0);<br>
EXPECT_THAT(consumeIDs(*DocIterator), ElementsAre());<br>
<br>
- auto AndIterator = createAnd(<br>
- createLimit(createTrue(9000), 343), createLimit(L0.iterator(), 2),<br>
- createLimit(L1.iterator(), 3), createLimit(L2.iterator(), 42));<br>
+ auto AndIterator =<br>
+ C.intersect(C.limit(C.all(), 343), C.limit(L0.iterator(), 2),<br>
+ C.limit(L1.iterator(), 3), C.limit(L2.iterator(), 42));<br>
EXPECT_THAT(consumeIDs(*AndIterator), ElementsAre(3, 7));<br>
}<br>
<br>
TEST(DexIterators, True) {<br>
- auto TrueIterator = createTrue(0U);<br>
+ Corpus C{0};<br>
+ auto TrueIterator = C.all();<br>
EXPECT_TRUE(TrueIterator->reachedEnd());<br>
EXPECT_THAT(consumeIDs(*TrueIterator), ElementsAre());<br>
<br>
+ C = Corpus{7};<br>
const PostingList L0({1, 2, 5, 7});<br>
- TrueIterator = createTrue(7U);<br>
+ TrueIterator = C.all();<br>
EXPECT_THAT(TrueIterator->peek(), 0);<br>
- auto AndIterator = createAnd(L0.iterator(), move(TrueIterator));<br>
+ auto AndIterator = C.intersect(L0.iterator(), move(TrueIterator));<br>
EXPECT_FALSE(AndIterator->reachedEnd());<br>
EXPECT_THAT(consumeIDs(*AndIterator), ElementsAre(1, 2, 5));<br>
}<br>
<br>
TEST(DexIterators, Boost) {<br>
- auto BoostIterator = createBoost(createTrue(5U), 42U);<br>
+ Corpus C{5};<br>
+ auto BoostIterator = C.boost(C.all(), 42U);<br>
EXPECT_FALSE(BoostIterator->reachedEnd());<br>
auto ElementBoost = BoostIterator->consume();<br>
EXPECT_THAT(ElementBoost, 42U);<br>
<br>
const PostingList L0({2, 4});<br>
const PostingList L1({1, 4});<br>
- auto Root = createOr(createTrue(5U), createBoost(L0.iterator(), 2U),<br>
- createBoost(L1.iterator(), 3U));<br>
+ auto Root = C.unionOf(C.all(), C.boost(L0.iterator(), 2U),<br>
+ C.boost(L1.iterator(), 3U));<br>
<br>
ElementBoost = Root->consume();<br>
- EXPECT_THAT(ElementBoost, Iterator::DEFAULT_BOOST_SCORE);<br>
+ EXPECT_THAT(ElementBoost, 1);<br>
Root->advance();<br>
EXPECT_THAT(Root->peek(), 1U);<br>
ElementBoost = Root->consume();<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>
</blockquote></div>