Remove some superfluous blank lines
[xapian.git] / xapian-core / backends / glass / glass_spellingwordslist.cc
blob66598260d476e7307099ee580bb256fd4475fedf
1 /** @file glass_spellingwordslist.cc
2 * @brief Iterator for the spelling correction words in a glass database.
3 */
4 /* Copyright (C) 2004,2005,2006,2007,2008,2009,2017 Olly Betts
5 * Copyright (C) 2007 Lemur Consulting Ltd
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
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.
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
22 #include <config.h>
24 #include "glass_spellingwordslist.h"
26 #include "xapian/error.h"
27 #include "xapian/types.h"
29 #include "debuglog.h"
30 #include "glass_database.h"
31 #include "pack.h"
32 #include "stringutils.h"
34 GlassSpellingWordsList::~GlassSpellingWordsList()
36 LOGCALL_DTOR(DB, "GlassSpellingWordsList");
37 delete cursor;
40 Xapian::termcount
41 GlassSpellingWordsList::get_approx_size() const
43 // This is an over-estimate, but we only use this value to build a balanced
44 // or-tree, and it'll do a decent enough job for that.
45 return database->spelling_table.get_entry_count();
48 string
49 GlassSpellingWordsList::get_termname() const
51 LOGCALL(DB, string, "GlassSpellingWordsList::get_termname", NO_ARGS);
52 Assert(cursor);
53 Assert(!at_end());
54 Assert(!cursor->current_key.empty());
55 Assert(cursor->current_key[0] == 'W');
56 RETURN(cursor->current_key.substr(1));
59 Xapian::doccount
60 GlassSpellingWordsList::get_termfreq() const
62 LOGCALL(DB, Xapian::doccount, "GlassSpellingWordsList::get_termfreq", NO_ARGS);
63 Assert(cursor);
64 Assert(!at_end());
65 Assert(!cursor->current_key.empty());
66 Assert(cursor->current_key[0] == 'W');
67 cursor->read_tag();
69 Xapian::termcount freq;
70 const char *p = cursor->current_tag.data();
71 if (!unpack_uint_last(&p, p + cursor->current_tag.size(), &freq)) {
72 throw Xapian::DatabaseCorruptError("Bad spelling word freq");
74 RETURN(freq);
77 Xapian::termcount
78 GlassSpellingWordsList::get_collection_freq() const
80 throw Xapian::InvalidOperationError("GlassSpellingWordsList::get_collection_freq() not meaningful");
83 TermList *
84 GlassSpellingWordsList::next()
86 LOGCALL(DB, TermList *, "GlassSpellingWordsList::next", NO_ARGS);
87 Assert(!at_end());
89 cursor->next();
90 if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
91 // We've reached the end of the prefixed terms.
92 cursor->to_end();
95 RETURN(NULL);
98 TermList *
99 GlassSpellingWordsList::skip_to(const string &tname)
101 LOGCALL(DB, TermList *, "GlassSpellingWordsList::skip_to", tname);
102 Assert(!at_end());
104 if (!cursor->find_entry_ge("W" + tname)) {
105 // The exact term we asked for isn't there, so check if the next
106 // term after it also has a W prefix.
107 if (!cursor->after_end() && !startswith(cursor->current_key, 'W')) {
108 // We've reached the end of the prefixed terms.
109 cursor->to_end();
112 RETURN(NULL);
115 bool
116 GlassSpellingWordsList::at_end() const
118 LOGCALL(DB, bool, "GlassSpellingWordsList::at_end", NO_ARGS);
119 RETURN(cursor->after_end());