LCOV - code coverage report
Current view: top level - backends/brass - brass_inverter.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 24 29 82.8 %
Date: 2011-08-21 Functions: 5 5 100.0 %
Branches: 5 8 62.5 %

           Branch data     Line data    Source code
       1                 :            : /** @file brass_inverter.cc
       2                 :            :  * @brief Inverter class which "inverts the file".
       3                 :            :  */
       4                 :            : /* Copyright (C) 2009 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or modify
       7                 :            :  * it under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation; either version 2 of the License, or
       9                 :            :  * (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program; if not, write to the Free Software
      18                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      19                 :            :  */
      20                 :            : 
      21                 :            : #include <config.h>
      22                 :            : 
      23                 :            : #include "brass_inverter.h"
      24                 :            : 
      25                 :            : #include "brass_postlist.h"
      26                 :            : 
      27                 :            : #include <map>
      28                 :            : #include <string>
      29                 :            : 
      30                 :            : using namespace std;
      31                 :            : 
      32                 :            : void
      33                 :        462 : Inverter::flush_doclengths(BrassPostListTable & table)
      34                 :            : {
      35                 :        462 :     table.merge_doclen_changes(doclen_changes);
      36                 :        462 :     doclen_changes.clear();
      37                 :        462 : }
      38                 :            : 
      39                 :            : void
      40                 :        351 : Inverter::flush_post_list(BrassPostListTable & table, const string & term)
      41                 :            : {
      42                 :        351 :     map<string, PostingChanges>::iterator i;
      43                 :        351 :     i = postlist_changes.find(term);
      44         [ +  + ]:        351 :     if (i == postlist_changes.end()) return;
      45                 :            : 
      46                 :            :     // Flush buffered changes for just this term's postlist.
      47                 :         80 :     table.merge_changes(term, i->second);
      48                 :        351 :     postlist_changes.erase(i);
      49                 :            : }
      50                 :            : 
      51                 :            : void
      52                 :        483 : Inverter::flush_all_post_lists(BrassPostListTable & table)
      53                 :            : {
      54                 :        483 :     map<string, PostingChanges>::const_iterator i;
      55         [ +  + ]:      21944 :     for (i = postlist_changes.begin(); i != postlist_changes.end(); ++i) {
      56                 :      21469 :         table.merge_changes(i->first, i->second);
      57                 :            :     }
      58                 :        475 :     postlist_changes.clear();
      59                 :        475 : }
      60                 :            : 
      61                 :            : void
      62                 :         51 : Inverter::flush_post_lists(BrassPostListTable & table, const string & pfx)
      63                 :            : {
      64         [ +  - ]:         51 :     if (pfx.empty())
      65                 :         51 :         return flush_all_post_lists(table);
      66                 :            : 
      67                 :          0 :     map<string, PostingChanges>::iterator i, begin, end;
      68                 :          0 :     begin = postlist_changes.lower_bound(pfx);
      69                 :          0 :     end = postlist_changes.upper_bound(pfx);
      70                 :            : 
      71         [ #  # ]:          0 :     for (i = begin; i != end; ++i) {
      72                 :          0 :         table.merge_changes(i->first, i->second);
      73                 :            :     }
      74                 :            : 
      75                 :            :     // Erase all the entries in one go, as that's:
      76                 :            :     //  O(log(postlist_changes.size()) + O(number of elements removed)
      77                 :         51 :     postlist_changes.erase(begin, end);
      78                 :            : }
      79                 :            : 
      80                 :            : void
      81                 :        432 : Inverter::flush(BrassPostListTable & table)
      82                 :            : {
      83                 :        432 :     flush_doclengths(table);
      84                 :        432 :     flush_all_post_lists(table);
      85                 :        424 : }

Generated by: LCOV version 1.8