summaryrefslogtreecommitdiffstats
path: root/src/storage
diff options
context:
space:
mode:
Diffstat (limited to 'src/storage')
-rw-r--r--src/storage/pinyin_large_table.cpp18
-rw-r--r--src/storage/pinyin_phrase.h22
2 files changed, 33 insertions, 7 deletions
diff --git a/src/storage/pinyin_large_table.cpp b/src/storage/pinyin_large_table.cpp
index 29febce..204518d 100644
--- a/src/storage/pinyin_large_table.cpp
+++ b/src/storage/pinyin_large_table.cpp
@@ -327,18 +327,21 @@ int PinyinLengthIndexLevel::search( int phrase_length,
template<size_t phrase_length>
int PinyinArrayIndexLevel<phrase_length>::search(/* in */ PinyinCustomSettings * custom, /* in */ PinyinKey keys[], /* out */ PhraseIndexRanges ranges){
- PhraseExactLessThan<phrase_length> m_lessthan;
PinyinIndexItem<phrase_length> * chunk_begin, * chunk_end;
chunk_begin = (PinyinIndexItem<phrase_length> *)m_chunk.begin();
chunk_end = (PinyinIndexItem<phrase_length> *)m_chunk.end();
+
//do the search
PinyinKey left_keys[phrase_length], right_keys[phrase_length];
compute_lower_value(*custom, keys, left_keys, phrase_length);
compute_upper_value(*custom, keys, right_keys, phrase_length);
+
PinyinIndexItem<phrase_length> left(left_keys, -1), right(right_keys, -1);
- PinyinIndexItem<phrase_length> * begin = std_lite::lower_bound(chunk_begin, chunk_end, left, m_lessthan);
- PinyinIndexItem<phrase_length> * end = std_lite::upper_bound(chunk_begin, chunk_end, right, m_lessthan);
+ PinyinIndexItem<phrase_length> * begin = std_lite::lower_bound
+ (chunk_begin, chunk_end, left, phrase_exact_less_than<phrase_length>);
+ PinyinIndexItem<phrase_length> * end = std_lite::upper_bound
+ (chunk_begin, chunk_end, right, phrase_exact_less_than<phrase_length>);
return convert(custom, keys, begin, end, ranges);
}
@@ -474,7 +477,6 @@ int PinyinLengthIndexLevel::remove_index( int phrase_length, /* in */ PinyinKey
template<size_t phrase_length>
int PinyinArrayIndexLevel<phrase_length>::add_index(/* in */ PinyinKey keys[], /* in */ phrase_token_t token){
- PhraseExactLessThan<phrase_length> m_lessthan;
PinyinIndexItem<phrase_length> * buf_begin, * buf_end;
PinyinIndexItem<phrase_length> new_elem(keys, token);
@@ -482,7 +484,8 @@ int PinyinArrayIndexLevel<phrase_length>::add_index(/* in */ PinyinKey keys[], /
buf_end = (PinyinIndexItem<phrase_length> *) m_chunk.end();
std_lite::pair<PinyinIndexItem<phrase_length> *, PinyinIndexItem<phrase_length> *> range;
- range = std_lite::equal_range(buf_begin, buf_end, new_elem, m_lessthan);
+ range = std_lite::equal_range
+ (buf_begin, buf_end, new_elem, phrase_exact_less_than<phrase_length>);
PinyinIndexItem<phrase_length> * cur_elem;
for ( cur_elem = range.first;
@@ -502,7 +505,6 @@ int PinyinArrayIndexLevel<phrase_length>::add_index(/* in */ PinyinKey keys[], /
template<size_t phrase_length>
int PinyinArrayIndexLevel<phrase_length>::remove_index(/* in */ PinyinKey keys[], /* in */ phrase_token_t token){
- PhraseExactLessThan<phrase_length> m_lessthan;
PinyinIndexItem<phrase_length> * buf_begin, * buf_end;
PinyinIndexItem<phrase_length> remove_elem(keys, token);
@@ -510,7 +512,9 @@ int PinyinArrayIndexLevel<phrase_length>::remove_index(/* in */ PinyinKey keys[]
buf_end = (PinyinIndexItem<phrase_length> *) m_chunk.end();
std_lite::pair<PinyinIndexItem<phrase_length> *, PinyinIndexItem<phrase_length> *> range;
- range = std_lite::equal_range(buf_begin, buf_end, remove_elem, m_lessthan);
+ range = std_lite::equal_range
+ (buf_begin, buf_end, remove_elem,
+ phrase_exact_less_than<phrase_length>);
PinyinIndexItem<phrase_length> * cur_elem;
for ( cur_elem = range.first;
diff --git a/src/storage/pinyin_phrase.h b/src/storage/pinyin_phrase.h
index 61c0c6e..b9a8812 100644
--- a/src/storage/pinyin_phrase.h
+++ b/src/storage/pinyin_phrase.h
@@ -187,8 +187,28 @@ public:
}
};
+
//for find the element in the phrase array
template<int phrase_length>
+inline int phrase_exact_compare(const PinyinIndexItem<phrase_length> &lhs,
+ const PinyinIndexItem<phrase_length> &rhs)
+{
+ PinyinKey * key_lhs = (PinyinKey *) lhs.m_keys;
+ PinyinKey * key_rhs = (PinyinKey *) rhs.m_keys;
+ return pinyin_exact_compare(key_lhs, key_rhs, phrase_length);
+}
+
+template<int phrase_length>
+inline bool phrase_exact_less_than(const PinyinIndexItem<phrase_length> &lhs,
+ const PinyinIndexItem<phrase_length> &rhs)
+{
+ return 0 > phrase_exact_compare<phrase_length>(lhs, rhs);
+}
+
+
+#if 0
+
+template<int phrase_length>
class PhraseExactCompare
: public std_lite::binary_function <const PinyinIndexItem<phrase_length>
,const PinyinIndexItem<phrase_length>, int>
@@ -219,6 +239,8 @@ class PhraseExactLessThan
}
};
+#endif
+
};
#endif