null+****@clear*****
null+****@clear*****
2011年 7月 4日 (月) 17:20:38 JST
Susumu Yata 2011-07-04 08:20:38 +0000 (Mon, 04 Jul 2011)
New Revision: 39f66f85c73465c7b8205cbabfda4a6ca8ed7eaa
Log:
fixed a bug --- a search result of grn::dat::PredictiveCursor + grn::dat::ASCENDING_CURSOR contains invalid keys.
Modified files:
lib/dat/predictive-cursor.cpp
lib/dat/predictive-cursor.hpp
Modified: lib/dat/predictive-cursor.cpp (+10 -2)
===================================================================
--- lib/dat/predictive-cursor.cpp 2011-07-04 08:18:05 +0000 (f5e755f)
+++ lib/dat/predictive-cursor.cpp 2011-07-04 08:20:38 +0000 (3437665)
@@ -101,6 +101,9 @@ void PredictiveCursor::init(const String &str) {
trie_->ith_key(base.key_id(), &key);
if ((key.length() >= str.length()) &&
(key.str().substr(0, str.length()).compare(str, i) == 0)) {
+ if ((flags_ & ASCENDING_CURSOR) == ASCENDING_CURSOR) {
+ node_id |= IS_ROOT_FLAG;
+ }
GRN_DAT_THROW_IF(MEMORY_ERROR, !buf_.push_back(node_id));
}
}
@@ -112,6 +115,10 @@ void PredictiveCursor::init(const String &str) {
return;
}
}
+
+ if ((flags_ & ASCENDING_CURSOR) == ASCENDING_CURSOR) {
+ node_id |= IS_ROOT_FLAG;
+ }
GRN_DAT_THROW_IF(MEMORY_ERROR, !buf_.push_back(node_id));
}
@@ -128,11 +135,12 @@ void PredictiveCursor::swap(PredictiveCursor *cursor) {
bool PredictiveCursor::ascending_next(Key *key) {
while (!buf_.empty()) {
- const UInt32 node_id = buf_.back();
+ const bool is_root = (buf_.back() & IS_ROOT_FLAG) == IS_ROOT_FLAG;
+ const UInt32 node_id = buf_.back() & ~IS_ROOT_FLAG;
buf_.pop_back();
const Node node = trie_->ith_node(node_id);
- if (node.sibling() != INVALID_LABEL) {
+ if (!is_root && (node.sibling() != INVALID_LABEL)) {
GRN_DAT_THROW_IF(MEMORY_ERROR,
!buf_.push_back(node_id ^ node.label() ^ node.sibling()));
}
Modified: lib/dat/predictive-cursor.hpp (+1 -0)
===================================================================
--- lib/dat/predictive-cursor.hpp 2011-07-04 08:18:05 +0000 (fa3e7b4)
+++ lib/dat/predictive-cursor.hpp 2011-07-04 08:20:38 +0000 (5309f8a)
@@ -55,6 +55,7 @@ class PredictiveCursor : public Cursor {
bool ascending_next(Key *key);
bool descending_next(Key *key);
+ static const UInt32 IS_ROOT_FLAG = 0x80000000U;
static const UInt32 POST_ORDER_FLAG = 0x80000000U;
// Disallows copy and assignment.