LCOV - code coverage report
Current view: top level - backends/brass - brass_dbstats.cc (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 20 22 90.9 %
Date: 2011-08-21 Functions: 4 4 100.0 %
Branches: 11 22 50.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file brass_dbstats.cc
       2                 :            :  * @brief Brass class for database statistics.
       3                 :            :  */
       4                 :            : /* Copyright (C) 2009 Olly Betts
       5                 :            :  * Copyright (C) 2011 Dan Colish
       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 USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #include <config.h>
      23                 :            : 
      24                 :            : #include "brass_dbstats.h"
      25                 :            : 
      26                 :            : #include "brass_postlist.h"
      27                 :            : 
      28                 :            : using namespace std;
      29                 :            : 
      30                 :            : /// The key in the postlist table which we use to store our encoded statistics.
      31                 :       2335 : static const string DATABASE_STATS_KEY(1, '\0');
      32                 :            : 
      33                 :            : void
      34                 :       2076 : BrassDatabaseStats::read(BrassPostListTable & postlist_table)
      35                 :            : {
      36                 :       2076 :     string data;
      37         [ +  + ]:       2076 :     if (!postlist_table.get_exact_entry(DATABASE_STATS_KEY, data)) {
      38                 :            :         // If there's no entry yet, then all the values are zero.
      39                 :        575 :         zero();
      40                 :            :         return;
      41                 :            :     }
      42                 :            : 
      43                 :       1501 :     const char * p = data.data();
      44                 :       1501 :     const char * end = p + data.size();
      45                 :            : 
      46   [ +  -  +  - ]:       1501 :     if (unpack_uint(&p, end, &last_docid) &&
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      47                 :            :         unpack_uint(&p, end, &doclen_lbound) &&
      48                 :            :         unpack_uint(&p, end, &wdf_ubound) &&
      49                 :            :         unpack_uint(&p, end, &doclen_ubound) &&
      50                 :            :         unpack_uint(&p, end, &oldest_changeset) &&
      51                 :            :         unpack_uint_last(&p, end, &total_doclen)) {
      52                 :            :         // doclen_ubound should always be >= wdf_ubound, so we store the
      53                 :            :         // difference as it may encode smaller.  wdf_ubound is likely to
      54                 :            :         // be larger than doclen_lbound.
      55                 :       1501 :         doclen_ubound += wdf_ubound;
      56                 :            :         return;
      57                 :            :     }
      58                 :            : 
      59         [ #  # ]:          0 :     if (p)
      60                 :          0 :         throw Xapian::DatabaseCorruptError("Bad encoded DB stats (overflowed)");
      61                 :            : 
      62                 :       2076 :     throw Xapian::DatabaseCorruptError("Bad encoded DB stats (out of data)");
      63                 :            : }
      64                 :            : 
      65                 :            : void
      66                 :        432 : BrassDatabaseStats::write(BrassPostListTable & postlist_table) const
      67                 :            : {
      68                 :        432 :     string data;
      69                 :        432 :     pack_uint(data, last_docid);
      70                 :        432 :     pack_uint(data, doclen_lbound);
      71                 :        432 :     pack_uint(data, wdf_ubound);
      72                 :            :     // doclen_ubound should always be >= wdf_ubound, so we store the
      73                 :            :     // difference as it may encode smaller.  wdf_ubound is likely to
      74                 :            :     // be larger than doclen_lbound.
      75                 :        432 :     pack_uint(data, doclen_ubound - wdf_ubound);
      76                 :        432 :     pack_uint(data, oldest_changeset);
      77                 :            :     // Micro-optimisation: total_doclen is likely to be the largest value, so
      78                 :            :     // store it last as pack_uint_last() uses a slightly more compact encoding
      79                 :            :     // - this could save us a few bytes!
      80                 :        432 :     pack_uint_last(data, total_doclen);
      81                 :        432 :     postlist_table.add(DATABASE_STATS_KEY, data);
      82 [ +  - ][ +  - ]:       7437 : }

Generated by: LCOV version 1.8