LCOV - code coverage report
Current view: top level - backends/chert - chert_alldocsmodifiedpostlist.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 39 50 78.0 %
Date: 2011-08-21 Functions: 7 9 77.8 %
Branches: 37 54 68.5 %

           Branch data     Line data    Source code
       1                 :            : /** @file chert_alldocsmodifiedpostlist.cc
       2                 :            :  * @brief A ChertAllDocsPostList plus pending modifications.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2008 Lemur Consulting Ltd
       5                 :            :  * Copyright (C) 2006,2007,2008,2009,2010 Olly Betts
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or modify
       8                 :            :  * it under the terms of the GNU General Public License as published by
       9                 :            :  * the Free Software Foundation; either version 2 of the License, or
      10                 :            :  * (at your option) any later version.
      11                 :            :  *
      12                 :            :  * This program is distributed in the hope that it will be useful,
      13                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15                 :            :  * GNU General Public License for more details.
      16                 :            :  *
      17                 :            :  * You should have received a copy of the GNU General Public License
      18                 :            :  * along with this program; if not, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <config.h>
      23                 :            : #include "chert_alldocsmodifiedpostlist.h"
      24                 :            : 
      25                 :            : #include "chert_database.h"
      26                 :            : #include "debuglog.h"
      27                 :            : #include "str.h"
      28                 :            : 
      29                 :            : using namespace std;
      30                 :            : 
      31                 :         24 : ChertAllDocsModifiedPostList::ChertAllDocsModifiedPostList(Xapian::Internal::RefCntPtr<const ChertDatabase> db_,
      32                 :            :                                                            Xapian::doccount doccount_,
      33                 :            :                                                            const map<Xapian::docid, Xapian::termcount> & doclens_)
      34                 :            :         : ChertAllDocsPostList(db_, doccount_),
      35                 :            :           doclens(doclens_),
      36                 :         24 :           doclens_it(doclens.begin())
      37                 :            : {
      38                 :            :     LOGCALL_CTOR(DB, "ChertAllDocsModifiedPostList", db_.get() | doccount_ | doclens_);
      39                 :         24 : }
      40                 :            : 
      41                 :            : void
      42                 :       3086 : ChertAllDocsModifiedPostList::skip_deletes(Xapian::weight w_min)
      43                 :            : {
      44                 :            :     LOGCALL_VOID(DB, "ChertAllDocsModifiedPostList::skip_deletes", w_min);
      45         [ +  + ]:       3104 :     while (!ChertAllDocsPostList::at_end()) {
      46         [ -  + ]:       2057 :         if (doclens_it == doclens.end()) return;
      47         [ +  + ]:       2057 :         if (doclens_it->first != ChertAllDocsPostList::get_docid()) return;
      48         [ -  + ]:         18 :         if (doclens_it->second != static_cast<Xapian::termcount>(-1)) return;
      49                 :         18 :         ++doclens_it;
      50                 :         18 :         ChertAllDocsPostList::next(w_min);
      51                 :            :     }
      52 [ +  + ][ +  + ]:       3092 :     while (doclens_it != doclens.end() && doclens_it->second == static_cast<Xapian::termcount>(-1)) {
                 [ +  + ]
      53                 :          6 :         ++doclens_it;
      54                 :            :     }
      55                 :            : }
      56                 :            : 
      57                 :            : Xapian::docid
      58                 :       4070 : ChertAllDocsModifiedPostList::get_docid() const
      59                 :            : {
      60                 :            :     LOGCALL(DB, Xapian::docid, "ChertAllDocsModifiedPostList::get_docid()", NO_ARGS);
      61         [ -  + ]:       4070 :     if (doclens_it == doclens.end()) RETURN(ChertAllDocsPostList::get_docid());
      62         [ +  + ]:       4070 :     if (ChertAllDocsPostList::at_end()) RETURN(doclens_it->first);
      63                 :       4070 :     RETURN(min(doclens_it->first, ChertAllDocsPostList::get_docid()));
      64                 :            : }
      65                 :            : 
      66                 :            : Xapian::termcount
      67                 :          5 : ChertAllDocsModifiedPostList::get_doclength() const
      68                 :            : {
      69                 :            :     LOGCALL(DB, Xapian::termcount, "ChertAllDocsModifiedPostList::get_doclength", NO_ARGS);
      70                 :            :     // Override with value from doclens_it (which cannot be -1, because that
      71                 :            :     // would have been skipped past).
      72 [ +  - ][ +  + ]:          5 :     if (doclens_it != doclens.end() &&
         [ -  + ][ +  + ]
      73                 :            :         (ChertAllDocsPostList::at_end() ||
      74                 :            :          doclens_it->first <= ChertAllDocsPostList::get_docid()))
      75                 :          4 :         RETURN(doclens_it->second);
      76                 :            : 
      77                 :          5 :     RETURN(ChertAllDocsPostList::get_doclength());
      78                 :            : }
      79                 :            : 
      80                 :            : PostList *
      81                 :       3085 : ChertAllDocsModifiedPostList::next(Xapian::weight w_min)
      82                 :            : {
      83                 :            :     LOGCALL(DB, PostList *, "ChertAllDocsModifiedPostList::next", w_min);
      84         [ +  + ]:       3085 :     if (have_started) {
      85         [ +  + ]:       3061 :         if (ChertAllDocsPostList::at_end()) {
      86                 :       1022 :             ++doclens_it;
      87                 :       1022 :             skip_deletes(w_min);
      88                 :       1022 :             RETURN(NULL);
      89                 :            :         }
      90                 :       2039 :         Xapian::docid unmod_did = ChertAllDocsPostList::get_docid();
      91   [ +  -  -  + ]:       2039 :         if (doclens_it != doclens.end() && doclens_it->first <= unmod_did) {
                 [ -  + ]
      92 [ #  # ][ #  # ]:          0 :             if (doclens_it->first < unmod_did &&
                 [ #  # ]
      93                 :            :                 doclens_it->second != static_cast<Xapian::termcount>(-1)) {
      94                 :          0 :                 ++doclens_it;
      95                 :          0 :                 skip_deletes(w_min);
      96                 :          0 :                 RETURN(NULL);
      97                 :            :             }
      98                 :          0 :             ++doclens_it;
      99                 :            :         }
     100                 :            :     }
     101                 :       2063 :     ChertAllDocsPostList::next(w_min);
     102                 :       2063 :     skip_deletes(w_min);
     103                 :       3085 :     RETURN(NULL);
     104                 :            : }
     105                 :            : 
     106                 :            : PostList *
     107                 :          1 : ChertAllDocsModifiedPostList::skip_to(Xapian::docid desired_did,
     108                 :            :                                       Xapian::weight w_min)
     109                 :            : {
     110                 :            :     LOGCALL(DB, PostList *, "ChertAllDocsModifiedPostList::skip_to", desired_did | w_min);
     111         [ -  + ]:          1 :     if (!ChertAllDocsPostList::at_end())
     112                 :          0 :         ChertAllDocsPostList::skip_to(desired_did, w_min);
     113                 :            :     /* FIXME: should we use lower_bound() on the map? */
     114 [ +  - ][ +  + ]:         11 :     while (doclens_it != doclens.end() && doclens_it->first < desired_did) {
                 [ +  + ]
     115                 :         10 :         ++doclens_it;
     116                 :            :     }
     117                 :          1 :     skip_deletes(w_min);
     118                 :          1 :     RETURN(NULL);
     119                 :            : }
     120                 :            : 
     121                 :            : bool
     122                 :       3086 : ChertAllDocsModifiedPostList::at_end() const
     123                 :            : {
     124                 :            :     LOGCALL(DB, bool, "ChertAllDocsModifiedPostList::end", NO_ARGS);
     125 [ +  + ][ +  - ]:       3086 :     RETURN(doclens_it == doclens.end() && ChertAllDocsPostList::at_end());
     126                 :            : }
     127                 :            : 
     128                 :            : string
     129                 :          0 : ChertAllDocsModifiedPostList::get_description() const
     130                 :            : {
     131                 :          0 :     string desc = "ChertAllDocsModifiedPostList(did=";
     132                 :          0 :     desc += str(get_docid());
     133                 :          0 :     desc += ')';
     134                 :          0 :     return desc;
     135                 :            : }

Generated by: LCOV version 1.8