add get_shengmu/yunmu_string
[platform/upstream/libpinyin.git] / src / storage / phrase_large_table2.h
index 6a73851..368d03d 100644 (file)
@@ -55,6 +55,9 @@ public:
     int add_index(int phrase_length, /* in */ ucs4_t phrase[], /* in */ phrase_token_t token);
 
     int remove_index(int phrase_length, /* in */ ucs4_t phrase[], /* in */ phrase_token_t token);
+
+    /* mask out method */
+    bool mask_out(phrase_token_t mask, phrase_token_t value);
 };
 
 
@@ -106,10 +109,15 @@ public:
     int remove_index(int phrase_length, /* in */ ucs4_t phrase[], /* in */ phrase_token_t token) {
         return m_bitmap_table.remove_index(phrase_length, phrase, token);
     }
+
+    /* mask out method */
+    bool mask_out(phrase_token_t mask, phrase_token_t value) {
+        return m_bitmap_table.mask_out(mask, value);
+    }
 };
 
 
-static inline int reduce_tokens(PhraseTokens tokens,
+static inline int reduce_tokens(const PhraseTokens tokens,
                                 GArray * tokenarray) {
     int num = 0;
     g_array_set_size(tokenarray, 0);
@@ -131,24 +139,15 @@ static inline int reduce_tokens(PhraseTokens tokens,
 }
 
 /* for compatibility. */
-static inline int get_first_token(PhraseTokens tokens,
+static inline int get_first_token(const PhraseTokens tokens,
                                   /* out */ phrase_token_t & token){
-    int num = 0; token = null_token;
-
-    for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) {
-        GArray * array = tokens[i];
-        if (NULL == array || 0 == array->len)
-            continue;
+    token = null_token;
 
-        num += array->len;
-
-        if (null_token == token) {
-            token = g_array_index(array, phrase_token_t, 0);
-        }
-    }
-
-    /* the following line will be removed in future after code are verified. */
-    assert(0 == num || 1 == num);
+    GArray * tokenarray = g_array_new(FALSE, FALSE, sizeof(phrase_token_t));
+    int num = reduce_tokens(tokens, tokenarray);
+    if (num)
+        token = g_array_index(tokenarray, phrase_token_t, 0);
+    g_array_free(tokenarray, TRUE);
 
     return num;
 }