Skip to content

Commit

Permalink
Merge pull request #14 from czchen/master
Browse files Browse the repository at this point in the history
Move several global variables into ChewingData
  • Loading branch information
kanru committed Oct 4, 2012
2 parents e6d0d24 + 0935184 commit 2ca7235
Show file tree
Hide file tree
Showing 20 changed files with 546 additions and 415 deletions.
3 changes: 0 additions & 3 deletions include/chewing.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ extern "C" {
*/
#define LIBCHEWING_ENCODING "UTF-8"

/* statistics symbol reported by chewing */
extern int chewing_lifetime;

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 5 additions & 3 deletions include/internal/char-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define _CHEWING_CHAR_PRIVATE_H

#include "global.h"
#include "chewing-private.h"

#ifndef SEEK_SET
#define SEEK_SET 0
Expand All @@ -21,8 +22,9 @@ typedef struct {
char word[ 7 ];
} Word;

int GetCharFirst( Word *, uint16 );
int GetCharNext ( Word * );
int InitChar( const char * );
int GetCharFirst( ChewingData *, Word *, uint16 );
int GetCharNext ( ChewingData *, Word * );
int InitChar( ChewingData *pgdata, const char * prefix );
void TerminateChar( ChewingData *pgdata );

#endif
62 changes: 62 additions & 0 deletions include/internal/chewing-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
#ifndef _CHEWING_CORE_PRIVATE_H
#define _CHEWING_CORE_PRIVATE_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "global.h"
#include <wchar.h>
#include "plat_mmap.h"

#define MAX_KBTYPE 11
#define WCH_SIZE 4
Expand All @@ -24,6 +29,8 @@
#define MAX_INTERVAL ( ( MAX_PHONE_SEQ_LEN + 1 ) * MAX_PHONE_SEQ_LEN / 2 )
#define MAX_CHOICE (567)
#define MAX_CHOICE_BUF (50) /* max length of the choise buffer */
#define N_HASH_BIT (14)
#define HASH_TABLE_SIZE (1<<N_HASH_BIT)

#ifndef max
#define max(a, b) \
Expand Down Expand Up @@ -116,6 +123,21 @@ typedef struct _SymbolEntry {
char symbols[ 1 ][ MAX_UTF8_SIZE + 1 ];
} SymbolEntry;

typedef struct {
uint16 *phoneSeq;
char *wordSeq;
int userfreq;
int recentTime;
int origfreq; /* the initial frequency of this phrase */
int maxfreq; /* the maximum frequency of the phrase of the same pid */
} UserPhraseData ;

typedef struct tag_HASH_ITEM {
int item_index;
UserPhraseData data;
struct tag_HASH_ITEM *next;
} HASH_ITEM;

typedef struct {
AvailInfo availInfo;
ChoiceInfo choiceInfo;
Expand Down Expand Up @@ -146,6 +168,46 @@ typedef struct {
int bChiSym, bSelect, bCaseChange, bFirstKey, bFullShape;
/* Symbol Key buffer */
char symbolKeyBuf[ MAX_PHONE_SEQ_LEN ];

TreeType *tree;
size_t tree_size;
#ifdef USE_BINARY_DATA
plat_mmap tree_mmap;
#endif

uint16 *arrPhone;
int *char_begin;
size_t phone_num;
void *char_;
void *char_cur_pos;
int char_end_pos;
#ifdef USE_BINARY_DATA
plat_mmap char_mmap;
plat_mmap char_begin_mmap;
plat_mmap char_phone_mmap;
#else
FILE *charfile;
#endif

int *dict_begin;
void *dict_cur_pos;
int dict_end_pos;

void *dict;

#ifdef USE_BINARY_DATA
plat_mmap dict_mmap;
plat_mmap index_mmap;
#else
FILE *dictfile;
#endif


int chewing_lifetime;

char hashfilename[ 200 ];
HASH_ITEM *hashtable[ HASH_TABLE_SIZE ];
HASH_ITEM *pHead;
} ChewingData;

typedef struct {
Expand Down
7 changes: 4 additions & 3 deletions include/internal/dict-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@

#define PHONE_PHRASE_NUM (162244)

int GetPhraseFirst( Phrase *phr_ptr, int phone_phr_id );
int GetPhraseNext ( Phrase *phr_ptr );
int InitDict( const char * );
int GetPhraseFirst( ChewingData *pgdata, Phrase *phr_ptr, int phone_phr_id );
int GetPhraseNext ( ChewingData *pgdata, Phrase *phr_ptr );
int InitDict( ChewingData *pgdata, const char * prefix );
void TerminateDict( ChewingData *pgdata );

#endif
19 changes: 6 additions & 13 deletions include/internal/hash-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,17 @@
#endif

#define FIELD_SIZE (125)
#define N_HASH_BIT (14)
#define BIN_HASH_SIG "CBiH"
#define HASH_FILE "uhash.dat"
#define HASH_TABLE_SIZE (1<<N_HASH_BIT)

typedef struct tag_HASH_ITEM {
int item_index;
UserPhraseData data;
struct tag_HASH_ITEM *next;
} HASH_ITEM;

HASH_ITEM *HashFindPhone( const uint16 phoneSeq[] );
HASH_ITEM *HashFindEntry( const uint16 phoneSeq[], const char wordSeq[] );
HASH_ITEM *HashInsert( UserPhraseData *pData );
HASH_ITEM *HashFindPhonePhrase( const uint16 phoneSeq[], HASH_ITEM *pHashLast );
void HashModify( HASH_ITEM *pItem );
HASH_ITEM *HashFindEntry( ChewingData *pgdata, const uint16 phoneSeq[], const char wordSeq[] );
HASH_ITEM *HashInsert( ChewingData *pgdata, UserPhraseData *pData );
HASH_ITEM *HashFindPhonePhrase( ChewingData *pgdata, const uint16 phoneSeq[], HASH_ITEM *pHashLast );
void HashModify( ChewingData *pgdata, HASH_ITEM *pItem );
int AlcUserPhraseSeq( UserPhraseData *pData, int phonelen, int wordlen );
int InitHash( const char *path );
int InitHash( ChewingData *ctx );
void TerminateHash( ChewingData *pgdata );
void FreeHashTable( void );

#endif
8 changes: 5 additions & 3 deletions include/internal/tree-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
#define IS_USER_PHRASE 1
#define IS_DICT_PHRASE 0

void InitTree( const char * );
int Phrasing( PhrasingOutput *ppo, uint16 phoneSeq[], int nPhoneSeq,
int InitTree( ChewingData *pgdata, const char *prefix );
void TerminateTree( ChewingData *pgdata );

int Phrasing( ChewingData *pgdata, PhrasingOutput *ppo, uint16 phoneSeq[], int nPhoneSeq,
char selectStr[][ MAX_PHONE_SEQ_LEN * MAX_UTF8_SIZE + 1 ],
IntervalType selectInterval[], int nSelect,
int bArrBrkpt[], int bUserArrCnnct[] );
int IsIntersect( IntervalType in1, IntervalType in2 );

int TreeFindPhrase( int begin, int end, const uint16 *phoneSeq );
int TreeFindPhrase( ChewingData *pgdata, int begin, int end, const uint16 *phoneSeq );

#endif
15 changes: 3 additions & 12 deletions include/internal/userphrase-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@
#define USER_UPDATE_MODIFY (2)
#define USER_UPDATE_IGNORE (8)

typedef struct {
uint16 *phoneSeq;
char *wordSeq;
int userfreq;
int recentTime;
int origfreq; /* the initial frequency of this phrase */
int maxfreq; /* the maximum frequency of the phrase of the same pid */
} UserPhraseData ;

/**
* @brief Update or add a new UserPhrase.
*
Expand All @@ -44,7 +35,7 @@ typedef struct {
* @retval USER_UPDATE_INSERT Sequence is new, add new entry.
* @retval USER_UPDATE_MODIFY Sequence is existing, update it's data.
*/
int UserUpdatePhrase( const uint16 phoneSeq[], const char wordSeq[] );
int UserUpdatePhrase( ChewingData *pgdata, const uint16 phoneSeq[], const char wordSeq[] );

/**
* @brief Read the first phrase of the phone in user phrase database.
Expand All @@ -53,7 +44,7 @@ int UserUpdatePhrase( const uint16 phoneSeq[], const char wordSeq[] );
*
* @return UserPhraseData, if it's not existing then return NULL.
*/
UserPhraseData *UserGetPhraseFirst( const uint16 phoneSeq[] );
UserPhraseData *UserGetPhraseFirst( ChewingData *pgdata, const uint16 phoneSeq[] );

/**
* @brief Read the next phrase of the phone in user phrase database.
Expand All @@ -62,6 +53,6 @@ UserPhraseData *UserGetPhraseFirst( const uint16 phoneSeq[] );
*
* @return UserPhraseData, if it's not existing then return NULL.
*/
UserPhraseData *UserGetPhraseNext( const uint16 phoneSeq[] );
UserPhraseData *UserGetPhraseNext( ChewingData *pgdata, const uint16 phoneSeq[] );

#endif
2 changes: 1 addition & 1 deletion include/internal/zuin-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ enum {
KB_TYPE_NUM
};

int ZuinPhoInput( ZuinData *,int key ); /* assume `key' is "ascii" code. */
int ZuinPhoInput( ChewingData *, ZuinData *,int key ); /* assume `key' is "ascii" code. */
int ZuinRemoveLast( ZuinData * );
int ZuinRemoveAll( ZuinData * );
int ZuinIsEntering( ZuinData * );
Expand Down

0 comments on commit 2ca7235

Please sign in to comment.