LCOV - code coverage report
Current view: top level - backends/chert - chert_record.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 15 21 71.4 %
Date: 2011-08-21 Functions: 4 5 80.0 %
Branches: 4 6 66.7 %

           Branch data     Line data    Source code
       1                 :            : /* chert_record.cc: Records in chert databases
       2                 :            :  *
       3                 :            :  * Copyright 2002 Ananova Ltd
       4                 :            :  * Copyright 2002,2003,2004,2005,2008 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                 :            : 
      24                 :            : #include "chert_record.h"
      25                 :            : 
      26                 :            : #include <xapian/error.h>
      27                 :            : #include "debuglog.h"
      28                 :            : #include "omassert.h"
      29                 :            : #include "pack.h"
      30                 :            : #include "str.h"
      31                 :            : 
      32                 :            : using std::string;
      33                 :            : 
      34                 :            : inline string
      35                 :          0 : make_key(Xapian::docid did)
      36                 :            : {
      37                 :          0 :     string key;
      38                 :          0 :     pack_uint_preserving_sort(key, did);
      39                 :          0 :     return key;
      40                 :            : }
      41                 :            : 
      42                 :            : string
      43                 :     151669 : ChertRecordTable::get_record(Xapian::docid did) const
      44                 :            : {
      45                 :            :     LOGCALL(DB, string, "ChertRecordTable::get_record", did);
      46                 :     151669 :     string tag;
      47                 :            : 
      48         [ -  + ]:     151669 :     if (!get_exact_entry(make_key(did), tag)) {
      49                 :     151669 :         throw Xapian::DocNotFoundError("Document " + str(did) + " not found.");
      50                 :            :     }
      51                 :            : 
      52                 :          0 :     RETURN(tag);
      53                 :            : }
      54                 :            : 
      55                 :            : Xapian::doccount
      56                 :     226095 : ChertRecordTable::get_doccount() const
      57                 :            : {   
      58                 :            :     LOGCALL(DB, Xapian::doccount, "ChertRecordTable::get_doccount", NO_ARGS);
      59                 :     226095 :     chert_tablesize_t count = get_entry_count();
      60         [ -  + ]:     226095 :     if (rare(count > chert_tablesize_t(Xapian::doccount(-1)))) {
      61                 :            :         // If we've got more entries than there are possible docids, the
      62                 :            :         // database is in an odd state.
      63                 :          0 :         throw Xapian::DatabaseCorruptError("Impossibly many entries in the record table");
      64                 :            :     }
      65                 :     226095 :     RETURN(Xapian::doccount(count));
      66                 :            : }
      67                 :            : 
      68                 :            : void
      69                 :      77490 : ChertRecordTable::replace_record(const string & data, Xapian::docid did)
      70                 :            : {
      71                 :            :     LOGCALL_VOID(DB, "ChertRecordTable::replace_record", data | did);
      72                 :      77490 :     add(make_key(did), data);
      73                 :      77490 : }
      74                 :            : 
      75                 :            : void
      76                 :       9894 : ChertRecordTable::delete_record(Xapian::docid did)
      77                 :            : {
      78                 :            :     LOGCALL_VOID(DB, "ChertRecordTable::delete_record", did);
      79         [ +  + ]:       9894 :     if (!del(make_key(did)))
      80                 :          3 :         throw Xapian::DocNotFoundError("Can't delete non-existent document #" + str(did));
      81                 :       9891 : }

Generated by: LCOV version 1.8