This repository was archived by the owner on Oct 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxbw.h
130 lines (105 loc) · 3.88 KB
/
xbw.h
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <iostream>
#include <fstream>
#include <cassert>
#include <basics.h>
#include <static_sequence.h>
#include <static_bitsequence.h>
#include <alphabet_mapper.h>
using namespace std;
/** Implementation of the XBW-Index proposed by Ferragina, Luccio, Manzini and Muthukrishnan
* in FOCS 2005. The idea is patented, this code can't be redistributed nor used for
* commercial purposes.
*
* @author Francisco Claude
* @email [email protected]
*/
class XBW {
public:
/** Builds an XBW object reading it from a file, it uses ssb to create the \alpha sequence
* and sbb to create the bit-sequences.
* @param filename file where the index is stored
* @param params parameters not implemented
*/
XBW(const string & filename, const string & params);
/** Destroys the object */
~XBW();
/** Searchs for path query in the tree. Computes the range of nodes that satisfy the
* query up to the last item.
* @param qry query, qry[0]=a and qry[1]=b means /a/b
* @param ql length of the query
* @param ini pointer for storing the initial position of the range answering the query
* @param fin pointer for storing the final position of the range answering the query
*/
void subPathSearch(const uint * query, const uint ql, uint * ini, uint * fin) const;
/** Searchs for path query in the tree, produces an array with the node ids that
* satisfy the query.
* @param qry query, qry[0]=a and qry[1]=b means /a/b
* @param ql length of the query
* @param len pointer to store the length of the result
* @return array with node ids descending from a path labeles qry, the length of the array is stored in len
*/
uint * subPathSearch(const uint * qry, const uint ql, uint * len) const;
/** Computes the parent of a node
* @param n node id
* @return parent of n
*/
uint getParent(const uint n) const;
/** Computes the k-th child of node n
* @param n node id
* @param k child number
* @return commputes the k-th child of node n
*/
uint getRankedChild(const uint n, const uint k) const;
/** Selects the k-th children of node n with label l
* @param n node id
* @param l label
* @param k occurrence
* @return k-th occurrence of l among the children of n
*/
uint getCharRankedChild(const uint n, const uint l, const uint k) const;
/** Computes how many children does node n have
* @param n node id
* @return degree of n
*/
uint getDegree(const uint n) const;
/** Computes how many children of node n have label l
* @param n node id
* @param l label
* @return number of children of n with label l
*/
uint getCharDegree(const uint n, const uint l) const;
/** checks whether node n is a leaf or not
* @param n node id
* @return true if n is a leaf
*/
bool isLeaf(const uint n) const;
/** Returns the size of the XBW structure */
uint size() const;
/** gets the range where the children of node n are
* @param n node id
* @param ini pointer to where to store the initial position of the range
* @param fin pointer to where to store the final position of the range
*/
void getChildren(const uint n, uint * ini, uint * fin) const;
/** Retrieves the label of node n
* @param n node id
* @return label of n
*/
uint getLabel(const uint n) const;
protected:
/** number of nodes in the tree */
uint nodesCount;
/** max label */
uint maxLabel;
/** labels of the nodes in the tree */
static_sequence * alpha;
/** marks the rightmost child of every node */
static_bitsequence * last;
/** marks which nodes are leaves */
static_bitsequence * leaf;
/** marks the beginning of each symbol run in \pi */
static_bitsequence * A;
uint * alphaTmp;
uint * alphaSeq;
uint balpha;
};