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

@blackglory/structures

Package Overview
Dependencies
Maintainers
0
Versions
101
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blackglory/structures - npm Package Compare versions

Comparing version 0.14.7 to 0.14.8

7

lib/async-generator-emitter.js
import { go, goAsyncGenerator } from '@blackglory/go';
export class AsyncGeneratorEmitter {
constructor() {
this.map = new Map();
}
map = new Map();
get [Symbol.toStringTag]() {

@@ -51,6 +49,5 @@ return this.constructor.name;

removeAllListeners(event) {
var _a;
(_a = this.map.get(event)) === null || _a === void 0 ? void 0 : _a.clear();
this.map.get(event)?.clear();
}
}
//# sourceMappingURL=async-generator-emitter.js.map
export class BigMap {
constructor() {
this._maps = [];
}
_maps = [];
get [Symbol.toStringTag]() {

@@ -6,0 +4,0 @@ return this.constructor.name;

export class BigSet {
constructor() {
this._sets = [];
}
_sets = [];
get [Symbol.toStringTag]() {

@@ -6,0 +4,0 @@ return this.constructor.name;

import { assert } from '@blackglory/errors';
import { trailingZeros } from "./utils/trailing-zeros.js";
export class BitSet {
bitsPerElement;
array = [];
length = 0;
_size = 0;
constructor(bitsPerElement = 8) {
this.bitsPerElement = bitsPerElement;
this.array = [];
this.length = 0;
this._size = 0;
assert(Number.isInteger(bitsPerElement), 'The parameter bitsPerElement must be an integer');

@@ -51,8 +52,6 @@ assert(bitsPerElement > 0, 'The parameter bitsPerElement must be greater than 0');

has(value) {
var _a;
const [index, mask] = this.getPosition(value);
return (((_a = this.array[index]) !== null && _a !== void 0 ? _a : 0) & mask) === mask;
return ((this.array[index] ?? 0) & mask) === mask;
}
add(value) {
var _a;
assert(value >= 0, 'value must be greater than or equal to 0');

@@ -63,3 +62,3 @@ if (value >= this.length) {

const [index, mask] = this.getPosition(value);
const element = (_a = this.array[index]) !== null && _a !== void 0 ? _a : 0;
const element = this.array[index] ?? 0;
this.array[index] = element | mask;

@@ -73,5 +72,4 @@ const added = (element & mask) !== mask;

delete(value) {
var _a;
const [index, mask] = this.getPosition(value);
const element = ((_a = this.array[index]) !== null && _a !== void 0 ? _a : 0);
const element = (this.array[index] ?? 0);
this.array[index] = element & ~mask;

@@ -78,0 +76,0 @@ const deleted = (element & mask) === mask;

export class Box {
value;
get [Symbol.toStringTag]() {

@@ -3,0 +4,0 @@ return this.constructor.name;

import { assert } from '@blackglory/errors';
import { isntUndefined } from 'extra-utils';
export class DisjointSet {
constructor() {
this.parent = [];
this.rank = [];
}
parent = [];
rank = [];
has(value) {

@@ -9,0 +7,0 @@ return isntUndefined(this.parent[value]);

import { assert } from '@blackglory/errors';
export class DynamicTypedArray {
typedArrayConstructor;
array;
_length = 0;
initialCapacity;
growthFactor;
get internalTypedArray() {

@@ -20,3 +25,2 @@ return this.array;

this.typedArrayConstructor = typedArrayConstructor;
this._length = 0;
assert(Number.isInteger(capacity), 'capacity must be an integer');

@@ -23,0 +27,0 @@ assert(capacity >= 0, 'capacity must be greater than or equal to 0');

import { go } from '@blackglory/go';
export class Emitter {
constructor() {
this.map = new Map();
}
map = new Map();
get [Symbol.toStringTag]() {

@@ -43,10 +41,8 @@ return this.constructor.name;

emit(event, ...args) {
var _a;
(_a = this.map.get(event)) === null || _a === void 0 ? void 0 : _a.forEach(cb => cb(...args));
this.map.get(event)?.forEach(cb => cb(...args));
}
removeAllListeners(event) {
var _a;
(_a = this.map.get(event)) === null || _a === void 0 ? void 0 : _a.clear();
this.map.get(event)?.clear();
}
}
//# sourceMappingURL=emitter.js.map
import { setSchedule } from 'extra-timers';
export class ExpirableMap {
constructor() {
this.map = new Map();
this.itemMetadataSortedByExpirationTime = [];
}
map = new Map();
cancelScheduledCleaner;
itemMetadataSortedByExpirationTime = [];
get [Symbol.toStringTag]() {

@@ -26,3 +25,2 @@ return this.constructor.name;

delete(key) {
var _a;
const exists = this.map.delete(key);

@@ -33,3 +31,3 @@ if (exists) {

if (index === 0) {
(_a = this.cancelScheduledCleaner) === null || _a === void 0 ? void 0 : _a.call(this);
this.cancelScheduledCleaner?.();
this.scheduleCleaner();

@@ -41,9 +39,7 @@ }

clear() {
var _a;
this.map.clear();
(_a = this.cancelScheduledCleaner) === null || _a === void 0 ? void 0 : _a.call(this);
this.cancelScheduledCleaner?.();
this.itemMetadataSortedByExpirationTime = [];
}
addItemMetadata(key, expirationTime) {
var _a, _b;
for (let i = 0; i < this.itemMetadataSortedByExpirationTime.length; i++) {

@@ -54,3 +50,3 @@ const item = this.itemMetadataSortedByExpirationTime[i];

if (i === 0) {
(_a = this.cancelScheduledCleaner) === null || _a === void 0 ? void 0 : _a.call(this);
this.cancelScheduledCleaner?.();
this.scheduleCleaner();

@@ -63,3 +59,3 @@ }

if (this.itemMetadataSortedByExpirationTime.length === 1) {
(_b = this.cancelScheduledCleaner) === null || _b === void 0 ? void 0 : _b.call(this);
this.cancelScheduledCleaner?.();
this.scheduleCleaner();

@@ -69,3 +65,2 @@ }

removeItemMetadata(key) {
var _a;
const index = this.itemMetadataSortedByExpirationTime.findIndex(x => x.key === key);

@@ -75,3 +70,3 @@ if (index >= 0) {

if (index === 0) {
(_a = this.cancelScheduledCleaner) === null || _a === void 0 ? void 0 : _a.call(this);
this.cancelScheduledCleaner?.();
this.scheduleCleaner();

@@ -86,5 +81,4 @@ }

this.cancelScheduledCleaner = setSchedule(item.expirationTime, () => {
var _a;
this.clearExpiredItems(Date.now());
(_a = this.cancelScheduledCleaner) === null || _a === void 0 ? void 0 : _a.call(this);
this.cancelScheduledCleaner?.();
this.scheduleCleaner();

@@ -91,0 +85,0 @@ });

import { go, goGenerator } from '@blackglory/go';
export class GeneratorEmitter {
constructor() {
this.map = new Map();
}
map = new Map();
get [Symbol.toStringTag]() {

@@ -51,6 +49,5 @@ return this.constructor.name;

removeAllListeners(event) {
var _a;
(_a = this.map.get(event)) === null || _a === void 0 ? void 0 : _a.clear();
this.map.get(event)?.clear();
}
}
//# sourceMappingURL=generator-emitter.js.map
export class HashMap {
hash;
map = new Map();
get [Symbol.toStringTag]() {

@@ -10,3 +12,2 @@ return this.constructor.name;

this.hash = hash;
this.map = new Map();
}

@@ -13,0 +14,0 @@ set(key, value) {

@@ -12,3 +12,4 @@ export declare class HashSet<V, Hash = unknown> implements Iterable<V> {

clear(): void;
keys(): IterableIterator<V>;
values(): IterableIterator<V>;
}
export class HashSet {
hash;
map = new Map();
get [Symbol.toStringTag]() {

@@ -13,3 +15,2 @@ return this.constructor.name;

this.hash = hash;
this.map = new Map();
}

@@ -29,2 +30,5 @@ add(value) {

}
keys() {
return this.values();
}
values() {

@@ -31,0 +35,0 @@ return this.map.values();

import { assert } from '@blackglory/errors';
import { first } from 'iterable-operator';
export class LRUMap {
limit;
map = new Map();
get [Symbol.toStringTag]() {

@@ -11,3 +13,2 @@ return this.constructor.name;

constructor(limit) {
this.map = new Map();
assert(Number.isInteger(limit), 'The parameter limit must be an integer');

@@ -14,0 +15,0 @@ assert(limit > 0, 'The parameter limit must be a positive value');

export class Queue {
constructor() {
this.items = [];
}
items = [];
get [Symbol.toStringTag]() {

@@ -6,0 +4,0 @@ return this.constructor.name;

import { toArray, first, map, find } from 'iterable-operator';
import { isntUndefined } from 'extra-utils';
class TreeNode {
value;
children = new Map();
constructor(value) {
this.value = value;
this.children = new Map();
}
}
export class RadixTree {
constructor() {
this.root = new TreeNode();
}
root = new TreeNode();
get [Symbol.toStringTag]() {

@@ -14,0 +13,0 @@ return this.constructor.name;

import { SkipList } from "./utils/skip-list.js";
import { map } from 'iterable-operator';
export class SortedSet {
skipList;
get [Symbol.toStringTag]() {

@@ -5,0 +6,0 @@ return this.constructor.name;

export class SparseMap {
constructor() {
this.keyToIndex = [];
this.indexToKey = [];
this.indexToValue = [];
}
keyToIndex = [];
indexToKey = [];
indexToValue = [];
get [Symbol.toStringTag]() {

@@ -8,0 +6,0 @@ return this.constructor.name;

export class SparseSet {
indexToValue = [];
valueToIndex;
get [Symbol.toStringTag]() {

@@ -12,3 +14,2 @@ return this.constructor.name;

constructor(array = []) {
this.indexToValue = [];
const valueToIndex = [];

@@ -15,0 +16,0 @@ if (array.length > 0) {

import { toArray, first, map, find } from 'iterable-operator';
import { isntUndefined } from 'extra-utils';
class TreeNode {
value;
children = new Map();
constructor(value) {
this.value = value;
this.children = new Map();
}
}
export class StringRadixTree {
constructor() {
this.root = new TreeNode();
}
root = new TreeNode();
get [Symbol.toStringTag]() {

@@ -14,0 +13,0 @@ return this.constructor.name;

import { zip, toArray, map } from 'iterable-operator';
import { isntUndefined } from 'extra-utils';
class TrieNode {
value;
children = new Map();
constructor(value) {
this.value = value;
this.children = new Map();
}
}
export class StringTrieMap {
constructor() {
this.root = new TrieNode();
}
root = new TrieNode();
get [Symbol.toStringTag]() {

@@ -14,0 +13,0 @@ return this.constructor.name;

@@ -5,2 +5,6 @@ import { assert } from '@blackglory/errors';

export class TLRUMap {
limit;
map = new Map();
cancelClearTimeout;
itemMetadataSortedByExpirationTime = [];
get [Symbol.toStringTag]() {

@@ -13,4 +17,2 @@ return this.constructor.name;

constructor(limit) {
this.map = new Map();
this.itemMetadataSortedByExpirationTime = [];
assert(Number.isInteger(limit), 'The parameter limit must be an integer');

@@ -60,5 +62,4 @@ assert(limit > 0, 'The parameter limit must be a positive value');

clear() {
var _a;
this.map.clear();
(_a = this.cancelClearTimeout) === null || _a === void 0 ? void 0 : _a.call(this);
this.cancelClearTimeout?.();
this.itemMetadataSortedByExpirationTime = [];

@@ -103,4 +104,3 @@ }

rescheduleClearTimeout() {
var _a;
(_a = this.cancelClearTimeout) === null || _a === void 0 ? void 0 : _a.call(this);
this.cancelClearTimeout?.();
if (this.itemMetadataSortedByExpirationTime.length > 0) {

@@ -107,0 +107,0 @@ const item = this.itemMetadataSortedByExpirationTime[0];

import { zip, toArray, map } from 'iterable-operator';
import { isntUndefined } from 'extra-utils';
class TrieNode {
value;
children = new Map();
constructor(value) {
this.value = value;
this.children = new Map();
}
}
export class TrieMap {
constructor() {
this.root = new TrieNode();
}
root = new TrieNode();
get [Symbol.toStringTag]() {

@@ -14,0 +13,0 @@ return this.constructor.name;

import { assert } from '@blackglory/errors';
import { trailingZeros } from "./utils/trailing-zeros.js";
export class TypedBitSet {
array;
bitsPerElement;
length = 0;
_size = 0;
constructor(array) {
this.array = array;
this.length = 0;
this._size = 0;
const bitsPerElement = array.BYTES_PER_ELEMENT * 8;

@@ -52,8 +54,6 @@ assert(Number.isInteger(bitsPerElement), 'The parameter bitsPerElement must be an integer');

has(value) {
var _a;
const [index, mask] = this.getPosition(value);
return (((_a = this.array.get(index)) !== null && _a !== void 0 ? _a : 0) & mask) === mask;
return ((this.array.get(index) ?? 0) & mask) === mask;
}
add(value) {
var _a;
assert(value >= 0, 'value must be greater than or equal to 0');

@@ -64,3 +64,3 @@ if (value >= this.length) {

const [index, mask] = this.getPosition(value);
const element = (_a = this.array.get(index)) !== null && _a !== void 0 ? _a : 0;
const element = this.array.get(index) ?? 0;
this.array.set(index, element | mask);

@@ -74,5 +74,4 @@ const added = (element & mask) !== mask;

delete(value) {
var _a;
const [index, mask] = this.getPosition(value);
const element = ((_a = this.array.get(index)) !== null && _a !== void 0 ? _a : 0);
const element = (this.array.get(index) ?? 0);
this.array.set(index, element & ~mask);

@@ -79,0 +78,0 @@ const deleted = (element & mask) === mask;

import { assert } from '@blackglory/errors';
export class TypedSparseMap {
keyToIndex = [];
indexToKey = [];
indexToValue;
get [Symbol.toStringTag]() {

@@ -13,4 +16,2 @@ return this.constructor.name;

constructor(array) {
this.keyToIndex = [];
this.indexToKey = [];
assert(array.length === 0, 'array should be empty');

@@ -17,0 +18,0 @@ this.indexToValue = array;

export class TypedSparseSet {
valueToIndex;
indexToValue;
constructor(array) {

@@ -3,0 +5,0 @@ const valueToIndex = [];

import { isntNull } from 'extra-utils';
export class SkipListNode {
value;
previous = null;
next = null;
up = null;
down = null;
constructor(value) {
this.value = value;
this.previous = null;
this.next = null;
this.up = null;
this.down = null;
}
}
export class SkipList {
compare;
head = new SkipListNode(null);
tail = new SkipListNode(null);
height = 0;
_size = 0;
get size() {

@@ -17,6 +23,2 @@ return this._size;

this.compare = compare;
this.head = new SkipListNode(null);
this.tail = new SkipListNode(null);
this.height = 0;
this._size = 0;
this.head.next = this.tail;

@@ -23,0 +25,0 @@ this.tail.previous = this.head;

{
"name": "@blackglory/structures",
"version": "0.14.7",
"version": "0.14.8",
"description": "",

@@ -5,0 +5,0 @@ "files": [

@@ -258,2 +258,3 @@ # structures

clear(): void
keys(): IterableIterator<V>
values(): IterableIterator<V>

@@ -260,0 +261,0 @@ }

@@ -1,2 +0,2 @@

export class HashSet<V, Hash = unknown> implements Iterable<V> {
export class HashSet<V, Hash = unknown> implements Iterable<V> /* ReadonlySetLike<V> */ {
private map = new Map<Hash, V>()

@@ -35,2 +35,6 @@

keys(): IterableIterator<V> {
return this.values()
}
values(): IterableIterator<V> {

@@ -37,0 +41,0 @@ return this.map.values()

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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