LCOV - code coverage report
Current view: top level - backends/brass - brass_dbstats.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 38 38 100.0 %
Date: 2011-08-21 Functions: 14 14 100.0 %
Branches: 12 12 100.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file brass_dbstats.h
       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                 :            : #ifndef XAPIAN_INCLUDED_BRASS_DBSTATS_H
      23                 :            : #define XAPIAN_INCLUDED_BRASS_DBSTATS_H
      24                 :            : 
      25                 :            : #include "brass_types.h"
      26                 :            : #include "xapian/types.h"
      27                 :            : 
      28                 :            : #include "internaltypes.h"
      29                 :            : 
      30                 :            : class BrassPostListTable;
      31                 :            : 
      32                 :            : /// Brass class for database statistics.
      33                 :            : class BrassDatabaseStats {
      34                 :            :     /// Don't allow assignment.
      35                 :            :     void operator=(const BrassDatabaseStats &);
      36                 :            : 
      37                 :            :     /// Don't allow copying.
      38                 :            :     BrassDatabaseStats(const BrassDatabaseStats &);
      39                 :            : 
      40                 :            :     /// The total of the lengths of all documents in the database.
      41                 :            :     totlen_t total_doclen;
      42                 :            : 
      43                 :            :     /// Greatest document id ever used in this database.
      44                 :            :     Xapian::docid last_docid;
      45                 :            : 
      46                 :            :     /// A lower bound on the smallest document length in this database.
      47                 :            :     Xapian::termcount doclen_lbound;
      48                 :            : 
      49                 :            :     /// An upper bound on the greatest document length in this database.
      50                 :            :     Xapian::termcount doclen_ubound;
      51                 :            : 
      52                 :            :     /// An upper bound on the greatest wdf in this database.
      53                 :            :     Xapian::termcount wdf_ubound;
      54                 :            : 
      55                 :            :     /// Oldest changeset removed when max_changesets is set
      56                 :            :     brass_revision_number_t oldest_changeset;
      57                 :            : 
      58                 :            :   public:
      59                 :       2208 :     BrassDatabaseStats()
      60                 :            :         : total_doclen(0), last_docid(0), doclen_lbound(0), doclen_ubound(0),
      61                 :       2208 :           wdf_ubound(0), oldest_changeset(0) { }
      62                 :            : 
      63                 :      73958 :     totlen_t get_total_doclen() const { return total_doclen; }
      64                 :            : 
      65                 :      89822 :     Xapian::docid get_last_docid() const { return last_docid; }
      66                 :            : 
      67                 :     356634 :     Xapian::termcount get_doclength_lower_bound() const {
      68                 :     356634 :         return doclen_lbound;
      69                 :            :     }
      70                 :            : 
      71                 :       1563 :     Xapian::termcount get_doclength_upper_bound() const {
      72                 :       1563 :         return doclen_ubound;
      73                 :            :     }
      74                 :            : 
      75                 :     235763 :     Xapian::termcount get_wdf_upper_bound() const { return wdf_ubound; }
      76                 :            : 
      77                 :         23 :     brass_revision_number_t get_oldest_changeset() const { return oldest_changeset; }
      78                 :            : 
      79                 :        883 :     void zero() {
      80                 :        883 :         total_doclen = 0;
      81                 :        883 :         last_docid = 0;
      82                 :        883 :         doclen_lbound = 0;
      83                 :        883 :         doclen_ubound = 0;
      84                 :        883 :         wdf_ubound = 0;
      85                 :        883 :         oldest_changeset = 0;
      86                 :        883 :     }
      87                 :            : 
      88                 :            :     void read(BrassPostListTable & postlist_table);
      89                 :            : 
      90                 :         92 :     void set_last_docid(Xapian::docid did) { last_docid = did; }
      91                 :            : 
      92                 :         37 :     void set_oldest_changeset(brass_revision_number_t changeset) { oldest_changeset = changeset; }
      93                 :            : 
      94                 :      77387 :     void add_document(Xapian::termcount doclen) {
      95 [ +  + ][ +  + ]:      77387 :         if (total_doclen == 0 || (doclen && doclen < doclen_lbound))
                 [ +  + ]
      96                 :      42530 :             doclen_lbound = doclen;
      97         [ +  + ]:      77387 :         if (doclen > doclen_ubound)
      98                 :        461 :             doclen_ubound = doclen;
      99                 :      77387 :         total_doclen += doclen;
     100                 :      77387 :     }
     101                 :            : 
     102                 :      19094 :     void delete_document(Xapian::termcount doclen) {
     103                 :      19094 :         total_doclen -= doclen;
     104                 :            :         // If the database no longer contains any postings, we can reset
     105                 :            :         // doclen_lbound, doclen_ubound and wdf_ubound.
     106         [ +  + ]:      19094 :         if (total_doclen == 0) {
     107                 :       9148 :             doclen_lbound = 0;
     108                 :       9148 :             doclen_ubound = 0;
     109                 :       9148 :             wdf_ubound = 0;
     110                 :            :         }
     111                 :      19094 :     }
     112                 :            : 
     113                 :     777222 :     void check_wdf(Xapian::termcount wdf) {
     114         [ +  + ]:     777222 :         if (wdf > wdf_ubound) wdf_ubound = wdf;
     115                 :     777222 :     }
     116                 :            : 
     117                 :      68211 :     Xapian::docid get_next_docid() { return ++last_docid; }
     118                 :            : 
     119                 :            :     void write(BrassPostListTable & postlist_table) const;
     120                 :            : };
     121                 :            : 
     122                 :            : #endif // XAPIAN_INCLUDED_BRASS_DBSTATS_H

Generated by: LCOV version 1.8