LCOV - code coverage report
Current view: top level - backends/inmemory - inmemory_alltermslist.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 7028d852e609 Lines: 27 38 71.1 %
Date: 2019-02-17 14:59:59 Functions: 5 7 71.4 %
Branches: 44 74 59.5 %

           Branch data     Line data    Source code
       1                 :            : /** @file inmemory_alltermslist.cc
       2                 :            :  * @brief Iterate all terms in an inmemory db
       3                 :            :  */
       4                 :            : /* Copyright 1999,2000,2001 BrightStation PLC
       5                 :            :  * Copyright 2003,2004,2007,2008,2009,2017 Olly Betts
       6                 :            :  *
       7                 :            :  * This program is free software; you can redistribute it and/or
       8                 :            :  * modify it under the terms of the GNU General Public License as
       9                 :            :  * published by the Free Software Foundation; either version 2 of the
      10                 :            :  * License, or (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
      20                 :            :  * USA
      21                 :            :  */
      22                 :            : 
      23                 :            : #include <config.h>
      24                 :            : #include "inmemory_alltermslist.h"
      25                 :            : 
      26                 :            : #include "stringutils.h"
      27                 :            : 
      28                 :            : Xapian::termcount
      29                 :          0 : InMemoryAllTermsList::get_approx_size() const
      30                 :            : {
      31                 :            :     // This may be an over-estimate due to deleted entries, and we may be
      32                 :            :     // restricted to a prefix, but we only use this value to build a balanced
      33                 :            :     // or-tree, and it'll do a decent job for that.
      34                 :          0 :     return tmap->size();
      35                 :            : }
      36                 :            : 
      37                 :            : string
      38                 :       1205 : InMemoryAllTermsList::get_termname() const
      39                 :            : {
      40         [ +  + ]:       1205 :     if (database->is_closed()) InMemoryDatabase::throw_database_closed();
      41                 :            :     Assert(!at_end());
      42                 :            :     Assert(!it->first.empty());
      43                 :       1204 :     return it->first;
      44                 :            : }
      45                 :            : 
      46                 :            : Xapian::doccount
      47                 :        181 : InMemoryAllTermsList::get_termfreq() const
      48                 :            : {
      49         [ +  + ]:        181 :     if (database->is_closed()) InMemoryDatabase::throw_database_closed();
      50                 :            :     Assert(!at_end());
      51                 :            :     Assert(!it->first.empty());
      52                 :            :     /* FIXME: this isn't quite right. */
      53                 :        180 :     return it->second.docs.size();
      54                 :            : }
      55                 :            : 
      56                 :            : Xapian::termcount
      57                 :          0 : InMemoryAllTermsList::get_collection_freq() const
      58                 :            : {
      59         [ #  # ]:          0 :     if (database->is_closed()) InMemoryDatabase::throw_database_closed();
      60                 :            :     Assert(!at_end());
      61                 :            :     Assert(!it->first.empty());
      62 [ #  # ][ #  # ]:          0 :     throw Xapian::UnimplementedError("Collection frequency not implemented in InMemory backend");
                 [ #  # ]
      63                 :            : }
      64                 :            : 
      65                 :            : TermList *
      66                 :          6 : InMemoryAllTermsList::skip_to(const string &tname_)
      67                 :            : {
      68         [ -  + ]:          6 :     if (database->is_closed()) InMemoryDatabase::throw_database_closed();
      69         [ +  - ]:          6 :     string tname(tname_);
      70                 :            :     Assert(it != tmap->end());
      71         [ +  - ]:          6 :     if (!it->first.empty()) {
      72                 :            :         // Don't skip backwards.
      73 [ +  - ][ +  + ]:          6 :         if (tname <= it->first) return NULL;
      74                 :            :     } else {
      75                 :            :         // Don't skip to before where we're supposed to start.
      76 [ #  # ][ #  # ]:          0 :         if (tname < prefix) {
      77         [ #  # ]:          0 :             tname = prefix;
      78         [ #  # ]:          0 :         } else if (tname.empty()) {
      79                 :          0 :             ++it;
      80                 :          0 :             return NULL;
      81                 :            :         }
      82                 :            :     }
      83         [ +  - ]:          4 :     it = tmap->lower_bound(tname);
      84 [ +  + ][ -  + ]:          4 :     while (it != tmap->end() && it->second.term_freq == 0) ++it;
         [ +  - ][ -  + ]
      85 [ +  + ][ -  + ]:          4 :     if (it != tmap->end() && !startswith(it->first, prefix))
         [ +  - ][ -  + ]
      86                 :          0 :         it = tmap->end();
      87                 :          6 :     return NULL;
      88                 :            : }
      89                 :            : 
      90                 :            : TermList *
      91                 :        772 : InMemoryAllTermsList::next()
      92                 :            : {
      93         [ +  + ]:        772 :     if (database->is_closed()) InMemoryDatabase::throw_database_closed();
      94                 :            :     Assert(it != tmap->end());
      95 [ +  + ][ +  + ]:        771 :     if (it->first.empty() && !prefix.empty()) {
                 [ +  + ]
      96                 :         70 :         it = tmap->lower_bound(prefix);
      97                 :            :     } else {
      98                 :        701 :         ++it;
      99                 :            :     }
     100 [ +  + ][ +  + ]:        794 :     while (it != tmap->end() && it->second.term_freq == 0) ++it;
         [ +  - ][ +  + ]
     101 [ +  + ][ +  + ]:        771 :     if (it != tmap->end() && !startswith(it->first, prefix))
         [ +  - ][ +  + ]
     102                 :         47 :         it = tmap->end();
     103                 :        771 :     return NULL;
     104                 :            : }
     105                 :            : 
     106                 :            : bool
     107                 :        782 : InMemoryAllTermsList::at_end() const
     108                 :            : {
     109         [ -  + ]:        782 :     if (database->is_closed()) InMemoryDatabase::throw_database_closed();
     110                 :            :     Assert(it == tmap->end() || !it->first.empty());
     111                 :        782 :     return (it == tmap->end());
     112                 :            : }
     113                 :            : 
     114                 :            : #ifdef DISABLE_GPL_LIBXAPIAN
     115                 :            : # error GPL source we cannot relicense included in libxapian
     116                 :            : #endif

Generated by: LCOV version 1.11