1 #ifndef XML_TREE_INTERNAL__
2 #error "xml-tree-inc.hpp should not be included directly"
5 #ifndef XML_TREE_INC_HPP_
6 #define XML_TREE_INC_HPP_
10 inline uint32_t xml_tree::size() const
12 return tag_seq_len / 2;
15 inline uint32_t xml_tree::num_tags() const
17 return tag_names->size();
20 inline uint32_t xml_tree::subtree_size(xml_tree::node_t x) const
22 return bp_subtree_size(this->par, x);
26 xml_tree::subtree_tags(xml_tree::node_t x, xml_tree::tag_t label) const
28 xml_tree::node_t y = bp_find_close(this->par, x);
31 for(xml_tree::node_t i = x; i < y; i++)
32 count += (tag(i) == label);
35 return tags->rank(label, y) - tags->rank(label, x);
39 inline bool xml_tree::is_leaf(xml_tree::node_t x) const
41 return !bp_inspect(this->par, x+1);
44 inline bool xml_tree::is_ancestor(xml_tree::node_t x,
45 xml_tree::node_t y) const
47 return bp_is_ancestor(this->par, x, y);
51 xml_tree::is_right_descendant(xml_tree::node_t x,
52 xml_tree::node_t y) const
56 && (y <= bp_parent_close(this->par, x))
57 && (y >= bp_find_close(this->par, x));
60 inline bool xml_tree::is_first_child(xml_tree::node_t x) const
62 return (x <= this->root()) || (bp_inspect(this->par, x - 1));
65 inline bool xml_tree::is_nil(xml_tree::node_t x) const
67 return (x == xml_tree::NIL);
70 inline xml_tree::tag_t xml_tree::tag(xml_tree::node_t x) const
72 if (bits_per_tag == 8)
73 return (xml_tree::tag_t) (((unsigned char*) tag_seq)[x]);
75 return get_field(tag_seq, bits_per_tag, x);
78 inline xml_tree::node_t xml_tree::root() const
80 return xml_tree::ROOT;
84 inline xml_tree::node_t xml_tree::parent(xml_tree::node_t x) const
86 return bp_parent(this->par, x);
89 inline xml_tree::node_t xml_tree::first_child(node_t x) const
91 xml_tree::node_t result = bp_first_child(this->par, x);
95 inline xml_tree::node_t xml_tree::last_child(xml_tree::node_t x) const
100 return bp_find_open(this->par, bp_find_close(this->par, x) - 1);
103 inline xml_tree::node_t xml_tree::next_sibling(xml_tree::node_t x) const
105 xml_tree::node_t result = bp_next_sibling(this->par, x);
109 inline xml_tree::node_t xml_tree::prev_sibling(xml_tree::node_t x) const
111 return bp_prev_sibling(this->par, x);
114 inline xml_tree::node_t xml_tree::first_element(xml_tree::node_t x) const
116 xml_tree::node_t n = first_child(x);
117 if (is_nil(n)) return xml_tree::NIL;
119 case xml_tree::ATTRIBUTE_OPEN_TAG_ID:
121 if (is_nil(n) || tag(n) != xml_tree::PCDATA_OPEN_TAG_ID) return n;
123 case PCDATA_OPEN_TAG_ID:
125 return bp_inspect(this->par, n) ? n : xml_tree::NIL;
131 inline xml_tree::node_t xml_tree::next_element(xml_tree::node_t x) const
134 if (is_nil(x)) return x;
135 if (tag(x) == xml_tree::PCDATA_OPEN_TAG_ID){
136 xml_tree::node_t y = x + 2;
137 return bp_inspect(this->par, y) ? y : xml_tree::NIL;
142 inline xml_tree::node_t xml_tree::tagged_next(node_t x, tag_t tag) const
144 return this->tags->select_next(tag, x);
147 inline xml_tree::node_t
148 xml_tree::tagged_descendant(xml_tree::node_t x,
149 xml_tree::tag_t tag) const
151 xml_tree::node_t y = tagged_next(x, tag);
152 return is_nil(y) || !is_ancestor(x, y) ? xml_tree::NIL : y;
155 inline xml_tree::node_t
156 xml_tree::tagged_following_before(xml_tree::node_t x,
158 xml_tree::node_t limit) const
160 xml_tree::node_t close = bp_find_close(this->par, x);
161 xml_tree::node_t s = tagged_next(close, tag);
162 return (s < limit) ? s : xml_tree::NIL;
166 inline xml_tree::node_t xml_tree::tagged_child(xml_tree::node_t x,
167 xml_tree::tag_t t) const
169 xml_tree::node_t c = first_child(x);
170 xml_tree::node_t result;
171 if (is_nil(c) || tag(c) == t)
174 return tagged_sibling(c, t);
177 inline xml_tree::node_t xml_tree::tagged_sibling(xml_tree::node_t x,
178 xml_tree::tag_t t) const
180 xml_tree::node_t sibling = next_sibling(x);
181 xml_tree::tag_t stag;
182 while (sibling != xml_tree::NIL) {
186 sibling = next_sibling(sibling);
191 xml_tree::node_t xml_tree::closing(xml_tree::node_t x) const
193 return bp_find_close(this->par, x);
197 inline SXSI::TextCollection *xml_tree::get_text_collection() const
199 return text_collection;
202 inline xml_tree::node_t xml_tree::parent_node(int32_t d) const
204 return (xml_tree::node_t) text_positions->select1(d + 1);
207 inline SXSI::TextCollection::document_result
208 xml_tree::prefix(uchar const *s) const
210 return text_collection->Prefix(s);
213 inline SXSI::TextCollection::document_result
214 xml_tree::suffix(uchar const *s) const
216 return text_collection->Suffix(s);
219 inline SXSI::TextCollection::document_result
220 xml_tree::equals(uchar const *s) const
222 return text_collection->Equal(s);
225 inline SXSI::TextCollection::document_result
226 xml_tree::contains(uchar const *s) const
228 return text_collection->Contains(s);
231 inline SXSI::TextCollection::document_result
232 xml_tree::less_than(uchar const *s) const
234 return text_collection->LessThan(s);
238 #endif //XML_TREE_INC_HPP_