File: flint_positionlist.h

package info (click to toggle)
xapian-core 0.9.9-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 14,456 kB
  • ctags: 10,769
  • sloc: cpp: 50,894; sh: 8,889; ansic: 3,729; makefile: 622; perl: 149
file content (114 lines) | stat: -rw-r--r-- 3,542 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/* flint_positionlist.h: A position list in a flint database.
 *
 * Copyright (C) 2005,2006 Olly Betts
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

#ifndef XAPIAN_HGUARD_FLINT_POSITIONLIST_H
#define XAPIAN_HGUARD_FLINT_POSITIONLIST_H

#include <xapian/types.h>

#include "flint_table.h"
#include "flint_utils.h"
#include "positionlist.h"

#include <string>
#include <vector>

using namespace std;

class FlintPositionListTable : public FlintTable {
    static string make_key(Xapian::docid did, const string & tname) {
	return pack_uint_preserving_sort(did) + tname;
    }

  public:
    /** Create a new FlintPositionListTable object.
     *
     *  This method does not create or open the table on disk - you
     *  must call the create() or open() methods respectively!
     *
     *  @param dbdir		The directory the flint database is stored in.
     *  @param readonly		true if we're opening read-only, else false.
     */
    FlintPositionListTable(string dbdir, bool readonly)
	: FlintTable(dbdir + "/position.", readonly) { }

    /// Set the position list for term tname in document did.
    void set_positionlist(Xapian::docid did, const string & tname,
			  Xapian::PositionIterator pos,
			  const Xapian::PositionIterator &pos_end);

    /// Delete the position list for term tname in document did.
    void delete_positionlist(Xapian::docid did, const string & tname) {
	del(make_key(did, tname));
    }
};

/** A position list in a flint database. */
class FlintPositionList : public PositionList {
    /// Vector of term positions.
    vector<Xapian::termpos> positions;

    /// Position of iteration through data.
    vector<Xapian::termpos>::const_iterator current_pos;

    /// Have we started iterating yet?
    bool have_started;

    /// Advance to next term position.
    void next_internal();

    /// Copying is not allowed.
    FlintPositionList(const FlintPositionList &);

    /// Assignment is not allowed.
    void operator=(const FlintPositionList &);

  public:
    /// Default constructor.
    FlintPositionList() : have_started(false) {}

    /// Destructor.
    ~FlintPositionList() { }

    /// Fill list with data, and move the position to the start.
    void read_data(const FlintTable * table, Xapian::docid did,
		   const string & tname);

    /// Returns size of position list.
    Xapian::termcount get_size() const;

    /** Returns current position.
     *
     *  Either next() or skip_to() must have been called before this
     *  method can be called.
     */
    Xapian::termpos get_position() const;

    /// Advance to the next term position in the list.
    void next();

    /// Advance to the first term position which is at least termpos.
    void skip_to(Xapian::termpos termpos);

    /// True if we're off the end of the list
    bool at_end() const;
};

#endif /* XAPIAN_HGUARD_FLINT_POSITIONLIST_H */