summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2013-04-18 11:26:23 +0800
committerPeng Wu <alexepico@gmail.com>2013-04-18 11:26:23 +0800
commitcb827e2511b9557e41acec74a3d6ebcfaed862f8 (patch)
tree1da7c29c8bef4d3f231b5e996fb967678be25fd8
parent0ee1b6a1b63ae2d55684bd982a95a6a9389f12d2 (diff)
downloadlibpinyin-cb827e2511b9557e41acec74a3d6ebcfaed862f8.tar.gz
libpinyin-cb827e2511b9557e41acec74a3d6ebcfaed862f8.tar.xz
libpinyin-cb827e2511b9557e41acec74a3d6ebcfaed862f8.zip
add const modifiers for chewing table
-rw-r--r--src/storage/chewing_large_table.cpp40
-rw-r--r--src/storage/chewing_large_table.h19
-rw-r--r--src/storage/facade_chewing_table.h6
-rw-r--r--src/storage/pinyin_phrase2.h11
4 files changed, 39 insertions, 37 deletions
diff --git a/src/storage/chewing_large_table.cpp b/src/storage/chewing_large_table.cpp
index 33bb733..85246c3 100644
--- a/src/storage/chewing_large_table.cpp
+++ b/src/storage/chewing_large_table.cpp
@@ -45,13 +45,13 @@ public:
/* search method */
int search(pinyin_option_t options, int phrase_length,
- /* in */ ChewingKey keys[],
+ /* in */ const ChewingKey keys[],
/* out */ PhraseIndexRanges ranges) const;
/* add/remove index method */
- int add_index(int phrase_length, /* in */ ChewingKey keys[],
+ int add_index(int phrase_length, /* in */ const ChewingKey keys[],
/* in */ phrase_token_t token);
- int remove_index(int phrase_length, /* in */ ChewingKey keys[],
+ int remove_index(int phrase_length, /* in */ const ChewingKey keys[],
/* in */ phrase_token_t token);
/* get length method */
@@ -72,7 +72,7 @@ protected:
/* compress consecutive tokens */
int convert(pinyin_option_t options,
- ChewingKey keys[],
+ const ChewingKey keys[],
IndexItem * begin,
IndexItem * end,
PhraseIndexRanges ranges) const;
@@ -84,12 +84,12 @@ public:
table_offset_t & end);
/* search method */
- int search(pinyin_option_t options, /* in */ChewingKey keys[],
+ int search(pinyin_option_t options, /* in */const ChewingKey keys[],
/* out */ PhraseIndexRanges ranges) const;
/* add/remove index method */
- int add_index(/* in */ ChewingKey keys[], /* in */ phrase_token_t token);
- int remove_index(/* in */ ChewingKey keys[],
+ int add_index(/* in */ const ChewingKey keys[], /* in */ phrase_token_t token);
+ int remove_index(/* in */ const ChewingKey keys[],
/* in */ phrase_token_t token);
/* get length method */
@@ -129,14 +129,14 @@ void ChewingBitmapIndexLevel::reset() {
/* search method */
int ChewingBitmapIndexLevel::search(int phrase_length,
- /* in */ ChewingKey keys[],
+ /* in */ const ChewingKey keys[],
/* out */ PhraseIndexRanges ranges) const {
assert(phrase_length > 0);
return initial_level_search(phrase_length, keys, ranges);
}
int ChewingBitmapIndexLevel::initial_level_search (int phrase_length,
- /* in */ ChewingKey keys[], /* out */ PhraseIndexRanges ranges) const {
+ /* in */ const ChewingKey keys[], /* out */ PhraseIndexRanges ranges) const {
/* macros */
#define MATCH(AMBIGUITY, ORIGIN, ANOTHER) case ORIGIN: \
@@ -197,7 +197,7 @@ int ChewingBitmapIndexLevel::initial_level_search (int phrase_length,
int ChewingBitmapIndexLevel::middle_and_final_level_search
-(ChewingInitial initial, int phrase_length, /* in */ ChewingKey keys[],
+(ChewingInitial initial, int phrase_length, /* in */ const ChewingKey keys[],
/* out */ PhraseIndexRanges ranges) const {
/* macros */
@@ -268,7 +268,7 @@ int ChewingBitmapIndexLevel::middle_and_final_level_search
int ChewingBitmapIndexLevel::tone_level_search
(ChewingInitial initial, ChewingMiddle middle, ChewingFinal final,
- int phrase_length, /* in */ ChewingKey keys[],
+ int phrase_length, /* in */ const ChewingKey keys[],
/* out */ PhraseIndexRanges ranges) const {
int result = SEARCH_NONE;
@@ -352,7 +352,7 @@ ChewingLengthIndexLevel::~ChewingLengthIndexLevel() {
int ChewingLengthIndexLevel::search(pinyin_option_t options, int phrase_length,
- /* in */ ChewingKey keys[],
+ /* in */ const ChewingKey keys[],
/* out */ PhraseIndexRanges ranges) const {
int result = SEARCH_NONE;
if (m_chewing_array_indexes->len < phrase_length + 1)
@@ -397,7 +397,7 @@ int ChewingLengthIndexLevel::search(pinyin_option_t options, int phrase_length,
template<size_t phrase_length>
int ChewingArrayIndexLevel<phrase_length>::search
-(pinyin_option_t options, /* in */ChewingKey keys[],
+(pinyin_option_t options, /* in */ const ChewingKey keys[],
/* out */ PhraseIndexRanges ranges) const {
IndexItem * chunk_begin = NULL, * chunk_end = NULL;
chunk_begin = (IndexItem *) m_chunk.begin();
@@ -423,7 +423,7 @@ int ChewingArrayIndexLevel<phrase_length>::search
/* compress consecutive tokens */
template<size_t phrase_length>
int ChewingArrayIndexLevel<phrase_length>::convert
-(pinyin_option_t options, ChewingKey keys[],
+(pinyin_option_t options, const ChewingKey keys[],
IndexItem * begin, IndexItem * end,
PhraseIndexRanges ranges) const {
IndexItem * iter = NULL;
@@ -471,7 +471,7 @@ int ChewingArrayIndexLevel<phrase_length>::convert
/* add/remove index method */
int ChewingBitmapIndexLevel::add_index(int phrase_length,
- /* in */ ChewingKey keys[],
+ /* in */ const ChewingKey keys[],
/* in */ phrase_token_t token) {
const ChewingKey first_key = keys[0];
ChewingLengthIndexLevel * & length_array = m_chewing_length_indexes
@@ -486,7 +486,7 @@ int ChewingBitmapIndexLevel::add_index(int phrase_length,
}
int ChewingBitmapIndexLevel::remove_index(int phrase_length,
- /* in */ ChewingKey keys[],
+ /* in */ const ChewingKey keys[],
/* in */ phrase_token_t token) {
const ChewingKey first_key = keys[0];
ChewingLengthIndexLevel * & length_array = m_chewing_length_indexes
@@ -508,7 +508,7 @@ int ChewingBitmapIndexLevel::remove_index(int phrase_length,
}
int ChewingLengthIndexLevel::add_index(int phrase_length,
- /* in */ ChewingKey keys[],
+ /* in */ const ChewingKey keys[],
/* in */ phrase_token_t token) {
if (!(phrase_length + 1 < MAX_PHRASE_LENGTH))
return ERROR_PHRASE_TOO_LONG;
@@ -551,7 +551,7 @@ int ChewingLengthIndexLevel::add_index(int phrase_length,
}
int ChewingLengthIndexLevel::remove_index(int phrase_length,
- /* in */ ChewingKey keys[],
+ /* in */ const ChewingKey keys[],
/* in */ phrase_token_t token) {
if (!(phrase_length + 1 < MAX_PHRASE_LENGTH))
return ERROR_PHRASE_TOO_LONG;
@@ -606,7 +606,7 @@ int ChewingLengthIndexLevel::remove_index(int phrase_length,
template<size_t phrase_length>
int ChewingArrayIndexLevel<phrase_length>::add_index
-(/* in */ ChewingKey keys[], /* in */ phrase_token_t token) {
+(/* in */ const ChewingKey keys[], /* in */ phrase_token_t token) {
IndexItem * begin, * end;
IndexItem add_elem(keys, token);
@@ -633,7 +633,7 @@ int ChewingArrayIndexLevel<phrase_length>::add_index
template<size_t phrase_length>
int ChewingArrayIndexLevel<phrase_length>::remove_index
-(/* in */ ChewingKey keys[], /* in */ phrase_token_t token) {
+(/* in */ const ChewingKey keys[], /* in */ phrase_token_t token) {
IndexItem * begin, * end;
IndexItem remove_elem(keys, token);
diff --git a/src/storage/chewing_large_table.h b/src/storage/chewing_large_table.h
index 6ec218f..30ae9aa 100644
--- a/src/storage/chewing_large_table.h
+++ b/src/storage/chewing_large_table.h
@@ -43,16 +43,17 @@ protected:
[CHEWING_NUMBER_OF_FINALS][CHEWING_NUMBER_OF_TONES];
/* search functions */
- int initial_level_search(int phrase_length, /* in */ ChewingKey keys[],
+ int initial_level_search(int phrase_length,
+ /* in */ const ChewingKey keys[],
/* out */ PhraseIndexRanges ranges) const;
int middle_and_final_level_search(ChewingInitial initial,
int phrase_length,
- /* in */ ChewingKey keys[],
+ /* in */ const ChewingKey keys[],
/* out */ PhraseIndexRanges ranges) const;
int tone_level_search(ChewingInitial initial, ChewingMiddle middle,
ChewingFinal final, int phrase_length,
- /* in */ ChewingKey keys[],
+ /* in */ const ChewingKey keys[],
/* out */ PhraseIndexRanges ranges) const;
void reset();
@@ -74,13 +75,13 @@ public:
table_offset_t & end);
/* search method */
- int search(int phrase_length, /* in */ ChewingKey keys[],
+ int search(int phrase_length, /* in */ const ChewingKey keys[],
/* out */ PhraseIndexRanges ranges) const;
/* add/remove index method */
- int add_index(int phrase_length, /* in */ ChewingKey keys[],
+ int add_index(int phrase_length, /* in */ const ChewingKey keys[],
/* in */ phrase_token_t token);
- int remove_index(int phrase_length, /* in */ ChewingKey keys[],
+ int remove_index(int phrase_length, /* in */ const ChewingKey keys[],
/* in */ phrase_token_t token);
/* mask out method */
@@ -126,18 +127,18 @@ public:
bool load_text(FILE * file);
/* search method */
- int search(int phrase_length, /* in */ ChewingKey keys[],
+ int search(int phrase_length, /* in */ const ChewingKey keys[],
/* out */ PhraseIndexRanges ranges) const {
return m_bitmap_table.search(phrase_length, keys, ranges);
}
/* add/remove index method */
- int add_index(int phrase_length, /* in */ ChewingKey keys[],
+ int add_index(int phrase_length, /* in */ const ChewingKey keys[],
/* in */ phrase_token_t token) {
return m_bitmap_table.add_index(phrase_length, keys, token);
}
- int remove_index(int phrase_length, /* in */ ChewingKey keys[],
+ int remove_index(int phrase_length, /* in */ const ChewingKey keys[],
/* in */ phrase_token_t token) {
return m_bitmap_table.remove_index(phrase_length, keys, token);
}
diff --git a/src/storage/facade_chewing_table.h b/src/storage/facade_chewing_table.h
index 572ce04..474311c 100644
--- a/src/storage/facade_chewing_table.h
+++ b/src/storage/facade_chewing_table.h
@@ -139,7 +139,7 @@ public:
* Search the phrase tokens according to the pinyin keys.
*
*/
- int search(int phrase_length, /* in */ ChewingKey keys[],
+ int search(int phrase_length, /* in */ const ChewingKey keys[],
/* out */ PhraseIndexRanges ranges) const {
/* clear ranges. */
@@ -171,7 +171,7 @@ public:
* Add the phrase token to the user chewing table.
*
*/
- int add_index(int phrase_length, /* in */ ChewingKey keys[],
+ int add_index(int phrase_length, /* in */ const ChewingKey keys[],
/* in */ phrase_token_t token) {
if (NULL == m_user_chewing_table)
return ERROR_NO_USER_TABLE;
@@ -188,7 +188,7 @@ public:
* Remove the phrase token from the user chewing table.
*
*/
- int remove_index(int phrase_length, /* in */ ChewingKey keys[],
+ int remove_index(int phrase_length, /* in */ const ChewingKey keys[],
/* in */ phrase_token_t token) {
if (NULL == m_user_chewing_table)
return ERROR_NO_USER_TABLE;
diff --git a/src/storage/pinyin_phrase2.h b/src/storage/pinyin_phrase2.h
index d5042aa..ba2f32e 100644
--- a/src/storage/pinyin_phrase2.h
+++ b/src/storage/pinyin_phrase2.h
@@ -107,9 +107,9 @@ inline int pinyin_compare_with_ambiguities2(pinyin_option_t options,
/* compute pinyin lower bound */
inline void compute_lower_value2(pinyin_option_t options,
- ChewingKey * in_keys,
- ChewingKey * out_keys,
- int phrase_length) {
+ const ChewingKey * in_keys,
+ ChewingKey * out_keys,
+ int phrase_length) {
ChewingKey aKey;
for (int i = 0; i < phrase_length; ++i) {
@@ -167,7 +167,7 @@ inline void compute_lower_value2(pinyin_option_t options,
/* compute pinyin upper bound */
inline void compute_upper_value2(pinyin_option_t options,
- ChewingKey * in_keys,
+ const ChewingKey * in_keys,
ChewingKey * out_keys,
int phrase_length) {
ChewingKey aKey;
@@ -237,7 +237,8 @@ struct PinyinIndexItem2{
phrase_token_t m_token;
ChewingKey m_keys[phrase_length];
public:
- PinyinIndexItem2<phrase_length> (ChewingKey * keys, phrase_token_t token) {
+ PinyinIndexItem2<phrase_length> (const ChewingKey * keys,
+ phrase_token_t token) {
memmove(m_keys, keys, sizeof(ChewingKey) * phrase_length);
m_token = token;
}