PageRenderTime 22ms CodeModel.GetById 13ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/src/im/gpinyin/include/lpicache.h

http://ftk.googlecode.com/
C++ Header | 62 lines | 22 code | 12 blank | 28 comment | 0 complexity | 2b0e944d7ae7b54e728b16f55a309157 MD5 | raw file
 1/*
 2 * Copyright (C) 2009 The Android Open Source Project
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *      http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef PINYINIME_ANDPY_INCLUDE_LPICACHE_H__
18#define PINYINIME_ANDPY_INCLUDE_LPICACHE_H__
19
20#include <stdlib.h>
21#include "./searchutility.h"
22#include "./spellingtrie.h"
23
24namespace ime_pinyin {
25
26// Used to cache LmaPsbItem list for half spelling ids.
27class LpiCache {
28 private:
29  static LpiCache *instance_;
30  static const int kMaxLpiCachePerId = 15;
31
32  LmaPsbItem *lpi_cache_;
33  uint16 *lpi_cache_len_;
34
35 public:
36  LpiCache();
37  ~LpiCache();
38
39  static LpiCache& get_instance();
40
41  // Test if the LPI list of the given splid  has been cached.
42  // If splid is a full spelling id, it returns false, because we only cache
43  // list for half ids.
44  bool is_cached(uint16 splid);
45
46  // Put LPI list to cahce. If the length of the list, lpi_num, is longer than
47  // the cache buffer. the list will be truncated, and function returns the
48  // maximum length of the cache buffer.
49  // Note: splid must be a half id, and lpi_items must be not NULL. The
50  // caller of this function should guarantee this.
51  unsigned put_cache(uint16 splid, LmaPsbItem lpi_items[], unsigned lpi_num);
52
53  // Get the cached list for the given half id.
54  // Return the length of the cached buffer.
55  // Note: splid must be a half id, and lpi_items must be not NULL. The
56  // caller of this function should guarantee this.
57  unsigned get_cache(uint16 splid, LmaPsbItem lpi_items[], unsigned lpi_max);
58};
59
60}  // namespace
61
62#endif  // PINYINIME_ANDPY_INCLUDE_LPICACHE_H__