Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit914d30e

Browse files
committed
2048-bit Bloom filter everywhere
1 parent13cf416 commit914d30e

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

‎js/RussianNouns.js‎

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -389,26 +389,25 @@
389389
return((0x7fffffff&hash)*2)+start;
390390
}
391391

392-
functiontoTenBitHash(hash){
393-
// Специально для 1024-битного фильтра Блума
394-
return(hash>>>30)^
395-
((hash>>>20)&0x3ff)^
396-
((hash>>>10)&0x3ff)^
397-
(hash&0x3ff);
392+
functionto11BitHash(hash){
393+
// Специально для 2048-битного фильтра Блума
394+
return((hash>>>22)&0x7ff)^
395+
((hash>>>11)&0x7ff)^
396+
(hash&0x7ff);
398397
}
399398

400399
/**
401-
*@param {Uint8ClampedArray} filter -128 bytes
402-
*@param {number}hash10 -Ten bits
400+
*@param {Uint8ClampedArray} filter -256 bytes
401+
*@param {number}hash11 -Eleven bits
403402
*@returns {boolean}
404403
*/
405-
functioninBloom(filter,hash10){
406-
return!!((filter[hash10>>>3]>>>(7-(hash10%8)))&1);
404+
functioninBloom(filter,hash11){
405+
return!!((filter[hash11>>>3]>>>(7-(hash11%8)))&1);
407406
}
408407

409-
functionbloomAdd(filter,hash10){
410-
constindex=hash10>>>3;
411-
filter[index]=filter[index]|(1<<(7-(hash10%8)));
408+
functionbloomAdd(filter,hash11){
409+
constindex=hash11>>>3;
410+
filter[index]=filter[index]|(1<<(7-(hash11%8)));
412411
}
413412

414413
functionpackEnding(lowerCaseUnicodeString){
@@ -478,9 +477,9 @@
478477
126869,23630,11218
479478
]);
480479

481-
conststressBloomAB=newUint8ClampedArray(128);
482-
stressHashesA.forEach(h=>bloomAdd(stressBloomAB,toTenBitHash(h)));
483-
stressHashesB.forEach(h=>bloomAdd(stressBloomAB,toTenBitHash(h)));
480+
conststressBloomAB=newUint8ClampedArray(256);
481+
stressHashesA.forEach(h=>bloomAdd(stressBloomAB,to11BitHash(h)));
482+
stressHashesB.forEach(h=>bloomAdd(stressBloomAB,to11BitHash(h)));
484483

485484
// Stemmer data
486485
constmobileVowelA=newSet(['бубен','бугор',
@@ -854,7 +853,7 @@
854853
homonyms.push([extendedFlags,settings]);
855854
}
856855

857-
bloomAdd(_bloomFilter,toTenBitHash(lemmaObject._hash));
856+
bloomAdd(_bloomFilter,to11BitHash(lemmaObject._hash));
858857
};
859858

860859
const_toResult=ch=>{
@@ -872,7 +871,7 @@
872871
}
873872

874873
this.hasStressedEndingSingular=function(query,grCase){
875-
if(inBloom(_bloomFilter,toTenBitHash(query._hash))){
874+
if(inBloom(_bloomFilter,to11BitHash(query._hash))){
876875

877876
constcaseIndex=CaseValues.indexOf(grCase);
878877

@@ -896,7 +895,7 @@
896895
};
897896

898897
this.hasStressedEndingPlural=function(query,grCase){
899-
if(inBloom(_bloomFilter,toTenBitHash(query._hash))){
898+
if(inBloom(_bloomFilter,to11BitHash(query._hash))){
900899

901900
constcaseIndex=CaseValues.indexOf(grCase);
902901

@@ -2064,7 +2063,7 @@
20642063
}
20652064
}
20662065

2067-
consthighPriorityBloomFilter=newUint8ClampedArray(128);
2066+
consthighPriorityBloomFilter=newUint8ClampedArray(256);
20682067
consthighPriorityExceptions=Object.freeze([
20692068
[
20702069
[
@@ -2161,7 +2160,7 @@
21612160

21622161
for(construleofhighPriorityExceptions){
21632162
Object.keys(rule[1]).map(word=>
2164-
bloomAdd(highPriorityBloomFilter,toTenBitHash(calculateHash(word))));
2163+
bloomAdd(highPriorityBloomFilter,to11BitHash(calculateHash(word))));
21652164
}
21662165

21672166
// Слова в первом склонении, которые оканчиваются на -я в мн.ч.,
@@ -2337,7 +2336,7 @@
23372336
}
23382337
}
23392338

2340-
if(inBloom(highPriorityBloomFilter,toTenBitHash(lemma._hash))){
2339+
if(inBloom(highPriorityBloomFilter,to11BitHash(lemma._hash))){
23412340
for(const[key,genderExceptions]ofhighPriorityExceptions){
23422341

23432342
constkeyGender=key[0];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp