From: <lau...@us...> - 2009-07-29 13:51:34
|
Revision: 783 http://xqilla.svn.sourceforge.net/xqilla/?rev=783&view=rev Author: lauren_foutz Date: 2009-07-29 13:51:18 +0000 (Wed, 29 Jul 2009) Log Message: ----------- [#17399] Removing reference counting and a lot of heap allocation from the implementation of AllMatches. Matches.hpp is no longer needed, but have not removed it because of difficulty recreating the Makefiles using automake. If anyone else can remove Matches.hpp and remake the Makefiles please do. Modified Paths: -------------- trunk/xqilla/Win32Projects/VC6/xqilla.dsp trunk/xqilla/Win32Projects/VC7.1/xqilla.vcproj trunk/xqilla/Win32Projects/VC8/xqilla.vcproj trunk/xqilla/include/xqilla/fulltext/AllMatches.hpp trunk/xqilla/include/xqilla/fulltext/DefaultTokenStore.hpp trunk/xqilla/include/xqilla/fulltext/DefaultTokenizer.hpp trunk/xqilla/include/xqilla/fulltext/FTAnd.hpp trunk/xqilla/include/xqilla/fulltext/FTContent.hpp trunk/xqilla/include/xqilla/fulltext/FTDistance.hpp trunk/xqilla/include/xqilla/fulltext/FTMildnot.hpp trunk/xqilla/include/xqilla/fulltext/FTOption.hpp trunk/xqilla/include/xqilla/fulltext/FTOr.hpp trunk/xqilla/include/xqilla/fulltext/FTOrder.hpp trunk/xqilla/include/xqilla/fulltext/FTScope.hpp trunk/xqilla/include/xqilla/fulltext/FTSelection.hpp trunk/xqilla/include/xqilla/fulltext/FTUnaryNot.hpp trunk/xqilla/include/xqilla/fulltext/FTWindow.hpp trunk/xqilla/include/xqilla/fulltext/FTWords.hpp trunk/xqilla/include/xqilla/fulltext/TokenInfo.hpp trunk/xqilla/src/fulltext/DefaultTokenStore.cpp trunk/xqilla/src/fulltext/DefaultTokenizer.cpp trunk/xqilla/src/fulltext/FTAnd.cpp trunk/xqilla/src/fulltext/FTContains.cpp trunk/xqilla/src/fulltext/FTContent.cpp trunk/xqilla/src/fulltext/FTDistance.cpp trunk/xqilla/src/fulltext/FTMildnot.cpp trunk/xqilla/src/fulltext/FTOr.cpp trunk/xqilla/src/fulltext/FTOrder.cpp trunk/xqilla/src/fulltext/FTScope.cpp trunk/xqilla/src/fulltext/FTUnaryNot.cpp trunk/xqilla/src/fulltext/FTWindow.cpp trunk/xqilla/src/fulltext/FTWords.cpp trunk/xqilla/wintools/srcfiles.in trunk/xqilla/wintools/xqilla.template.xml Modified: trunk/xqilla/Win32Projects/VC6/xqilla.dsp =================================================================== --- trunk/xqilla/Win32Projects/VC6/xqilla.dsp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/Win32Projects/VC6/xqilla.dsp 2009-07-29 13:51:18 UTC (rev 783) @@ -1241,10 +1241,6 @@ # End Source File # Begin Source File -SOURCE=..\..\include\xqilla\fulltext\Match.hpp -# End Source File -# Begin Source File - SOURCE=..\..\include\xqilla\fulltext\TokenInfo.hpp # End Source File # Begin Source File Modified: trunk/xqilla/Win32Projects/VC7.1/xqilla.vcproj =================================================================== --- trunk/xqilla/Win32Projects/VC7.1/xqilla.vcproj 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/Win32Projects/VC7.1/xqilla.vcproj 2009-07-29 13:51:18 UTC (rev 783) @@ -134,7 +134,6 @@ <File RelativePath="..\..\include\xqilla\fulltext\FTMildnot.hpp"/> <File RelativePath="..\..\include\xqilla\fulltext\FTUnaryNot.hpp"/> <File RelativePath="..\..\include\xqilla\fulltext\AllMatches.hpp"/> - <File RelativePath="..\..\include\xqilla\fulltext\Match.hpp"/> <File RelativePath="..\..\include\xqilla\fulltext\TokenInfo.hpp"/> <File RelativePath="..\..\include\xqilla\fulltext\Tokenizer.hpp"/> <File RelativePath="..\..\include\xqilla\fulltext\DefaultTokenizer.hpp"/> Modified: trunk/xqilla/Win32Projects/VC8/xqilla.vcproj =================================================================== --- trunk/xqilla/Win32Projects/VC8/xqilla.vcproj 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/Win32Projects/VC8/xqilla.vcproj 2009-07-29 13:51:18 UTC (rev 783) @@ -214,7 +214,6 @@ <File RelativePath="..\..\include\xqilla\fulltext\FTMildnot.hpp"/> <File RelativePath="..\..\include\xqilla\fulltext\FTUnaryNot.hpp"/> <File RelativePath="..\..\include\xqilla\fulltext\AllMatches.hpp"/> - <File RelativePath="..\..\include\xqilla\fulltext\Match.hpp"/> <File RelativePath="..\..\include\xqilla\fulltext\TokenInfo.hpp"/> <File RelativePath="..\..\include\xqilla\fulltext\Tokenizer.hpp"/> <File RelativePath="..\..\include\xqilla\fulltext\DefaultTokenizer.hpp"/> Modified: trunk/xqilla/include/xqilla/fulltext/AllMatches.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/AllMatches.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/AllMatches.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -23,20 +23,45 @@ #include <xqilla/framework/XQillaExport.hpp> #include <xqilla/framework/ReferenceCounted.hpp> -#include <xqilla/fulltext/Match.hpp> +#include <xqilla/fulltext/TokenInfo.hpp> class DynamicContext; -class XQILLA_API AllMatches : public ReferenceCounted, public LocationInfo +class XQILLA_API StringMatch { public: - typedef RefCountPointer<AllMatches> Ptr; + StringMatch() + : tokenInfo(), queryPos(0), startToken(false), endToken(false) + {} + StringMatch(unsigned int qPos, const TokenInfo &tInfo) + : tokenInfo(tInfo.word_, tInfo.position_, tInfo.sentence_, + tInfo.paragraph_), queryPos(qPos), startToken(false), endToken(false) + {} + StringMatch(const StringMatch &other) + : tokenInfo(other.tokenInfo.word_, other.tokenInfo.position_, + other.tokenInfo.sentence_, other.tokenInfo.paragraph_), queryPos(other.queryPos), + startToken(other.startToken), endToken(other.endToken) + {} + + TokenInfo tokenInfo; + unsigned int queryPos; + bool startToken, endToken; +}; + +typedef std::vector<StringMatch> StringMatches; + +class XQILLA_API AllMatches : public LocationInfo +{ +public: virtual ~AllMatches() {} - /// Get the next Match from the iterator. Returns null if the is no next value. - virtual Match::Ptr next(DynamicContext *context) = 0; + /// Get the next Match from the iterator. Returns false if there is no next value. + virtual bool next(DynamicContext *context) = 0; + virtual const StringMatches &getStringIncludes() = 0; + virtual const StringMatches &getStringExcludes() = 0; + protected: AllMatches(const LocationInfo *o) { Modified: trunk/xqilla/include/xqilla/fulltext/DefaultTokenStore.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/DefaultTokenStore.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/DefaultTokenStore.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -35,7 +35,7 @@ class XQILLA_API DefaultTokenStore : public TokenStore { public: - typedef std::vector<TokenInfo::Ptr> Tokens; + typedef std::vector<TokenInfo> Tokens; class TokenEntryStream : public TokenStream { @@ -43,11 +43,13 @@ TokenEntryStream(const Tokens &tokens) : it_(tokens.begin()), end_(tokens.end()) {} - virtual TokenInfo::Ptr next() + virtual TokenInfo next() { if(it_ != end_) return *it_++; - return 0; + TokenInfo token; + memset(&token, 0, sizeof(TokenInfo)); + return token; } private: @@ -68,7 +70,7 @@ class TokenEntry { public: - void addToken(const TokenInfo::Ptr &token) + void addToken(const TokenInfo &token) { tokens_.push_back(token); } Modified: trunk/xqilla/include/xqilla/fulltext/DefaultTokenizer.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/DefaultTokenizer.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/DefaultTokenizer.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -26,24 +26,6 @@ class XQILLA_API DefaultTokenizer : public Tokenizer { public: - class DefaultTokenInfo : public TokenInfo - { - public: - DefaultTokenInfo(const XMLCh *word, unsigned int pos, unsigned int sen, unsigned int para) - : word_(word), position_(pos), sentence_(sen), paragraph_(para) {} - - virtual const XMLCh *getWord() const { return word_; } - virtual unsigned int getPosition() const { return position_; } - virtual unsigned int getSentence() const { return sentence_; } - virtual unsigned int getParagraph() const { return paragraph_; } - - private: - const XMLCh *word_; - unsigned int position_; - unsigned int sentence_; - unsigned int paragraph_; - }; - DefaultTokenizer() {} virtual TokenStream::Ptr tokenize(const Node::Ptr &node, DynamicContext *context) const; @@ -55,7 +37,7 @@ public: DefaultTokenStream(const XMLCh *str, XPath2MemoryManager *mm); virtual ~DefaultTokenStream(); - virtual TokenInfo::Ptr next(); + virtual TokenInfo next(); private: XMLCh *string_; Modified: trunk/xqilla/include/xqilla/fulltext/FTAnd.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/FTAnd.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/FTAnd.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -33,7 +33,7 @@ virtual FTSelection *staticResolution(StaticContext *context); virtual FTSelection *staticTypingImpl(StaticContext *context); virtual FTSelection *optimize(FTContext *context) const; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const; + virtual AllMatches *execute(FTContext *ftcontext) const; const VectorOfFTSelections &getArguments() const { return args_; } void addArg(FTSelection *sel) { args_.push_back(sel); } @@ -45,32 +45,48 @@ class BufferedMatches : public AllMatches { public: - typedef RefCountPointer<BufferedMatches> Ptr; + BufferedMatches(const LocationInfo *info, AllMatches *matches); - BufferedMatches(const LocationInfo *info, const AllMatches::Ptr matches); - - Match::Ptr current(); - Match::Ptr next(DynamicContext *context); + bool next(DynamicContext *context); void reset(); + AllMatches *getAllMatches(); + + const StringMatches &getStringIncludes() { return *includeIt_; } + const StringMatches &getStringExcludes() { return *excludeIt_; } + private: - AllMatches::Ptr matches_; - std::list<Match::Ptr> buffer_; - std::list<Match::Ptr>::iterator it_; + AllMatches *matches_; + bool reset_; + std::vector<StringMatches> includeBuffer_; + std::vector<StringMatches> excludeBuffer_; + std::vector<StringMatches>::iterator includeIt_; + std::vector<StringMatches>::iterator excludeIt_; }; class FTConjunctionMatches : public AllMatches { public: FTConjunctionMatches(const LocationInfo *info); + ~FTConjunctionMatches(); - void addMatches(const AllMatches::Ptr &m); + void addMatches(AllMatches *m); - Match::Ptr next(DynamicContext *context); + bool next(DynamicContext *context); + const StringMatches &getStringIncludes(); + const StringMatches &getStringExcludes(); private: + void deleteMatches(); + +private: + void addStringIncludes(const StringMatches &sMatches); + void addStringExcludes(const StringMatches &sMatches); +private: bool toDo_; - std::vector<BufferedMatches::Ptr> args_; + std::vector<BufferedMatches> args_; + StringMatches includes_; + StringMatches excludes_; }; #endif Modified: trunk/xqilla/include/xqilla/fulltext/FTContent.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/FTContent.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/FTContent.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -39,7 +39,7 @@ virtual FTSelection *staticResolution(StaticContext *context); virtual FTSelection *staticTypingImpl(StaticContext *context); virtual FTSelection *optimize(FTContext *context) const; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const; + virtual AllMatches *execute(FTContext *ftcontext) const; virtual void setArgument(FTSelection *arg) { arg_ = arg; } FTSelection *getArgument() const { return arg_; } @@ -53,23 +53,31 @@ class FTContentAtStartMatches : public AllMatches { public: - FTContentAtStartMatches(const LocationInfo *info, const AllMatches::Ptr &arg) - : AllMatches(info), arg_(arg) {} - Match::Ptr next(DynamicContext *context); + FTContentAtStartMatches(const LocationInfo *info, AllMatches *arg) + : AllMatches(info), arg_(arg), includes_() {} + ~FTContentAtStartMatches(); + bool next(DynamicContext *context); + const StringMatches &getStringIncludes(); + const StringMatches &getStringExcludes(); private: - AllMatches::Ptr arg_; + AllMatches *arg_; + StringMatches includes_; }; class FTContentAtEndMatches : public AllMatches { public: - FTContentAtEndMatches(const LocationInfo *info, const AllMatches::Ptr &arg) - : AllMatches(info), arg_(arg) {} - Match::Ptr next(DynamicContext *context); + FTContentAtEndMatches(const LocationInfo *info, AllMatches *arg) + : AllMatches(info), arg_(arg), includes_() {} + ~FTContentAtEndMatches(); + bool next(DynamicContext *context); + const StringMatches &getStringIncludes(); + const StringMatches &getStringExcludes(); private: - AllMatches::Ptr arg_; + AllMatches *arg_; + StringMatches includes_; }; #endif Modified: trunk/xqilla/include/xqilla/fulltext/FTDistance.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/FTDistance.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/FTDistance.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -34,7 +34,7 @@ virtual FTSelection *staticResolution(StaticContext *context); virtual FTSelection *staticTypingImpl(StaticContext *context); virtual FTSelection *optimize(FTContext *context) const; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const; + virtual AllMatches *execute(FTContext *ftcontext) const; virtual void setArgument(FTSelection *arg) { arg_ = arg; } FTSelection *getArgument() const { return arg_; } @@ -62,7 +62,7 @@ virtual FTSelection *staticResolution(StaticContext *context); virtual FTSelection *staticTypingImpl(StaticContext *context); virtual FTSelection *optimize(FTContext *context) const; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const; + virtual AllMatches *execute(FTContext *ftcontext) const; virtual void setArgument(FTSelection *arg) { arg_ = arg; } FTSelection *getArgument() const { return arg_; } @@ -81,22 +81,26 @@ class FTDistanceMatches : public AllMatches { public: - FTDistanceMatches(const LocationInfo *info, unsigned int distance, FTOption::FTUnit unit, const AllMatches::Ptr &arg) - : AllMatches(info), distance_(distance), unit_(unit), arg_(arg) {} - Match::Ptr next(DynamicContext *context); + FTDistanceMatches(const LocationInfo *info, unsigned int distance, FTOption::FTUnit unit, AllMatches *arg) + : AllMatches(info), distance_(distance), unit_(unit), arg_(arg), excludes_() {} + ~FTDistanceMatches(); + bool next(DynamicContext *context); + const StringMatches &getStringIncludes(); + const StringMatches &getStringExcludes(); virtual bool distanceMatches(unsigned int actual) const = 0; protected: unsigned int distance_; FTOption::FTUnit unit_; - AllMatches::Ptr arg_; + AllMatches *arg_; + StringMatches excludes_; }; class FTDistanceExactlyMatches : public FTDistanceMatches { public: - FTDistanceExactlyMatches(const LocationInfo *info, unsigned int distance, FTOption::FTUnit unit, const AllMatches::Ptr &arg) + FTDistanceExactlyMatches(const LocationInfo *info, unsigned int distance, FTOption::FTUnit unit, AllMatches *arg) : FTDistanceMatches(info, distance, unit, arg) {} bool distanceMatches(unsigned int actual) const; }; @@ -104,7 +108,7 @@ class FTDistanceAtLeastMatches : public FTDistanceMatches { public: - FTDistanceAtLeastMatches(const LocationInfo *info, unsigned int distance, FTOption::FTUnit unit, const AllMatches::Ptr &arg) + FTDistanceAtLeastMatches(const LocationInfo *info, unsigned int distance, FTOption::FTUnit unit, AllMatches *arg) : FTDistanceMatches(info, distance, unit, arg) {} bool distanceMatches(unsigned int actual) const; }; @@ -112,7 +116,7 @@ class FTDistanceAtMostMatches : public FTDistanceMatches { public: - FTDistanceAtMostMatches(const LocationInfo *info, unsigned int distance, FTOption::FTUnit unit, const AllMatches::Ptr &arg) + FTDistanceAtMostMatches(const LocationInfo *info, unsigned int distance, FTOption::FTUnit unit, AllMatches *arg) : FTDistanceMatches(info, distance, unit, arg) {} bool distanceMatches(unsigned int actual) const; }; @@ -120,7 +124,7 @@ class FTDistanceFromToMatches : public FTDistanceMatches { public: - FTDistanceFromToMatches(const LocationInfo *info, unsigned int from, unsigned int to, FTOption::FTUnit unit, const AllMatches::Ptr &arg) + FTDistanceFromToMatches(const LocationInfo *info, unsigned int from, unsigned int to, FTOption::FTUnit unit, AllMatches *arg) : FTDistanceMatches(info, from, unit, arg), distance2_(to) {} bool distanceMatches(unsigned int actual) const; Modified: trunk/xqilla/include/xqilla/fulltext/FTMildnot.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/FTMildnot.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/FTMildnot.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -32,7 +32,7 @@ virtual FTSelection *staticResolution(StaticContext *context); virtual FTSelection *staticTypingImpl(StaticContext *context); virtual FTSelection *optimize(FTContext *context) const; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const; + virtual AllMatches *execute(FTContext *ftcontext) const; FTSelection *getLeft() const { return left_; } void setLeft(FTSelection *expr) { left_ = expr; } @@ -46,13 +46,16 @@ class FTMildnotMatches : public AllMatches { public: - FTMildnotMatches(const LocationInfo *info, const AllMatches::Ptr &left, const AllMatches::Ptr &right) + FTMildnotMatches(const LocationInfo *info, AllMatches *left, AllMatches *right) : AllMatches(info), left_(left), right_(right) {} - Match::Ptr next(DynamicContext *context); + ~FTMildnotMatches(); + bool next(DynamicContext *context); + const StringMatches &getStringIncludes(); + const StringMatches &getStringExcludes(); private: - AllMatches::Ptr left_; - AllMatches::Ptr right_; + AllMatches *left_; + AllMatches *right_; std::set<unsigned int> badTokens_; }; Modified: trunk/xqilla/include/xqilla/fulltext/FTOption.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/FTOption.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/FTOption.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -34,32 +34,41 @@ virtual void setArgument(FTSelection *arg) = 0; - static unsigned int tokenUnit(const TokenInfo::Ptr t, FTUnit unit) + static unsigned int tokenUnit(const TokenInfo &t, FTUnit unit) { switch(unit) { case WORDS: - return t->getPosition(); + return t.position_; case SENTENCES: - return t->getSentence(); + return t.sentence_; case PARAGRAPHS: - return t->getParagraph(); + return t.paragraph_; } return 0; } - static unsigned int tokenDistance(const TokenInfo::Ptr a, const TokenInfo::Ptr b, FTUnit unit) + static unsigned int tokenDistance(const TokenInfo &a, const TokenInfo &b, FTUnit unit) { switch(unit) { case WORDS: - return (unsigned int)labs((long)a->getPosition() - (long)b->getPosition()) - 1; + return (unsigned int)labs((long)a.position_ - (long)b.position_) - 1; case SENTENCES: - return (unsigned int)labs((long)a->getSentence() - (long)b->getSentence()); + return (unsigned int)labs((long)a.sentence_ - (long)b.sentence_); case PARAGRAPHS: - return (unsigned int)labs((long)a->getParagraph() - (long)b->getParagraph()); + return (unsigned int)labs((long)a.paragraph_ - (long)b.paragraph_); } return 0; } + static bool lessThanFunc(const TokenInfo &a, const TokenInfo &b) + { + if (a.paragraph_ != b.paragraph_) + return a.paragraph_ < b.paragraph_; + if (a.sentence_ != b.sentence_) + return a.sentence_ < b.sentence_; + return a.position_ < b.position_; + } + protected: FTOption(Type type, XPath2MemoryManager *memMgr) : FTSelection(type, memMgr) {} Modified: trunk/xqilla/include/xqilla/fulltext/FTOr.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/FTOr.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/FTOr.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -33,7 +33,7 @@ virtual FTSelection *staticResolution(StaticContext *context); virtual FTSelection *staticTypingImpl(StaticContext *context); virtual FTSelection *optimize(FTContext *context) const; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const; + virtual AllMatches *execute(FTContext *ftcontext) const; const VectorOfFTSelections &getArguments() const { return args_; } void addArg(FTSelection *sel) { args_.push_back(sel); } @@ -46,18 +46,21 @@ { public: FTDisjunctionMatches(const LocationInfo *info); + ~FTDisjunctionMatches(); - void addMatches(const AllMatches::Ptr &m) + void addMatches(AllMatches *m) { args_.push_back(m); } - Match::Ptr next(DynamicContext *context); + bool next(DynamicContext *context); + const StringMatches &getStringIncludes(); + const StringMatches &getStringExcludes(); private: bool toDo_; - std::vector<AllMatches::Ptr> args_; - std::vector<AllMatches::Ptr>::iterator it_; + std::vector<AllMatches*> args_; + std::vector<AllMatches*>::iterator it_; }; #endif Modified: trunk/xqilla/include/xqilla/fulltext/FTOrder.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/FTOrder.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/FTOrder.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -33,7 +33,7 @@ virtual FTSelection *staticResolution(StaticContext *context); virtual FTSelection *staticTypingImpl(StaticContext *context); virtual FTSelection *optimize(FTContext *context) const; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const; + virtual AllMatches *execute(FTContext *ftcontext) const; virtual void setArgument(FTSelection *arg) { arg_ = arg; } FTSelection *getArgument() const { return arg_; } @@ -45,12 +45,16 @@ class FTOrderMatches : public AllMatches { public: - FTOrderMatches(const LocationInfo *info, const AllMatches::Ptr &arg) - : AllMatches(info), arg_(arg) {} - Match::Ptr next(DynamicContext *context); + FTOrderMatches(const LocationInfo *info, AllMatches *arg) + : AllMatches(info), arg_(arg), excludes_() {} + ~FTOrderMatches(); + bool next(DynamicContext *context); + const StringMatches &getStringIncludes(); + const StringMatches &getStringExcludes(); private: - AllMatches::Ptr arg_; + AllMatches *arg_; + StringMatches excludes_; }; #endif Modified: trunk/xqilla/include/xqilla/fulltext/FTScope.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/FTScope.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/FTScope.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -21,6 +21,7 @@ #define _FTSCOPE_HPP #include <xqilla/fulltext/FTOption.hpp> +#include <set> class XQILLA_API FTScope : public FTOption { @@ -38,7 +39,7 @@ virtual FTSelection *staticResolution(StaticContext *context); virtual FTSelection *staticTypingImpl(StaticContext *context); virtual FTSelection *optimize(FTContext *context) const; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const; + virtual AllMatches *execute(FTContext *ftcontext) const; virtual void setArgument(FTSelection *arg) { arg_ = arg; } FTSelection *getArgument() const { return arg_; } @@ -54,25 +55,35 @@ class FTScopeSameMatches : public AllMatches { public: - FTScopeSameMatches(const LocationInfo *info, FTOption::FTUnit unit, const AllMatches::Ptr &arg) - : AllMatches(info), unit_(unit), arg_(arg) {} - Match::Ptr next(DynamicContext *context); + FTScopeSameMatches(const LocationInfo *info, FTOption::FTUnit unit, AllMatches *arg) + : AllMatches(info), unit_(unit), arg_(arg), excludes_(), unitValue_(0) {} + ~FTScopeSameMatches(); + bool next(DynamicContext *context); + const StringMatches &getStringIncludes(); + const StringMatches &getStringExcludes(); private: FTOption::FTUnit unit_; - AllMatches::Ptr arg_; + AllMatches *arg_; + StringMatches excludes_; + unsigned int unitValue_; }; class FTScopeDifferentMatches : public AllMatches { public: - FTScopeDifferentMatches(const LocationInfo *info, FTOption::FTUnit unit, const AllMatches::Ptr &arg) - : AllMatches(info), unit_(unit), arg_(arg) {} - Match::Ptr next(DynamicContext *context); + FTScopeDifferentMatches(const LocationInfo *info, FTOption::FTUnit unit, AllMatches *arg) + : AllMatches(info), unit_(unit), arg_(arg), excludes_(), unitValuesSeen_() {} + ~FTScopeDifferentMatches(); + bool next(DynamicContext *context); + const StringMatches &getStringIncludes(); + const StringMatches &getStringExcludes(); private: FTOption::FTUnit unit_; - AllMatches::Ptr arg_; + AllMatches *arg_; + StringMatches excludes_; + std::set<unsigned int> unitValuesSeen_; }; #endif Modified: trunk/xqilla/include/xqilla/fulltext/FTSelection.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/FTSelection.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/FTSelection.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -75,7 +75,7 @@ virtual FTSelection *staticResolution(StaticContext *context) = 0; virtual FTSelection *staticTypingImpl(StaticContext *context) = 0; virtual FTSelection *optimize(FTContext *context) const = 0; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const = 0; + virtual AllMatches *execute(FTContext *ftcontext) const = 0; XPath2MemoryManager *getMemoryManager() const { return memMgr_; } Modified: trunk/xqilla/include/xqilla/fulltext/FTUnaryNot.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/FTUnaryNot.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/FTUnaryNot.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -30,7 +30,7 @@ virtual FTSelection *staticResolution(StaticContext *context); virtual FTSelection *staticTypingImpl(StaticContext *context); virtual FTSelection *optimize(FTContext *context) const; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const; + virtual AllMatches *execute(FTContext *ftcontext) const; FTSelection *getArgument() const { return arg_; } void setArgument(FTSelection *expr) { arg_ = expr; } @@ -42,13 +42,22 @@ class FTUnaryNotMatches : public AllMatches { public: - FTUnaryNotMatches(const LocationInfo *info, const AllMatches::Ptr &arg) - : AllMatches(info), toDo_(true), arg_(arg) {} - Match::Ptr next(DynamicContext *context); + FTUnaryNotMatches(const LocationInfo *info, AllMatches *arg) + : AllMatches(info), toDo_(true), arg_(arg), includes_(), excludes_() {} + ~FTUnaryNotMatches(); + bool next(DynamicContext *context); + const StringMatches &getStringIncludes(); + const StringMatches &getStringExcludes(); private: + void addStringIncludes(const StringMatches &sMatches); + void addStringExcludes(const StringMatches &sMatches); + +private: bool toDo_; - AllMatches::Ptr arg_; + AllMatches *arg_; + StringMatches includes_; + StringMatches excludes_; }; #endif Modified: trunk/xqilla/include/xqilla/fulltext/FTWindow.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/FTWindow.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/FTWindow.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -37,7 +37,7 @@ virtual FTSelection *staticResolution(StaticContext *context); virtual FTSelection *staticTypingImpl(StaticContext *context); virtual FTSelection *optimize(FTContext *context) const; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const; + virtual AllMatches *execute(FTContext *ftcontext) const; virtual void setArgument(FTSelection *arg) { arg_ = arg; } FTSelection *getArgument() const { return arg_; } @@ -62,7 +62,7 @@ virtual FTSelection *staticResolution(StaticContext *context); virtual FTSelection *staticTypingImpl(StaticContext *context); virtual FTSelection *optimize(FTContext *context) const; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const; + virtual AllMatches *execute(FTContext *ftcontext) const; virtual void setArgument(FTSelection *arg) { arg_ = arg; } FTSelection *getArgument() const { return arg_; } @@ -78,17 +78,21 @@ class FTWindowMatches : public AllMatches { public: - FTWindowMatches(const LocationInfo *info, unsigned int distance, FTOption::FTUnit unit, const AllMatches::Ptr &arg) - : AllMatches(info), distance_(distance), unit_(unit), arg_(arg) {} - Match::Ptr next(DynamicContext *context); + FTWindowMatches(const LocationInfo *info, unsigned int distance, FTOption::FTUnit unit, AllMatches *arg) + : AllMatches(info), distance_(distance), unit_(unit), arg_(arg), found_(true), excludes_() {} + ~FTWindowMatches(); + bool next(DynamicContext *context); + const StringMatches &getStringIncludes(); + const StringMatches &getStringExcludes(); private: unsigned int distance_; FTOption::FTUnit unit_; - AllMatches::Ptr arg_; - Match::Ptr match_; + AllMatches *arg_; + bool found_; std::set<unsigned int> excludeValues_; std::set<unsigned int>::iterator excludeIt_; + StringMatches excludes_; }; #endif Modified: trunk/xqilla/include/xqilla/fulltext/FTWords.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/FTWords.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/FTWords.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -42,7 +42,7 @@ virtual FTSelection *staticResolution(StaticContext *context); virtual FTSelection *staticTypingImpl(StaticContext *context); virtual FTSelection *optimize(FTContext *context) const; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const; + virtual AllMatches *execute(FTContext *ftcontext) const; ASTNode *getExpr() const { return expr_; } void setExpr(ASTNode *expr) { expr_ = expr; } @@ -55,11 +55,11 @@ FTSelection *optimizeAny(Result strings, FTContext *ftcontext) const; FTSelection *optimizeAll(Result strings, FTContext *ftcontext) const; - AllMatches::Ptr executeAnyWord(Result strings, FTContext *ftcontext) const; - AllMatches::Ptr executeAllWords(Result strings, FTContext *ftcontext) const; - AllMatches::Ptr executePhrase(Result strings, FTContext *ftcontext) const; - AllMatches::Ptr executeAny(Result strings, FTContext *ftcontext) const; - AllMatches::Ptr executeAll(Result strings, FTContext *ftcontext) const; + AllMatches *executeAnyWord(Result strings, FTContext *ftcontext) const; + AllMatches *executeAllWords(Result strings, FTContext *ftcontext) const; + AllMatches *executePhrase(Result strings, FTContext *ftcontext) const; + AllMatches *executeAny(Result strings, FTContext *ftcontext) const; + AllMatches *executeAll(Result strings, FTContext *ftcontext) const; ASTNode *expr_; FTAnyallOption option_; @@ -73,7 +73,7 @@ virtual FTSelection *staticResolution(StaticContext *context); virtual FTSelection *staticTypingImpl(StaticContext *context); virtual FTSelection *optimize(FTContext *context) const; - virtual AllMatches::Ptr execute(FTContext *ftcontext) const; + virtual AllMatches *execute(FTContext *ftcontext) const; const XMLCh *getQueryString() const { return queryString_; } @@ -85,11 +85,15 @@ { public: FTStringSearchMatches(const LocationInfo *info, const XMLCh *queryString, FTContext *ftcontext); - Match::Ptr next(DynamicContext *context); + bool next(DynamicContext *context); + const StringMatches &getStringIncludes(); + const StringMatches &getStringExcludes(); private: unsigned int queryPos_; TokenStream::Ptr tokenStream_; + StringMatches includes_; + StringMatches excludes_; }; #endif Modified: trunk/xqilla/include/xqilla/fulltext/TokenInfo.hpp =================================================================== --- trunk/xqilla/include/xqilla/fulltext/TokenInfo.hpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/include/xqilla/fulltext/TokenInfo.hpp 2009-07-29 13:51:18 UTC (rev 783) @@ -25,20 +25,29 @@ #include <stdlib.h> -class XQILLA_API TokenInfo : public ReferenceCounted +struct XQILLA_API TokenInfo { -public: - typedef RefCountPointer<const TokenInfo> Ptr; + const XMLCh *word_; + unsigned int position_; + unsigned int sentence_; + unsigned int paragraph_; - virtual ~TokenInfo() {} + TokenInfo() + { + word_ = 0; + position_ = 0; + sentence_ = 0; + paragraph_ = 0; + } - virtual const XMLCh *getWord() const = 0; - virtual unsigned int getPosition() const = 0; - virtual unsigned int getSentence() const = 0; - virtual unsigned int getParagraph() const = 0; - -protected: - TokenInfo() {} + TokenInfo(const XMLCh *word, unsigned int position, + unsigned int sentence, unsigned int paragraph) + { + word_ = word; + position_ = position; + sentence_ = sentence; + paragraph_ = paragraph; + } }; class XQILLA_API TokenStream : public ReferenceCounted @@ -48,7 +57,7 @@ virtual ~TokenStream() {} - virtual TokenInfo::Ptr next() = 0; + virtual TokenInfo next() = 0; protected: TokenStream() {} Modified: trunk/xqilla/src/fulltext/DefaultTokenStore.cpp =================================================================== --- trunk/xqilla/src/fulltext/DefaultTokenStore.cpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/src/fulltext/DefaultTokenStore.cpp 2009-07-29 13:51:18 UTC (rev 783) @@ -38,11 +38,11 @@ buffer_(1023, context->getMemoryManager()) { TokenStream::Ptr stream = tokenizer->tokenize(node, context); - TokenInfo::Ptr token; - while((token = stream->next()).notNull()) { + TokenInfo token; + while((token = stream->next()).word_ != 0) { ++numTokens_; buffer_.reset(); - Normalizer::caseFoldAndRemoveDiacritics(token->getWord(), buffer_); + Normalizer::caseFoldAndRemoveDiacritics(token.word_, buffer_); TokenEntry *entry = tokens_.get(buffer_.getRawBuffer()); if(entry == 0) { Modified: trunk/xqilla/src/fulltext/DefaultTokenizer.cpp =================================================================== --- trunk/xqilla/src/fulltext/DefaultTokenizer.cpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/src/fulltext/DefaultTokenizer.cpp 2009-07-29 13:51:18 UTC (rev 783) @@ -58,16 +58,20 @@ #define REPORT_TOKEN \ if(tokenStart_ != 0) { \ *current_ = 0; \ - result = new DefaultTokenInfo(mm_->getPooledString(tokenStart_), position_, sentence_, paragraph_); \ + result.word_ = mm_->getPooledString(tokenStart_); \ + result.position_ = position_; \ + result.sentence_ = sentence_; \ + result.paragraph_ = paragraph_; \ ++position_; \ tokenStart_ = 0; \ } -TokenInfo::Ptr DefaultTokenizer::DefaultTokenStream::next() +TokenInfo DefaultTokenizer::DefaultTokenStream::next() { - TokenInfo::Ptr result(0); - while(result.isNull()) { + TokenInfo result; + memset(&result, 0, sizeof(TokenInfo)); + while(result.word_ == 0) { switch(*current_) { case '\n': { REPORT_TOKEN; Modified: trunk/xqilla/src/fulltext/FTAnd.cpp =================================================================== --- trunk/xqilla/src/fulltext/FTAnd.cpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/src/fulltext/FTAnd.cpp 2009-07-29 13:51:18 UTC (rev 783) @@ -83,10 +83,10 @@ return ftand; } -AllMatches::Ptr FTAnd::execute(FTContext *ftcontext) const +AllMatches *FTAnd::execute(FTContext *ftcontext) const { FTConjunctionMatches *conjunction = new FTConjunctionMatches(this); - AllMatches::Ptr result(conjunction); + AllMatches *result(conjunction); for(VectorOfFTSelections::const_iterator i = args_.begin(); i != args_.end(); ++i) { @@ -96,63 +96,85 @@ return result; } -BufferedMatches::BufferedMatches(const LocationInfo *info, const AllMatches::Ptr matches) +BufferedMatches::BufferedMatches(const LocationInfo *info, AllMatches *matches) : AllMatches(info), matches_(matches), - buffer_(), - it_(buffer_.begin()) + reset_(false), + includeBuffer_(), + excludeBuffer_(), + includeIt_(includeBuffer_.begin()), + excludeIt_(excludeBuffer_.begin()) { } -Match::Ptr BufferedMatches::current() +bool BufferedMatches::next(DynamicContext *context) { - if(it_ == buffer_.begin()) return 0; - Match::Ptr match = *--it_; - ++it_; - return match; -} + if(includeIt_ != includeBuffer_.end()) { + if (reset_) { + reset_ = false; + } else { + includeIt_++; + excludeIt_++; + } + if(includeIt_ != includeBuffer_.end()) + return true; + } -Match::Ptr BufferedMatches::next(DynamicContext *context) -{ - if(it_ != buffer_.end()) return *it_++; - - if(matches_.notNull()) { - Match::Ptr match = matches_->next(context); - if(match.isNull()) { - matches_ = 0; + if(matches_) { + if(matches_->next(context)) { + includeBuffer_.push_back(matches_->getStringIncludes()); + excludeBuffer_.push_back(matches_->getStringExcludes()); + includeIt_ = --(includeBuffer_.end()); + excludeIt_ = --(excludeBuffer_.end()); + return true; } - else { - buffer_.push_back(match); - return match; - } } - return 0; + return false; } void BufferedMatches::reset() { - it_ = buffer_.begin(); + reset_ = true; + includeIt_ = includeBuffer_.begin(); + excludeIt_ = excludeBuffer_.begin(); } +AllMatches *BufferedMatches::getAllMatches() +{ + return matches_; +} + FTConjunctionMatches::FTConjunctionMatches(const LocationInfo *info) : AllMatches(info), - toDo_(true) + toDo_(true), + includes_(), + excludes_() { } -void FTConjunctionMatches::addMatches(const AllMatches::Ptr &m) +FTConjunctionMatches::~FTConjunctionMatches() { - args_.push_back(m.notNull() ? new BufferedMatches(this, m) : 0); + deleteMatches(); } -Match::Ptr FTConjunctionMatches::next(DynamicContext *context) +void FTConjunctionMatches::addMatches(AllMatches *m) { + if (m) { + BufferedMatches buf(this, m); + args_.push_back(buf); + } +} + +bool FTConjunctionMatches::next(DynamicContext *context) +{ // TBD need to check for StringInclude / StringExclude contradictions - vector<BufferedMatches::Ptr>::reverse_iterator rend = args_.rend(); - vector<BufferedMatches::Ptr>::reverse_iterator rbegin = args_.rbegin(); - vector<BufferedMatches::Ptr>::reverse_iterator it; + includes_.clear(); + excludes_.clear(); + vector<BufferedMatches>::reverse_iterator rend = args_.rend(); + vector<BufferedMatches>::reverse_iterator rbegin = args_.rbegin(); + vector<BufferedMatches>::reverse_iterator it; bool initialisationState = false; if(toDo_) { @@ -174,8 +196,8 @@ } else { --it; - (*it)->reset(); - if((*it)->next(context).isNull()) { + it->reset(); + if(!it->next(context)) { initialisationState = false; ++it; } @@ -183,11 +205,11 @@ } else { if(it == rend) { - args_.clear(); - return 0; + deleteMatches(); + return false; } else { - if((*it)->next(context).notNull()) { + if(it->next(context)) { initialisationState = true; } else { @@ -197,11 +219,50 @@ } } - Match::Ptr result = new Match(); - for(vector<BufferedMatches::Ptr>::iterator i = args_.begin(); - i != args_.end(); ++i) { - result->add((*i)->current()); + return true; +} + +const StringMatches &FTConjunctionMatches::getStringIncludes() +{ + if (includes_.empty()) { + for(vector<BufferedMatches>::iterator i = args_.begin(); + i != args_.end(); ++i) { + addStringIncludes(i->getStringIncludes()); + } } + return includes_; +} - return result; +const StringMatches &FTConjunctionMatches::getStringExcludes() +{ + if (excludes_.empty()) { + for(vector<BufferedMatches>::iterator i = args_.begin(); + i != args_.end(); ++i) { + addStringExcludes(i->getStringExcludes()); + } + } + return excludes_; } + +void FTConjunctionMatches::deleteMatches() +{ + for (vector<BufferedMatches>::iterator it = args_.begin(); + it != args_.end(); it++) { + delete it->getAllMatches(); + } + args_.clear(); +} + +void FTConjunctionMatches::addStringIncludes(const StringMatches &sMatches) +{ + for(StringMatches::const_iterator j = sMatches.begin(); j != sMatches.end(); ++j) { + includes_.push_back(*j); + } +} + +void FTConjunctionMatches::addStringExcludes(const StringMatches &sMatches) +{ + for(StringMatches::const_iterator j = sMatches.begin(); j != sMatches.end(); ++j) { + excludes_.push_back(*j); + } +} Modified: trunk/xqilla/src/fulltext/FTContains.cpp =================================================================== --- trunk/xqilla/src/fulltext/FTContains.cpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/src/fulltext/FTContains.cpp 2009-07-29 13:51:18 UTC (rev 783) @@ -89,6 +89,7 @@ Result argNodes = parent_->getArgument()->createResult(context); Item::Ptr item; + AllMatches *matches = 0; while((item = argNodes->next(context)).notNull()) { if(!item->isNode()) XQThrow(XPath2TypeMatchException, X("FTContains::FTContainsResult::getSingleResult"), @@ -96,24 +97,24 @@ FTContext ftcontext(&tokenizer, new DefaultTokenStore((Node*)item.get(), &tokenizer, context), context); - AllMatches::Ptr matches = parent_->getSelection()->execute(&ftcontext); - if(matches.notNull()) { + if (matches != 0) delete matches; + matches = parent_->getSelection()->execute(&ftcontext); + if(matches) { StringMatches::const_iterator i; StringMatches::const_iterator end; - Match::Ptr match(0); - while((match = matches->next(context)).notNull()) { + while(matches->next(context)) { bool fail = false; - i = match->getStringIncludes().begin(); - end = match->getStringIncludes().end(); + i = matches->getStringIncludes().begin(); + end = matches->getStringIncludes().end(); for(; i != end; ++i) { - if(i->startToken && i->tokenInfo->getPosition() != + if(i->startToken && i->tokenInfo.position_ != ftcontext.tokenStore->getStartTokenPosition()) { fail = true; break; } - if(i->endToken && i->tokenInfo->getPosition() != + if(i->endToken && i->tokenInfo.position_ != ftcontext.tokenStore->getEndTokenPosition()) { fail = true; break; @@ -122,14 +123,14 @@ if(fail) continue; - i = match->getStringExcludes().begin(); - end = match->getStringExcludes().end(); + i = matches->getStringExcludes().begin(); + end = matches->getStringExcludes().end(); for(; i != end; ++i) { - if(i->startToken && i->tokenInfo->getPosition() != + if(i->startToken && i->tokenInfo.position_ != ftcontext.tokenStore->getStartTokenPosition()) { continue; } - if(i->endToken && i->tokenInfo->getPosition() != + if(i->endToken && i->tokenInfo.position_ != ftcontext.tokenStore->getEndTokenPosition()) { continue; } @@ -139,8 +140,10 @@ if(fail) continue; + delete matches; return context->getItemFactory()->createBoolean(true, context); } + delete matches; } } Modified: trunk/xqilla/src/fulltext/FTContent.cpp =================================================================== --- trunk/xqilla/src/fulltext/FTContent.cpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/src/fulltext/FTContent.cpp 2009-07-29 13:51:18 UTC (rev 783) @@ -58,7 +58,7 @@ return newarg; } -AllMatches::Ptr FTContent::execute(FTContext *ftcontext) const +AllMatches *FTContent::execute(FTContext *ftcontext) const { switch(type_) { case AT_START: @@ -72,95 +72,119 @@ } return 0; } +FTContentAtStartMatches::~FTContentAtStartMatches() +{ + delete arg_; +} -Match::Ptr FTContentAtStartMatches::next(DynamicContext *context) +bool FTContentAtStartMatches::next(DynamicContext *context) { - if(arg_.isNull()) return 0; + if(!arg_) return false; StringMatches::const_iterator smallest; - Match::Ptr match(0); - while(match.isNull()) { - match = arg_->next(context); - if(match.isNull()) { - arg_ = 0; - return 0; - } - - StringMatches::const_iterator i = match->getStringIncludes().begin(); - StringMatches::const_iterator end = match->getStringIncludes().end(); + bool found = false; + while(arg_->next(context)) { + StringMatches::const_iterator i = arg_->getStringIncludes().begin(); + StringMatches::const_iterator end = arg_->getStringIncludes().end(); if(i != end) { smallest = i; + found = true; for(++i; i != end; ++i) { - if(i->tokenInfo->getPosition() < smallest->tokenInfo->getPosition()) { + if(i->tokenInfo.position_ < smallest->tokenInfo.position_) { smallest = i; } } + break; } - else { - match = 0; - } } + if (!found) { + delete arg_; + arg_ = 0; + return false; + } - Match::Ptr result = new Match(); - StringMatches::const_iterator i = match->getStringIncludes().begin(); - StringMatches::const_iterator end = match->getStringIncludes().end(); + includes_.clear(); + StringMatches::const_iterator i = arg_->getStringIncludes().begin(); + StringMatches::const_iterator end = arg_->getStringIncludes().end(); for(; i != end; ++i) { if(i == smallest) { StringMatch sm(*i); sm.startToken = true; - result->addStringInclude(sm); + includes_.push_back(sm); } else { - result->addStringInclude(*i); + includes_.push_back(*i); } } - result->addStringExcludes(match->getStringExcludes()); + return true; +} - return result; +const StringMatches &FTContentAtStartMatches::getStringIncludes() +{ + assert(arg_); + return includes_; } +const StringMatches &FTContentAtStartMatches::getStringExcludes() +{ + assert(arg_); + return arg_->getStringExcludes(); +} -Match::Ptr FTContentAtEndMatches::next(DynamicContext *context) +FTContentAtEndMatches::~FTContentAtEndMatches() { - if(arg_.isNull()) return 0; + delete arg_; +} +bool FTContentAtEndMatches::next(DynamicContext *context) +{ + if(!arg_) return false; + StringMatches::const_iterator largest; - Match::Ptr match(0); - while(match.isNull()) { - match = arg_->next(context); - if(match.isNull()) { - arg_ = 0; - return 0; - } - - StringMatches::const_iterator i = match->getStringIncludes().begin(); - StringMatches::const_iterator end = match->getStringIncludes().end(); + bool found = false; + while(arg_->next(context)) { + StringMatches::const_iterator i = arg_->getStringIncludes().begin(); + StringMatches::const_iterator end = arg_->getStringIncludes().end(); if(i != end) { largest = i; + found = true; for(++i; i != end; ++i) { - if(i->tokenInfo->getPosition() > largest->tokenInfo->getPosition()) { + if(i->tokenInfo.position_ > largest->tokenInfo.position_) { largest = i; } } + break; } - else { - match = 0; - } } + if (!found) { + delete arg_; + arg_ = 0; + return false; + } - Match::Ptr result = new Match(); - StringMatches::const_iterator i = match->getStringIncludes().begin(); - StringMatches::const_iterator end = match->getStringIncludes().end(); + includes_.clear(); + StringMatches::const_iterator i = arg_->getStringIncludes().begin(); + StringMatches::const_iterator end = arg_->getStringIncludes().end(); for(; i != end; ++i) { if(i == largest) { StringMatch sm(*i); sm.endToken = true; - result->addStringInclude(sm); + includes_.push_back(sm); } else { - result->addStringInclude(*i); + includes_.push_back(*i); } } - result->addStringExcludes(match->getStringExcludes()); + return true; +} - return result; +const StringMatches &FTContentAtEndMatches::getStringIncludes() +{ + assert(arg_); + return includes_; } + +const StringMatches &FTContentAtEndMatches::getStringExcludes() +{ + assert(arg_); + return arg_->getStringExcludes(); +} Modified: trunk/xqilla/src/fulltext/FTDistance.cpp =================================================================== --- trunk/xqilla/src/fulltext/FTDistance.cpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/src/fulltext/FTDistance.cpp 2009-07-29 13:51:18 UTC (rev 783) @@ -117,7 +117,7 @@ return newarg; } -AllMatches::Ptr FTDistance::execute(FTContext *ftcontext) const +AllMatches *FTDistance::execute(FTContext *ftcontext) const { Numeric::Ptr num = (Numeric*)range_.arg1->createResult(ftcontext->context)->next(ftcontext->context).get(); @@ -170,7 +170,7 @@ return newarg; } -AllMatches::Ptr FTDistanceLiteral::execute(FTContext *ftcontext) const +AllMatches *FTDistanceLiteral::execute(FTContext *ftcontext) const { switch(type_) { case FTRange::EXACTLY: { @@ -193,23 +193,29 @@ static bool lessThanCompareFn(const StringMatch &first, const StringMatch &second) { - return first.tokenInfo->getPosition() < second.tokenInfo->getPosition(); + return first.tokenInfo.position_ < second.tokenInfo.position_; } -Match::Ptr FTDistanceMatches::next(DynamicContext *context) +FTDistanceMatches::~FTDistanceMatches() { - if(arg_.isNull()) return 0; + delete arg_; +} - Match::Ptr match(0); - while(match.isNull()) { - match = arg_->next(context); - if(match.isNull()) { - arg_ = 0; - return 0; - } +bool FTDistanceMatches::next(DynamicContext *context) +{ + excludes_.clear(); + if(!arg_) return false; - if(match->getStringIncludes().size() > 1) { - StringMatches sMatches = match->getStringIncludes(); + bool found = arg_->next(context); + if (!found) { + delete arg_; + arg_ = 0; + return false; + } + while(found) { + found = false; + if(arg_->getStringIncludes().size() > 1) { + StringMatches sMatches = arg_->getStringIncludes(); std::sort(sMatches.begin(), sMatches.end(), lessThanCompareFn); StringMatches::iterator end = sMatches.end(); @@ -218,29 +224,43 @@ for(; b != end; ++a, ++b) { unsigned int actual = FTOption::tokenDistance(a->tokenInfo, b->tokenInfo, unit_); if(!distanceMatches(actual)) { - match = 0; + found = arg_->next(context); + if (!found) { + delete arg_; + arg_ = 0; + return false; + } break; } } } } - Match::Ptr result = new Match(); - result->addStringIncludes(match->getStringIncludes()); + return true; +} - for(StringMatches::const_iterator i = match->getStringExcludes().begin(); - i != match->getStringExcludes().end(); ++i) { - for(StringMatches::const_iterator j = match->getStringIncludes().begin(); - j != match->getStringIncludes().end(); ++j) { - unsigned int actual = FTOption::tokenDistance(i->tokenInfo, j->tokenInfo, unit_); - if(distanceMatches(actual)) { - result->addStringExclude(*i); - break; +const StringMatches &FTDistanceMatches::getStringIncludes() +{ + assert(arg_); + return arg_->getStringIncludes(); +} + +const StringMatches &FTDistanceMatches::getStringExcludes() +{ + if (arg_ && !excludes_.empty()) { + for(StringMatches::const_iterator i = arg_->getStringExcludes().begin(); + i != arg_->getStringExcludes().end(); ++i) { + for(StringMatches::const_iterator j = arg_->getStringIncludes().begin(); + j != arg_->getStringIncludes().end(); ++j) { + unsigned int actual = FTOption::tokenDistance(i->tokenInfo, j->tokenInfo, unit_); + if(distanceMatches(actual)) { + excludes_.push_back(*i); + break; + } } } } - - return result; + return excludes_; } bool FTDistanceExactlyMatches::distanceMatches(unsigned int actual) const Modified: trunk/xqilla/src/fulltext/FTMildnot.cpp =================================================================== --- trunk/xqilla/src/fulltext/FTMildnot.cpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/src/fulltext/FTMildnot.cpp 2009-07-29 13:51:18 UTC (rev 783) @@ -59,54 +59,69 @@ return result; } -AllMatches::Ptr FTMildnot::execute(FTContext *ftcontext) const +AllMatches *FTMildnot::execute(FTContext *ftcontext) const { - AllMatches::Ptr leftMatches = left_->execute(ftcontext); - AllMatches::Ptr rightMatches = right_->execute(ftcontext); + AllMatches *leftMatches = left_->execute(ftcontext); + AllMatches *rightMatches = right_->execute(ftcontext); return new FTMildnotMatches(this, leftMatches, rightMatches); } -Match::Ptr FTMildnotMatches::next(DynamicContext *context) +FTMildnotMatches::~FTMildnotMatches() { - if(left_.isNull()) return 0; + delete left_; + delete right_; +} - if(right_.notNull()) { - Match::Ptr match(0); - while((match = right_->next(context)).notNull()) { - if(!match->getStringExcludes().empty()) +bool FTMildnotMatches::next(DynamicContext *context) +{ + if(!left_) return false; + + if(right_) { + while(right_->next(context)) { + if(!right_->getStringExcludes().empty()) XQThrow(XPath2ErrorException, X("FTMildnotMatches::next"), X("Invalid expression on the right-hand side of a not-in [err:FTDY0017]")); - StringMatches::const_iterator end = match->getStringIncludes().end(); - for(StringMatches::const_iterator i = match->getStringIncludes().begin(); + StringMatches::const_iterator end = right_->getStringIncludes().end(); + for(StringMatches::const_iterator i = right_->getStringIncludes().begin(); i != end; ++i) { - badTokens_.insert(i->tokenInfo->getPosition()); + badTokens_.insert(i->tokenInfo.position_); } } + delete right_; right_ = 0; } - Match::Ptr match(0); - while(match.isNull()) { - match = left_->next(context); - if(match.isNull()) { - left_ = 0; - return 0; - } - - if(!match->getStringExcludes().empty()) + while(left_->next(context)) { + if(!left_->getStringExcludes().empty()) XQThrow(XPath2ErrorException, X("FTMildnotMatches::next"), X("Invalid expression on the left-hand side of a not-in [err:FTDY0017]")); - StringMatches::const_iterator end = match->getStringIncludes().end(); - for(StringMatches::const_iterator i = match->getStringIncludes().begin(); + bool found = false; + StringMatches::const_iterator end = left_->getStringIncludes().end(); + for(StringMatches::const_iterator i = left_->getStringIncludes().begin(); i != end; ++i) { - if(badTokens_.find(i->tokenInfo->getPosition()) != badTokens_.end()) { - match = 0; + if(badTokens_.find(i->tokenInfo.position_) != badTokens_.end()) { + found = true; break; } } + if (!found) return true; } - return match; + delete left_; + left_ = 0; + return false; } + +const StringMatches &FTMildnotMatches::getStringIncludes() +{ + assert(left_); + return left_->getStringIncludes(); +} + +const StringMatches &FTMildnotMatches::getStringExcludes() +{ + assert(left_); + return left_->getStringExcludes(); +} \ No newline at end of file Modified: trunk/xqilla/src/fulltext/FTOr.cpp =================================================================== --- trunk/xqilla/src/fulltext/FTOr.cpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/src/fulltext/FTOr.cpp 2009-07-29 13:51:18 UTC (rev 783) @@ -83,10 +83,10 @@ return ftor; } -AllMatches::Ptr FTOr::execute(FTContext *ftcontext) const +AllMatches *FTOr::execute(FTContext *ftcontext) const { FTDisjunctionMatches *disjunction = new FTDisjunctionMatches(this); - AllMatches::Ptr result(disjunction); + AllMatches *result(disjunction); for(VectorOfFTSelections::const_iterator i = args_.begin(); i != args_.end(); ++i) { @@ -102,26 +102,44 @@ { } -Match::Ptr FTDisjunctionMatches::next(DynamicContext *context) +FTDisjunctionMatches::~FTDisjunctionMatches() { + for(it_ = args_.begin(); it_ != args_.end(); it_++) { + delete *(it_); + } +} + +bool FTDisjunctionMatches::next(DynamicContext *context) +{ // TBD AllMatches normalization - if(toDo_) { toDo_ = false; it_ = args_.begin(); } - Match::Ptr result(0); + bool found = false; while(it_ != args_.end()) { - result = (*it_)->next(context); - if(result.isNull()) { + if(!(*it_)->next(context)) { + delete *(it_); *it_ = 0; ++it_; } else { + found = true; break; } } - return result; + return found; } + +const StringMatches &FTDisjunctionMatches::getStringIncludes() +{ + assert(it_ != args_.end()); + return (*it_)->getStringIncludes(); +} +const StringMatches &FTDisjunctionMatches::getStringExcludes() +{ + assert(it_ != args_.end()); + return (*it_)->getStringExcludes(); +} Modified: trunk/xqilla/src/fulltext/FTOrder.cpp =================================================================== --- trunk/xqilla/src/fulltext/FTOrder.cpp 2009-07-20 13:59:32 UTC (rev 782) +++ trunk/xqilla/src/fulltext/FTOrder.cpp 2009-07-29 13:51:18 UTC (rev 783) @@ -50,53 +50,74 @@ return newarg; } -AllMatches::Ptr FTOrder::execute(FTContext *ftcontext) const +AllMatches *FTOrder::execute(FTContext *ftcontext) const { return new FTOrderMatches(this, arg_->execute(ftcontext)); } -Match::Ptr FTOrderMatches::next(DynamicContext *context) +FTOrderMatches::~FTOrderMatches() { - if(arg_.isNull()) return 0; + delete arg_; +} - Match::Ptr match(0); - while(match.isNull()) { - match = arg_->next(context); - if(match.isNull()) { - arg_ = 0; - return 0; - } +bool FTOrderMatches::next(DynamicContext *context) +{ + excludes_.clear(); + if(!arg_) return false; - StringMatches::const_iterator begin = match->getStringIncludes().begin(); - StringMatches::const_iterator end = match->getStringIncludes().end(); + bool found = arg_->next(context); + if (!found) { + delete arg_; + arg_ = 0; + return false; + } + while(found) { + found = false; + StringMatches::const_iterator begin = arg_->getStringIncludes().begin(); + StringMatches::const_iterator end = arg_->getStringIncludes().end(); StringMatches::const_iterator i, j; - for(i = begin; i != end && match.notNull(); ++i) { + for(i = begin; i != end; ++i) { for(j = i, ++j; j != end; ++j) { - if((i->queryPos > j->queryPos && i->tokenInfo->getPosition() < j->tokenInfo->getPosition()) || - (i->queryPos < j->queryPos && i->tokenInfo->getPosition() > j->tokenInfo->getPosition())) { - match = 0; + if((i->queryPos > j->queryPos && i->tokenInfo.position_ < j->tokenInfo.position_) || + (i->queryPos < j->queryPos && i->tokenInfo.position_ > j->tokenInfo.position_)) { + found = arg_->next(context); + if (!found) { + delete arg_; + arg_ = 0; + return false; + } break; } } + if (found) break; } } - Match::Ptr result = new Match(); - result->addStringIncludes(match->getStringIncludes()); + return true; +} - StringMatches::const_iterator e_end = match->getStringExcludes().end(); - StringMatches::const_iterator e = match->getStringExcludes().begin(); - StringMatches::const_iterator i_begin = match->getStringIncludes().begi... [truncated message content] |