00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MF_NGRAMCACHE_H
00024 #define MF_NGRAMCACHE_H
00025
00026 #include "mempool.h"
00027 #include "htable.h"
00028
00029
00030 #define NGRAMCACHE_t ngramcache
00031
00032 #define NGRAMCACHE_LOAD_FACTOR 0.5
00033
00034 typedef struct PROB_AND_STATE_ENTRY {
00035 double logpr;
00036 char* state;
00037 unsigned int statesize;
00038 double bow;
00039 int bol;
00040 bool extendible;
00041 PROB_AND_STATE_ENTRY(double lp=0.0, char* st=NULL, unsigned int stsz=0, double bw=0.0, int bl=0, bool ex=false): logpr(lp), state(st), statesize(stsz), bow(bw), bol(bl), extendible(ex) {};
00042 } prob_and_state_t;
00043
00044 void print(prob_and_state_t* pst, std::ostream& out=std::cout);
00045
00046 class ngramcache
00047 {
00048 private:
00049
00050 static const bool debug=true;
00051
00052 htable<int*>* ht;
00053 mempool *mp;
00054 int maxn;
00055 int ngsize;
00056 int infosize;
00057 int accesses;
00058 int hits;
00059 int entries;
00060 float load_factor;
00061 void print(const int*);
00062
00063 public:
00064 ngramcache(int n,int size,int maxentries,float lf=NGRAMCACHE_LOAD_FACTOR);
00065 ~ngramcache();
00066
00067 int cursize() {
00068 return entries;
00069 }
00070 int maxsize() {
00071 return maxn;
00072 }
00073 void reset(int n=0);
00074 char* get(const int* ngp,char*& info);
00075 char* get(const int* ngp,double& info);
00076 char* get(const int* ngp,prob_and_state_t& info);
00077 int add(const int* ngp,const char*& info);
00078 int add(const int* ngp,const double& info);
00079 int add(const int* ngp,const prob_and_state_t& info);
00080 int isfull() {
00081 return (entries >= maxn);
00082 }
00083 void stat();
00084 inline void used() {
00085 stat();
00086 };
00087
00088 inline float set_load_factor(float value) {
00089 return load_factor=value;
00090 }
00091 };
00092
00093 #endif
00094