LCOV - code coverage report
Current view: top level - backends/inmemory - inmemory_alltermslist.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 27 36 75.0 %
Date: 2011-08-21 Functions: 5 6 83.3 %
Branches: 34 50 68.0 %

           Branch data     Line data    Source code
       1                 :            : /* inmemoryalltermslist.cc
       2                 :            :  *
       3                 :            :  * Copyright 1999,2000,2001 BrightStation PLC
       4                 :            :  * Copyright 2003,2004,2007,2008,2009 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU General Public License as
       8                 :            :  * published by the Free Software Foundation; either version 2 of the
       9                 :            :  * License, or (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
      19                 :            :  * USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <config.h>
      23                 :            : #include "inmemory_alltermslist.h"
      24                 :            : 
      25                 :            : #include "stringutils.h"
      26                 :            : 
      27                 :            : string
      28                 :        601 : InMemoryAllTermsList::get_termname() const
      29                 :            : {
      30         [ -  + ]:        601 :     if (database->is_closed()) InMemoryDatabase::throw_database_closed();
      31                 :            :     Assert(!at_end());
      32                 :            :     Assert(!it->first.empty());
      33                 :        601 :     return it->first;
      34                 :            : }
      35                 :            : 
      36                 :            : Xapian::doccount
      37                 :         65 : InMemoryAllTermsList::get_termfreq() const
      38                 :            : {
      39         [ -  + ]:         65 :     if (database->is_closed()) InMemoryDatabase::throw_database_closed();
      40                 :            :     Assert(!at_end());
      41                 :            :     Assert(!it->first.empty());
      42                 :            :     /* FIXME: this isn't quite right. */
      43                 :         65 :     return it->second.docs.size();
      44                 :            : }
      45                 :            : 
      46                 :            : Xapian::termcount
      47                 :          0 : InMemoryAllTermsList::get_collection_freq() const
      48                 :            : {
      49         [ #  # ]:          0 :     if (database->is_closed()) InMemoryDatabase::throw_database_closed();
      50                 :            :     Assert(!at_end());
      51                 :            :     Assert(!it->first.empty());
      52                 :          0 :     throw Xapian::UnimplementedError("Collection frequency not implemented in InMemory backend");
      53                 :            : }
      54                 :            : 
      55                 :            : TermList *
      56                 :          6 : InMemoryAllTermsList::skip_to(const string &tname_)
      57                 :            : {
      58         [ -  + ]:          6 :     if (database->is_closed()) InMemoryDatabase::throw_database_closed();
      59                 :          6 :     string tname(tname_);
      60                 :            :     Assert(it != tmap->end());
      61         [ +  - ]:          6 :     if (!it->first.empty()) {
      62                 :            :         // Don't skip backwards.
      63         [ +  + ]:          6 :         if (tname <= it->first) return NULL;
      64                 :            :     } else {
      65                 :            :         // Don't skip to before where we're supposed to start.
      66         [ #  # ]:          0 :         if (tname < prefix) {
      67                 :          0 :             tname = prefix;
      68         [ #  # ]:          0 :         } else if (tname.empty()) {
      69                 :          0 :             ++it;
      70                 :          0 :             return NULL;
      71                 :            :         }
      72                 :            :     }
      73                 :          4 :     it = tmap->lower_bound(tname);
      74 [ +  + ][ -  + ]:          4 :     while (it != tmap->end() && it->second.term_freq == 0) ++it;
                 [ -  + ]
      75 [ +  + ][ -  + ]:          4 :     if (it != tmap->end() && !startswith(it->first, prefix))
                 [ -  + ]
      76                 :          0 :         it = tmap->end();
      77                 :          6 :     return NULL;
      78                 :            : }
      79                 :            : 
      80                 :            : TermList *
      81                 :        315 : InMemoryAllTermsList::next()
      82                 :            : {
      83         [ -  + ]:        315 :     if (database->is_closed()) InMemoryDatabase::throw_database_closed();
      84                 :            :     Assert(it != tmap->end());
      85 [ +  + ][ +  + ]:        315 :     if (it->first.empty() && !prefix.empty()) {
                 [ +  + ]
      86                 :         97 :         it = tmap->lower_bound(prefix);
      87                 :            :     } else {
      88                 :        218 :         ++it;
      89                 :            :     }
      90 [ +  + ][ +  + ]:        338 :     while (it != tmap->end() && it->second.term_freq == 0) ++it;
                 [ +  + ]
      91 [ +  + ][ +  + ]:        315 :     if (it != tmap->end() && !startswith(it->first, prefix))
                 [ +  + ]
      92                 :         78 :         it = tmap->end();
      93                 :        315 :     return NULL;
      94                 :            : }
      95                 :            : 
      96                 :            : bool
      97                 :        326 : InMemoryAllTermsList::at_end() const
      98                 :            : {
      99         [ -  + ]:        326 :     if (database->is_closed()) InMemoryDatabase::throw_database_closed();
     100                 :            :     Assert(it == tmap->end() || !it->first.empty());
     101                 :        326 :     return (it == tmap->end());
     102                 :            : }

Generated by: LCOV version 1.8