Branch data Line data Source code
1 : : /* brass_record.cc: Records in brass databases
2 : : *
3 : : * Copyright 2002 Ananova Ltd
4 : : * Copyright 2002,2003,2004,2005,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 : :
24 : : #include "brass_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 : 478104 : make_key(Xapian::docid did)
36 : : {
37 : 478104 : string key;
38 : 478104 : pack_uint_preserving_sort(key, did);
39 : 0 : return key;
40 : : }
41 : :
42 : : string
43 : 151669 : BrassRecordTable::get_record(Xapian::docid did) const
44 : : {
45 : : LOGCALL(DB, string, "BrassRecordTable::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 : 225901 : BrassRecordTable::get_doccount() const
57 : : {
58 : : LOGCALL(DB, Xapian::doccount, "BrassRecordTable::get_doccount", NO_ARGS);
59 : 225901 : brass_tablesize_t count = get_entry_count();
60 [ - + ]: 225901 : if (rare(count > brass_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 : 225901 : RETURN(Xapian::doccount(count));
66 : : }
67 : :
68 : : void
69 : 77488 : BrassRecordTable::replace_record(const string & data, Xapian::docid did)
70 : : {
71 : : LOGCALL_VOID(DB, "BrassRecordTable::replace_record", data | did);
72 : 77488 : add(make_key(did), data);
73 : 77488 : }
74 : :
75 : : void
76 : 9894 : BrassRecordTable::delete_record(Xapian::docid did)
77 : : {
78 : : LOGCALL_VOID(DB, "BrassRecordTable::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 : }
|