oblivious-set
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -6,17 +6,17 @@ /** | ||
*/ | ||
var ObliviousSet = /** @class */ (function () { | ||
function ObliviousSet(ttl) { | ||
export class ObliviousSet { | ||
ttl; | ||
map = new Map(); | ||
/** | ||
* Creating calls to setTimeout() is expensive, | ||
* so we only do that if there is not timeout already open. | ||
*/ | ||
_to = false; | ||
constructor(ttl) { | ||
this.ttl = ttl; | ||
this.map = new Map(); | ||
/** | ||
* Creating calls to setTimeout() is expensive, | ||
* so we only do that if there is not timeout already open. | ||
*/ | ||
this._to = false; | ||
} | ||
ObliviousSet.prototype.has = function (value) { | ||
has(value) { | ||
return this.map.has(value); | ||
}; | ||
ObliviousSet.prototype.add = function (value) { | ||
var _this = this; | ||
} | ||
add(value) { | ||
this.map.set(value, now()); | ||
@@ -31,14 +31,12 @@ /** | ||
this._to = true; | ||
setTimeout(function () { | ||
_this._to = false; | ||
removeTooOldValues(_this); | ||
setTimeout(() => { | ||
this._to = false; | ||
removeTooOldValues(this); | ||
}, 0); | ||
} | ||
}; | ||
ObliviousSet.prototype.clear = function () { | ||
} | ||
clear() { | ||
this.map.clear(); | ||
}; | ||
return ObliviousSet; | ||
}()); | ||
export { ObliviousSet }; | ||
} | ||
} | ||
/** | ||
@@ -49,4 +47,4 @@ * Removes all entries from the set | ||
export function removeTooOldValues(obliviousSet) { | ||
var olderThen = now() - obliviousSet.ttl; | ||
var iterator = obliviousSet.map[Symbol.iterator](); | ||
const olderThen = now() - obliviousSet.ttl; | ||
const iterator = obliviousSet.map[Symbol.iterator](); | ||
/** | ||
@@ -57,8 +55,8 @@ * Because we can assume the new values are added at the bottom, | ||
while (true) { | ||
var next = iterator.next().value; | ||
const next = iterator.next().value; | ||
if (!next) { | ||
return; // no more elements | ||
} | ||
var value = next[0]; | ||
var time = next[1]; | ||
const value = next[0]; | ||
const time = next[1]; | ||
if (time < olderThen) { | ||
@@ -74,4 +72,4 @@ obliviousSet.map.delete(value); | ||
export function now() { | ||
return new Date().getTime(); | ||
return Date.now(); | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.now = exports.removeTooOldValues = exports.ObliviousSet = void 0; | ||
/** | ||
@@ -9,17 +6,17 @@ * this is a set which automatically forgets | ||
*/ | ||
var ObliviousSet = /** @class */ (function () { | ||
function ObliviousSet(ttl) { | ||
export class ObliviousSet { | ||
ttl; | ||
map = new Map(); | ||
/** | ||
* Creating calls to setTimeout() is expensive, | ||
* so we only do that if there is not timeout already open. | ||
*/ | ||
_to = false; | ||
constructor(ttl) { | ||
this.ttl = ttl; | ||
this.map = new Map(); | ||
/** | ||
* Creating calls to setTimeout() is expensive, | ||
* so we only do that if there is not timeout already open. | ||
*/ | ||
this._to = false; | ||
} | ||
ObliviousSet.prototype.has = function (value) { | ||
has(value) { | ||
return this.map.has(value); | ||
}; | ||
ObliviousSet.prototype.add = function (value) { | ||
var _this = this; | ||
} | ||
add(value) { | ||
this.map.set(value, now()); | ||
@@ -34,14 +31,12 @@ /** | ||
this._to = true; | ||
setTimeout(function () { | ||
_this._to = false; | ||
removeTooOldValues(_this); | ||
setTimeout(() => { | ||
this._to = false; | ||
removeTooOldValues(this); | ||
}, 0); | ||
} | ||
}; | ||
ObliviousSet.prototype.clear = function () { | ||
} | ||
clear() { | ||
this.map.clear(); | ||
}; | ||
return ObliviousSet; | ||
}()); | ||
exports.ObliviousSet = ObliviousSet; | ||
} | ||
} | ||
/** | ||
@@ -51,5 +46,5 @@ * Removes all entries from the set | ||
*/ | ||
function removeTooOldValues(obliviousSet) { | ||
var olderThen = now() - obliviousSet.ttl; | ||
var iterator = obliviousSet.map[Symbol.iterator](); | ||
export function removeTooOldValues(obliviousSet) { | ||
const olderThen = now() - obliviousSet.ttl; | ||
const iterator = obliviousSet.map[Symbol.iterator](); | ||
/** | ||
@@ -60,8 +55,8 @@ * Because we can assume the new values are added at the bottom, | ||
while (true) { | ||
var next = iterator.next().value; | ||
const next = iterator.next().value; | ||
if (!next) { | ||
return; // no more elements | ||
} | ||
var value = next[0]; | ||
var time = next[1]; | ||
const value = next[0]; | ||
const time = next[1]; | ||
if (time < olderThen) { | ||
@@ -76,7 +71,5 @@ obliviousSet.map.delete(value); | ||
} | ||
exports.removeTooOldValues = removeTooOldValues; | ||
function now() { | ||
return new Date().getTime(); | ||
export function now() { | ||
return Date.now(); | ||
} | ||
exports.now = now; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "oblivious-set", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Like a JavaScript Set() but with a TTL for entries", | ||
@@ -20,3 +20,3 @@ "license": "MIT", | ||
"transpile": "tsc -p ./ && echo '# transpile es5 (require) sucess!'", | ||
"transpile:es": "tsc -p ./ --target ES5 --module ES6 --outDir ./dist/es && echo '# transpile es (modules) sucess!'", | ||
"transpile:es": "tsc -p ./ --module ES6 --outDir ./dist/es && echo '# transpile es (modules) sucess!'", | ||
"build": "rimraf -r ./dist && npm run transpile && npm run transpile:es", | ||
@@ -30,9 +30,9 @@ "test": "mocha -r ts-node/register test/unit.test.ts --timeout 20000 --bail" | ||
"assert": "2.0.0", | ||
"async-test-util": "1.7.3", | ||
"async-test-util": "2.2.0", | ||
"mocha": "8.4.0", | ||
"rimraf": "3.0.2", | ||
"ts-node": "10.0.0", | ||
"ts-node": "10.9.1", | ||
"tslint": "6.1.3", | ||
"typescript": "4.3.2" | ||
"typescript": "5.2.2" | ||
} | ||
} |
@@ -80,5 +80,5 @@ | ||
export function now(): number { | ||
return new Date().getTime(); | ||
return Date.now(); | ||
} | ||
@@ -11,3 +11,2 @@ { | ||
"noImplicitThis": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"downlevelIteration": true, | ||
@@ -17,3 +16,3 @@ "declaration": true, | ||
"esModuleInterop": true, | ||
"target": "es5", | ||
"target": "es2022", | ||
"outDir": "./dist/lib", | ||
@@ -20,0 +19,0 @@ "lib": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18018
450