matcher/branchpostlist.h

Go to the documentation of this file.
00001 /* branchpostlist.h: virtual base class for branched types of postlist
00002  *
00003  * Copyright 1999,2000,2001 BrightStation PLC
00004  * Copyright 2002 Ananova Ltd
00005  * Copyright 2003,2004,2007 Olly Betts
00006  * Copyright 2007 Lemur Consulting Ltd
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as
00010  * published by the Free Software Foundation; either version 2 of the
00011  * License, or (at your option) any later version.
00012  *
00013  * This program is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00021  * USA
00022  */
00023 
00024 #ifndef OM_HGUARD_BRANCHPOSTLIST_H
00025 #define OM_HGUARD_BRANCHPOSTLIST_H
00026 
00027 #include "multimatch.h"
00028 #include "postlist.h"
00029 
00037 class BranchPostList : public PostList {
00038     private:
00039         // Prevent copying
00040         BranchPostList(const BranchPostList &);
00041         BranchPostList & operator=(const BranchPostList &);
00042 
00043     protected:
00045         PostList *l;
00046 
00048         PostList *r;
00049 
00055         MultiMatch *matcher;
00056 
00060         void handle_prune(PostList *&kid, PostList *ret) {
00061             if (ret) {
00062                 delete kid;
00063                 kid = ret;
00064 
00065                 // now tell matcher that maximum weights need recalculation.
00066                 matcher->recalc_maxweight();
00067             }
00068         }
00069 
00070     public:
00071         BranchPostList(PostList *l_, PostList *r_, MultiMatch *matcher_)
00072                 : l(l_), r(r_), matcher(matcher_) {}
00073 
00074         virtual ~BranchPostList();
00075 
00081         virtual Xapian::termcount get_wdf() const;
00082 };
00083 
00084 // Helper functions - call next/skip_to on a postlist and handle any
00085 // resulting prune
00086 // 
00087 // Returns true iff a prune was handled, so the caller can recalculate
00088 // weights etc if necessary
00089 inline bool
00090 next_handling_prune(PostList * & pl, Xapian::weight w_min,
00091                     MultiMatch *matcher)
00092 {
00093     PostList *p = pl->next(w_min);
00094     if (!p) return false;
00095     delete pl;
00096     pl = p;
00097     // now tell matcher that maximum weights need recalculation.
00098     if (matcher) matcher->recalc_maxweight();
00099     return true;
00100 }
00101 
00102 inline bool
00103 skip_to_handling_prune(PostList * & pl, Xapian::docid did, Xapian::weight w_min,
00104                        MultiMatch *matcher)
00105 {
00106     PostList *p = pl->skip_to(did, w_min);
00107     if (!p) return false;
00108     delete pl;
00109     pl = p;
00110     // now tell matcher that maximum weights need recalculation.
00111     if (matcher) matcher->recalc_maxweight();
00112     return true;
00113 }
00114 
00115 #endif /* OM_HGUARD_BRANCHPOSTLIST_H */

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.