summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-04-06 12:49:52 +0800
committerPeng Wu <alexepico@gmail.com>2011-04-06 12:58:08 +0800
commitb92726f8d77634f89b34d4f72efb75a5b3aad586 (patch)
tree85cc659f805e0123ec3322a1c0eda90aa7f9638f
parent06b5488f084c5ad9fe5d70155b8c30ce2099501a (diff)
downloadlibpinyin-b92726f8d77634f89b34d4f72efb75a5b3aad586.tar.gz
libpinyin-b92726f8d77634f89b34d4f72efb75a5b3aad586.tar.xz
libpinyin-b92726f8d77634f89b34d4f72efb75a5b3aad586.zip
begin to write flexible single gram
-rw-r--r--src/pinyin.cpp1
-rw-r--r--src/storage/flexible_ngram.h17
2 files changed, 13 insertions, 5 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index 27f8dbf..cb95b9e 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -1,3 +1,4 @@
#include "pinyin.h"
+#include "flexible_ngram.h"
/* Place holder for combining static libraries in sub-directories. */
diff --git a/src/storage/flexible_ngram.h b/src/storage/flexible_ngram.h
index 2db7837..0f8644c 100644
--- a/src/storage/flexible_ngram.h
+++ b/src/storage/flexible_ngram.h
@@ -24,6 +24,7 @@
#ifndef FLEXIBLE_NGRAM_H
#define FLEXIBLE_NGRAM_H
+#include <db.h>
/* Note: the signature of the template parameters.
* struct MagicHeader, ArrayHeader, ArrayItem.
@@ -33,12 +34,14 @@ typedef GArray * FlexibleBigramPhraseArray;
template<typename ArrayHeader, typename ArrayItem>
class FlexibleSingleGram{
- template<typename MagicHeader, typename ArrayHeader,
- typename ArrayItem>
+ template<typename MH, typename AH,
+ typename AI>
friend class FlexibleBigram;
private:
MemoryChunk m_chunk;
- FlexibleSingleGram(void * buffer, size_t length);
+ FlexibleSingleGram(void * buffer, size_t length){
+ m_chunk.set_chunk(buffer, length, NULL);
+ }
public:
/* item typedefs */
typedef struct{
@@ -47,7 +50,10 @@ public:
} ArrayItemWithToken;
/* Null Constructor */
- FlexibleSingleGram();
+ FlexibleSingleGram(){
+ m_chunk.set_size(sizeof(ArrayHeader));
+ memset(m_chunk.begin(), 0, sizeof(ArrayHeader));
+ }
/* retrieve all items */
bool retrieve_all(/* out */ FlexibleBigramPhraseArray array);
@@ -97,7 +103,8 @@ public:
/* load/store one array. */
bool load(phrase_token_t index,
FlexibleSingleGram<ArrayHeader, ArrayItem> * & single_gram);
- bool store(phrase_token_t index, FlexibleSingleGram * & single_gram);
+ bool store(phrase_token_t index,
+ FlexibleSingleGram<ArrayHeader, ArrayItem> * & single_gram);
/* array of phrase_token_t items, for parameter estimation. */
bool get_all_items(GArray * items);