Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oblivious-set

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oblivious-set - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

3

dist/es/index.d.ts

@@ -8,4 +8,3 @@ /**

readonly ttl: number;
readonly set: Set<unknown>;
readonly timeMap: Map<any, any>;
readonly map: Map<any, any>;
constructor(ttl: number);

@@ -12,0 +11,0 @@ has(value: T): boolean;

@@ -9,12 +9,10 @@ /**

this.ttl = ttl;
this.set = new Set();
this.timeMap = new Map();
this.map = new Map();
}
ObliviousSet.prototype.has = function (value) {
return this.set.has(value);
return this.map.has(value);
};
ObliviousSet.prototype.add = function (value) {
var _this = this;
this.timeMap.set(value, now());
this.set.add(value);
this.map.set(value, now());
/**

@@ -31,4 +29,3 @@ * When a new value is added,

ObliviousSet.prototype.clear = function () {
this.set.clear();
this.timeMap.clear();
this.map.clear();
};

@@ -44,3 +41,3 @@ return ObliviousSet;

var olderThen = now() - obliviousSet.ttl;
var iterator = obliviousSet.set[Symbol.iterator]();
var iterator = obliviousSet.map[Symbol.iterator]();
/**

@@ -51,10 +48,10 @@ * Because we can assume the new values are added at the bottom,

while (true) {
var value = iterator.next().value;
if (!value) {
var next = iterator.next().value;
if (!next) {
return; // no more elements
}
var time = obliviousSet.timeMap.get(value);
var value = next[0];
var time = next[1];
if (time < olderThen) {
obliviousSet.timeMap.delete(value);
obliviousSet.set.delete(value);
obliviousSet.map.delete(value);
}

@@ -61,0 +58,0 @@ else {

@@ -8,4 +8,3 @@ /**

readonly ttl: number;
readonly set: Set<unknown>;
readonly timeMap: Map<any, any>;
readonly map: Map<any, any>;
constructor(ttl: number);

@@ -12,0 +11,0 @@ has(value: T): boolean;

@@ -12,12 +12,10 @@ "use strict";

this.ttl = ttl;
this.set = new Set();
this.timeMap = new Map();
this.map = new Map();
}
ObliviousSet.prototype.has = function (value) {
return this.set.has(value);
return this.map.has(value);
};
ObliviousSet.prototype.add = function (value) {
var _this = this;
this.timeMap.set(value, now());
this.set.add(value);
this.map.set(value, now());
/**

@@ -34,4 +32,3 @@ * When a new value is added,

ObliviousSet.prototype.clear = function () {
this.set.clear();
this.timeMap.clear();
this.map.clear();
};

@@ -47,3 +44,3 @@ return ObliviousSet;

var olderThen = now() - obliviousSet.ttl;
var iterator = obliviousSet.set[Symbol.iterator]();
var iterator = obliviousSet.map[Symbol.iterator]();
/**

@@ -54,10 +51,10 @@ * Because we can assume the new values are added at the bottom,

while (true) {
var value = iterator.next().value;
if (!value) {
var next = iterator.next().value;
if (!next) {
return; // no more elements
}
var time = obliviousSet.timeMap.get(value);
var value = next[0];
var time = next[1];
if (time < olderThen) {
obliviousSet.timeMap.delete(value);
obliviousSet.set.delete(value);
obliviousSet.map.delete(value);
}

@@ -64,0 +61,0 @@ else {

{
"name": "oblivious-set",
"version": "1.0.0",
"version": "1.1.0",
"description": "Like a JavaScript Set() but with a TTL for entries",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -8,4 +8,3 @@

export class ObliviousSet<T = any> {
public readonly set = new Set();
public readonly timeMap = new Map();
public readonly map = new Map();
constructor(

@@ -16,8 +15,7 @@ public readonly ttl: number

has(value: T): boolean {
return this.set.has(value);
return this.map.has(value);
}
add(value: T): void {
this.timeMap.set(value, now());
this.set.add(value);
this.map.set(value, now());

@@ -36,4 +34,3 @@ /**

clear() {
this.set.clear();
this.timeMap.clear();
this.map.clear();
}

@@ -51,3 +48,3 @@ }

const olderThen = now() - obliviousSet.ttl;
const iterator = obliviousSet.set[Symbol.iterator]();
const iterator = obliviousSet.map[Symbol.iterator]();

@@ -59,10 +56,12 @@ /**

while (true) {
const value = iterator.next().value;
if (!value) {
const next = iterator.next().value;
if (!next) {
return; // no more elements
}
const time = obliviousSet.timeMap.get(value);
const value = next[0];
const time = next[1];
if (time < olderThen) {
obliviousSet.timeMap.delete(value);
obliviousSet.set.delete(value);
obliviousSet.map.delete(value);
} else {

@@ -69,0 +68,0 @@ // We reached a value that is not old enough

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc