source: trunk/src/xmlpatterns/acceltree/qacceltree_p.h@ 98

Last change on this file since 98 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 14.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtXmlPatterns module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42//
43// W A R N I N G
44// -------------
45//
46// This file is not part of the Qt API. It exists purely as an
47// implementation detail. This header file may change from version to
48// version without notice, or even be removed.
49//
50// We mean it.
51
52#ifndef Patternist_AccelTree_H
53#define Patternist_AccelTree_H
54
55#include <QHash>
56#include <QUrl>
57#include <QVector>
58#include <QXmlName>
59
60#include "qitem_p.h"
61#include "qnamepool_p.h"
62
63QT_BEGIN_HEADER
64
65QT_BEGIN_NAMESPACE
66
67namespace QPatternist
68{
69 template<bool> class AccelTreeBuilder;
70
71 /**
72 * @short Stores an XML document using the XPath Accelerator scheme, also
73 * known as pre/post numbering.
74 *
75 * Working on this code will be destructive without a proper understanding of
76 * the Accelerator scheme, so do check out the links. We don't implement any form
77 * of staircase join, although that is only due to time constraints.
78 *
79 * @author Frans Englich <[email protected]>
80 * @see <a href="http://www.pathfinder-xquery.org/?q=research/xpath-accel">XPath
81 * Accelerator</a>
82 * @see <a href="http://www.pathfinder-xquery.org/files/xpath-accel.pdf">Accelerating
83 * XPath Location Steps, Torsten Grust</a>
84 * @see <a href="http://citeseer.ist.psu.edu/cache/papers/cs/29367/http:zSzzSzwww.informatik.uni-konstanz.dezSz~grustzSzfileszSzstaircase-join.pdf/grust03staircase.pdf">Staircase Join:
85 * Teach a Relational DBMS to Watch its (Axis) Steps</a>
86 * @see <a href="http://ftp.cwi.nl/CWIreports/INS/INS-E0510.pdf">Loop-lifted
87 * staircase join: from XPath to XQuery, Torsten Grust</a>
88 * @see <a href="http://englich.wordpress.com/2007/01/09/xmlstat/">xmlstat, Frans Englich</a>
89 * @see <a href"http://www.inf.uni-konstanz.de/dbis/publications/download/accelerating-locsteps.pdf">Accelerating
90 * XPath Evaluation in Any RDBMS, Torsten Grust</a>
91 */
92 class AccelTree : public QAbstractXmlNodeModel
93 {
94 public:
95 using QAbstractXmlNodeModel::createIndex;
96
97 typedef QExplicitlySharedDataPointer<AccelTree> Ptr;
98 typedef qint32 PreNumber;
99 typedef PreNumber PostNumber;
100 typedef qint8 Depth;
101
102 inline AccelTree(const QUrl &docURI,
103 const QUrl &bURI) : m_documentURI(docURI),
104 m_baseURI(bURI)
105 {
106 /* Pre-allocate at least a little bit. */
107 // TODO. Do it according to what an average 4 KB doc contains.
108 basicData.reserve(100);
109 data.reserve(30);
110 }
111
112 /**
113 * @short Houses data for a node, and that all node kinds have.
114 *
115 * BasicNodeData is internal to the Accel tree implementation, and is
116 * only used by those classes.
117 *
118 * @author Frans Englich <[email protected]>
119 * @todo Can't m_kind be coded somewhere else? If m_name is invalid,
120 * its bits can be used to distinguish the node types that doesn't have
121 * names, and for elements, attributes and processing instructions, we need
122 * two bits, somewhere. Attributes and processing instructions can't have a
123 * size, is that of help? There's also certain rules for the names. For instance,
124 * a processing instruction will never have a prefix nor namespace. Neither
125 * will an attribute node have a default, non-empty namespace, right?
126 * @todo Compress text nodes, add general support for it in Patternist.
127 */
128 class BasicNodeData
129 {
130 public:
131 inline BasicNodeData()
132 {
133 }
134
135 inline BasicNodeData(const PreNumber aDepth,
136 const PreNumber aParent,
137 const QXmlNodeModelIndex::NodeKind k,
138 const PreNumber s,
139 const QXmlName n = QXmlName()) : m_parent(aParent)
140 , m_size(s)
141 , m_name(n)
142 , m_depth(aDepth)
143 , m_kind(k)
144 {
145 }
146
147 inline Depth depth() const
148 {
149 return m_depth;
150 }
151
152 inline PreNumber parent() const
153 {
154 return m_parent;
155 }
156
157 /**
158 * @see AccelTree::size()
159 */
160 inline PreNumber size() const
161 {
162 /* Remember that we use the m_size to signal compression if
163 * we're a text node. */
164 if(m_kind == QXmlNodeModelIndex::Text)
165 return 0;
166 else
167 return m_size;
168 }
169
170 inline void setSize(const PreNumber aSize)
171 {
172 m_size = aSize;
173 }
174
175 inline QXmlNodeModelIndex::NodeKind kind() const
176 {
177 return m_kind;
178 }
179
180 inline QXmlName name() const
181 {
182 return m_name;
183 }
184
185 inline bool isCompressed() const
186 {
187 Q_ASSERT_X(m_kind == QXmlNodeModelIndex::Text, Q_FUNC_INFO,
188 "Currently, only text nodes are compressed.");
189 /* Note, we don't call size() here, since it has logic for text
190 * nodes. */
191 return m_size == IsCompressed;
192 }
193
194 private:
195 /**