47 flags = fix_flags(flags);
50 new_cursor.swap(
this);
55 new_cursor.swap(
this);
64 return ascending_next();
66 return descending_next();
91 if (cursor_order == 0) {
101 void PredictiveCursor::init(
const String &str) {
106 min_length_ = str.length();
113 for (
UInt32 i = 0;
i < str.length(); ++
i) {
115 if (base.is_linker()) {
117 const Key &key = trie_->
get_key(base.key_pos());
118 if ((key.length() >= str.length()) &&
119 (key.str().substr(0, str.length()).compare(str,
i) == 0)) {
121 node_id |= IS_ROOT_FLAG;
129 node_id = base.offset() ^ str[
i];
136 node_id |= IS_ROOT_FLAG;
141 void PredictiveCursor::swap(PredictiveCursor *cursor) {
142 std::swap(trie_, cursor->trie_);
143 std::swap(offset_, cursor->offset_);
144 std::swap(limit_, cursor->limit_);
145 std::swap(flags_, cursor->flags_);
146 buf_.
swap(&cursor->buf_);
147 std::swap(cur_, cursor->cur_);
148 std::swap(end_, cursor->end_);
149 std::swap(min_length_, cursor->min_length_);
152 const Key &PredictiveCursor::ascending_next() {
153 while (!buf_.
empty()) {
154 const bool is_root = (buf_.
back() & IS_ROOT_FLAG) == IS_ROOT_FLAG;
155 const UInt32 node_id = buf_.
back() & ~IS_ROOT_FLAG;
160 buf_.
push_back(node_id ^ node.label() ^ node.sibling());
163 if (node.is_linker()) {
164 const Key &key = trie_->
get_key(node.key_pos());
165 if (key.length() >= min_length_) {
166 if (cur_++ >= offset_) {
171 buf_.
push_back(node.offset() ^ node.child());
177 const Key &PredictiveCursor::descending_next() {
178 while (!buf_.
empty()) {
179 const bool post_order = (buf_.
back() & POST_ORDER_FLAG) == POST_ORDER_FLAG;
180 const UInt32 node_id = buf_.
back() & ~POST_ORDER_FLAG;
185 if (base.is_linker()) {
186 const Key &key = trie_->
get_key(base.key_pos());
187 if (key.length() >= min_length_) {
188 if (cur_++ >= offset_) {
194 buf_.
back() |= POST_ORDER_FLAG;
198 label = trie_->
ith_node(base.offset() ^ label).sibling();