diff options
author | mfederico <mfederico@1f5c12ca-751b-0410-a591-d2e778427230> | 2006-08-12 00:26:33 +0400 |
---|---|---|
committer | mfederico <mfederico@1f5c12ca-751b-0410-a591-d2e778427230> | 2006-08-12 00:26:33 +0400 |
commit | c36cc656110d18e3d1fb2f9ec050b65726bf9be5 (patch) | |
tree | d09509119f3518c7c8f363af8a320f508ce58133 /irstlm | |
parent | c2399678402ce208b57adc72cc4ed1c3ebcf7073 (diff) |
Some tuning if the caches
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@665 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'irstlm')
-rw-r--r-- | irstlm/src/htable.cpp | 41 | ||||
-rw-r--r-- | irstlm/src/lmtable.h | 6 |
2 files changed, 38 insertions, 9 deletions
diff --git a/irstlm/src/htable.cpp b/irstlm/src/htable.cpp index 88194c409..ad7a8e8ed 100644 --- a/irstlm/src/htable.cpp +++ b/irstlm/src/htable.cpp @@ -23,6 +23,11 @@ #include "mempool.h" #include "htable.h" +//bitwise rotation of unsigned integers + +#define rot_right(a,k) (((a) >> k ) | ((a) << (32-(k)))) +#define rot_left(a,k) (((a) << k ) | ((a) >> (32-(k)))) + using namespace std; htable::htable(int n,int kl,HTYPE ht,size_t (*klf)(const char* )){ @@ -199,16 +204,42 @@ address htable::HashStr(char *key) return h; } +//Herbert Glarner's "HSH 11/13" hash function. +/* +address htable::HashInt(char *key){ + +int *Key=(htype==INTPTR? *(int **)key:(int *)key); + +address state=12345,h=0; +register int i,j; + +int p=7; //precision=8 * sizeof(int)-1, in general must be >=7 + + for (i=0,h=0;i<keylen;i++){ + h = h ^ ((address) Key[i]); + for (j=0;j<p;j++){ + state = rot_left(state,11); //state = state left-rotate 11 bits + h = rot_left(h,13); //h = h left-rotate 13 bits + h ^= state ; //h = h xor state + h = rot_left(h,(state & (address)31)); //h = h left-rotate (state mod 32) bits + h = rot_left(h, (h & (address)31)); //h = h left-rotate (h mod 32) bits + } + } + + return h; +} + +*/ + address htable::HashInt(char *key) { int *Key=(htype==INTPTR? *(int **)key:(int *)key); - //cerr << "hash: " << Key << " length:" << length << "\n"; - register int h; + address h; register int i; - /*Thomas Wang's 32 bit Mix Function*/ + //Thomas Wang's 32 bit Mix Function for (i=0,h=0;i<keylen;i++){ h+=Key[i]; h += ~(h << 15); @@ -219,12 +250,10 @@ address htable::HashInt(char *key) h ^= (h >> 16); }; - //for (i=0,h=0;i<length;i++) h = h * Prime1 ^ Key[i]; - //h %= Prime2; - return h; } + int htable::CompStr(char *key1, char *key2) { assert(key1 && key2); diff --git a/irstlm/src/lmtable.h b/irstlm/src/lmtable.h index 4ef928699..c06b5de63 100644 --- a/irstlm/src/lmtable.h +++ b/irstlm/src/lmtable.h @@ -173,17 +173,17 @@ public: void init_probcache(){ assert(probcache==NULL); - probcache=new ngramcache(maxlev,sizeof(double),2000000); + probcache=new ngramcache(maxlev,sizeof(double),1000000); } void init_statecache(){ assert(statecache==NULL); - statecache=new ngramcache(maxlev-1,sizeof(char *),2000000); + statecache=new ngramcache(maxlev-1,sizeof(char *),200000); } void init_bicache(){ assert(bicache==NULL); - bicache=new ngramcache(2,sizeof(char *),2000000); + bicache=new ngramcache(2,sizeof(char *),200000); } |