gcs: replace multiplication with shifts.
This commit is contained in:
parent
b994c278f2
commit
3324d18f5f
@ -21,8 +21,7 @@ var DUMMY = Buffer.allocUnsafe(0);
|
||||
function GCSFilter() {
|
||||
this.n = 0;
|
||||
this.p = 0;
|
||||
this.modp = Int64(0);
|
||||
this.modnp = Int64(0);
|
||||
this.m = Int64(0);
|
||||
this.data = DUMMY;
|
||||
}
|
||||
|
||||
@ -41,7 +40,7 @@ GCSFilter.prototype.header = function header(prev) {
|
||||
|
||||
GCSFilter.prototype.match = function match(key, data) {
|
||||
var br = new BitReader(this.data);
|
||||
var term = siphash(data, key).imod(this.modnp);
|
||||
var term = siphash(data, key).imod(this.m);
|
||||
var last = Int64(0);
|
||||
var value;
|
||||
|
||||
@ -75,7 +74,7 @@ GCSFilter.prototype.matchAny = function matchAny(key, items) {
|
||||
|
||||
for (i = 0; i < items.length; i++) {
|
||||
item = items[i];
|
||||
hash = siphash(item, key).imod(this.modnp);
|
||||
hash = siphash(item, key).imod(this.m);
|
||||
values.push(hash);
|
||||
}
|
||||
|
||||
@ -125,7 +124,7 @@ GCSFilter.prototype.readU64 = function readU64(br) {
|
||||
|
||||
rem = br.readBits64(this.p);
|
||||
|
||||
return num.imul(this.modp).iadd(rem);
|
||||
return num.ishln(this.p).iadd(rem);
|
||||
};
|
||||
|
||||
GCSFilter.prototype.toBytes = function toBytes() {
|
||||
@ -171,15 +170,14 @@ GCSFilter.prototype.fromData = function fromData(P, key, items) {
|
||||
|
||||
this.n = items.length;
|
||||
this.p = P;
|
||||
this.modp = Int64(1).ishln(this.p);
|
||||
this.modnp = Int64(this.n).imul(this.modp);
|
||||
this.m = Int64(this.n).ishln(this.p);
|
||||
|
||||
bw = new BitWriter();
|
||||
|
||||
for (i = 0; i < items.length; i++) {
|
||||
item = items[i];
|
||||
assert(Buffer.isBuffer(item));
|
||||
hash = siphash(item, key).imod(this.modnp);
|
||||
hash = siphash(item, key).imod(this.m);
|
||||
values.push(hash);
|
||||
}
|
||||
|
||||
@ -187,7 +185,7 @@ GCSFilter.prototype.fromData = function fromData(P, key, items) {
|
||||
|
||||
for (i = 0; i < values.length; i++) {
|
||||
hash = values[i];
|
||||
rem = hash.sub(last).iand(this.modp.subn(1));
|
||||
rem = hash.sub(last).imaskn(this.p);
|
||||
value = hash.sub(last).isub(rem).ishrn(this.p);
|
||||
last = hash;
|
||||
|
||||
@ -214,8 +212,7 @@ GCSFilter.prototype.fromBytes = function fromBytes(N, P, data) {
|
||||
|
||||
this.n = N;
|
||||
this.p = P;
|
||||
this.modp = Int64(1).ishln(this.p);
|
||||
this.modnp = Int64(this.n).imul(this.modp);
|
||||
this.m = Int64(this.n).ishln(this.p);
|
||||
this.data = data;
|
||||
|
||||
return this;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user