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

@blackglory/structures

Package Overview
Dependencies
Maintainers
1
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.1.15 to 0.2.0

lib/es2015/lru-map.d.ts

23

CHANGELOG.md

@@ -5,2 +5,25 @@ # Changelog

## [0.2.0](https://github.com/BlackGlory/structures/compare/v0.1.15...v0.2.0) (2021-05-16)
### ⚠ BREAKING CHANGES
* rewrite
* rename LRU to LRUMap
### Features
* add LRU#clear, LRU#delete ([cdac3dc](https://github.com/BlackGlory/structures/commit/cdac3dcb1521abb0360d04f36097cc9b8027a09c))
* improve Cons ([4564103](https://github.com/BlackGlory/structures/commit/456410346050b5c83c11c85808f447ffcb3484b2))
* improve HashSet, Queue ([da0f515](https://github.com/BlackGlory/structures/commit/da0f5150c04af76d1dc93f2227e00099dacb0280))
* rewrite ([902152b](https://github.com/BlackGlory/structures/commit/902152b0ed00fcb44b90df7e443b62a6147d796a))
### Bug Fixes
* bundle ([0abacc1](https://github.com/BlackGlory/structures/commit/0abacc18c95884206ecb7d6323614bae826ff38c))
* rename LRU to LRUMap ([7f0b8bb](https://github.com/BlackGlory/structures/commit/7f0b8bb3c35cd72bb8b9705ad0c40f09cc2353a2))
### [0.1.15](https://github.com/BlackGlory/structures/compare/v0.1.14...v0.1.15) (2021-05-15)

@@ -7,0 +30,0 @@

1

lib/es2015/cons.d.ts
export declare type Cons<T> = [T, Cons<T>] | [T, null];
export declare function convertConsToArray<T>([value, next]: Cons<T>): T[];
export declare function convertArrayToCons<T>([value, ...next]: T[]): Cons<T>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertConsToArray = void 0;
exports.convertArrayToCons = exports.convertConsToArray = void 0;
function convertConsToArray([value, next]) {

@@ -10,2 +10,6 @@ if (next === null)

exports.convertConsToArray = convertConsToArray;
function convertArrayToCons([value, ...next]) {
return [value, next.length ? convertArrayToCons(next) : null];
}
exports.convertArrayToCons = convertArrayToCons;
//# sourceMappingURL=cons.js.map
declare type Handler<T> = (value: T) => void;
export declare class Emitter<T> {
#private;
get [Symbol.toStringTag](): string;
on(event: string, handler: Handler<T>): void;

@@ -5,0 +6,0 @@ off(event: string, handler: Handler<T>): void;

26

lib/es2015/emitter.js

@@ -15,5 +15,9 @@ "use strict";

}
get [(_map = new WeakMap(), Symbol.toStringTag)]() {
return this.constructor.name;
}
on(event, handler) {
if (!__classPrivateFieldGet(this, _map).has(event))
if (!__classPrivateFieldGet(this, _map).has(event)) {
__classPrivateFieldGet(this, _map).set(event, new Set());
}
const set = __classPrivateFieldGet(this, _map).get(event);

@@ -23,18 +27,18 @@ set.add(handler);

off(event, handler) {
if (__classPrivateFieldGet(this, _map).has(event)) {
const set = __classPrivateFieldGet(this, _map).get(event);
set.delete(handler);
if (set.size === 0)
__classPrivateFieldGet(this, _map).delete(event);
if (!__classPrivateFieldGet(this, _map).has(event))
return;
const handlers = __classPrivateFieldGet(this, _map).get(event);
handlers.delete(handler);
if (handlers.size === 0) {
__classPrivateFieldGet(this, _map).delete(event);
}
}
emit(event, value) {
if (__classPrivateFieldGet(this, _map).has(event)) {
const set = __classPrivateFieldGet(this, _map).get(event);
set.forEach(cb => cb(value));
}
if (!__classPrivateFieldGet(this, _map).has(event))
return;
const set = __classPrivateFieldGet(this, _map).get(event);
set.forEach(cb => cb(value));
}
}
exports.Emitter = Emitter;
_map = new WeakMap();
//# sourceMappingURL=emitter.js.map

@@ -1,13 +0,13 @@

export declare class HashSet<T> implements Iterable<T> {
export declare class HashSet<V, K = unknown> implements Iterable<V> {
#private;
private hash;
constructor(hash: (value: T) => string);
add(value: T): this;
delete(value: T): boolean;
has(value: T): boolean;
get [Symbol.toStringTag](): string;
get size(): number;
[Symbol.iterator](): IterableIterator<V>;
constructor(hash: (value: V) => K);
add(value: V): this;
delete(value: V): boolean;
has(value: V): boolean;
clear(): void;
values(): IterableIterator<T>;
get size(): number;
get [Symbol.toStringTag](): string;
[Symbol.iterator](): IterableIterator<T>;
values(): Iterable<V>;
}

@@ -16,2 +16,11 @@ "use strict";

}
get [(_map = new WeakMap(), Symbol.toStringTag)]() {
return this.constructor.name;
}
get size() {
return __classPrivateFieldGet(this, _map).size;
}
[Symbol.iterator]() {
return __classPrivateFieldGet(this, _map).values();
}
add(value) {

@@ -33,13 +42,4 @@ __classPrivateFieldGet(this, _map).set(this.hash(value), value);

}
get size() {
return __classPrivateFieldGet(this, _map).size;
}
get [(_map = new WeakMap(), Symbol.toStringTag)]() {
return this.constructor.name;
}
[Symbol.iterator]() {
return __classPrivateFieldGet(this, _map).values();
}
}
exports.HashSet = HashSet;
//# sourceMappingURL=hash-set.js.map

@@ -5,2 +5,3 @@ export * from './cons';

export * from './queue';
export * from './lru';
export * from './lru-map';
export * from './trie-map';

@@ -17,3 +17,4 @@ "use strict";

__exportStar(require("./queue"), exports);
__exportStar(require("./lru"), exports);
__exportStar(require("./lru-map"), exports);
__exportStar(require("./trie-map"), exports);
//# sourceMappingURL=index.js.map

@@ -1,12 +0,9 @@

import { CustomError } from '@blackglory/errors';
export declare class Queue<T> {
#private;
get [Symbol.toStringTag](): string;
get size(): number;
empty(): void;
enqueue(...items: T[]): void;
dequeue(): T;
get size(): number;
dequeue(): T | undefined;
remove(item: T): void;
}
export declare class EmptyQueueError extends CustomError {
constructor();
}

@@ -10,4 +10,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.EmptyQueueError = exports.Queue = void 0;
const errors_1 = require("@blackglory/errors");
exports.Queue = void 0;
class Queue {

@@ -17,2 +16,8 @@ constructor() {

}
get [(_items = new WeakMap(), Symbol.toStringTag)]() {
return this.constructor.name;
}
get size() {
return __classPrivateFieldGet(this, _items).length;
}
empty() {

@@ -25,9 +30,4 @@ __classPrivateFieldGet(this, _items).length = 0;

dequeue() {
if (this.size === 0)
throw new EmptyQueueError();
return __classPrivateFieldGet(this, _items).shift();
}
get size() {
return __classPrivateFieldGet(this, _items).length;
}
remove(item) {

@@ -41,9 +41,2 @@ let index;

exports.Queue = Queue;
_items = new WeakMap();
class EmptyQueueError extends errors_1.CustomError {
constructor() {
super('Queue is empty.');
}
}
exports.EmptyQueueError = EmptyQueueError;
//# sourceMappingURL=queue.js.map
export declare type Cons<T> = [T, Cons<T>] | [T, null];
export declare function convertConsToArray<T>([value, next]: Cons<T>): T[];
export declare function convertArrayToCons<T>([value, ...next]: T[]): Cons<T>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertConsToArray = void 0;
exports.convertArrayToCons = exports.convertConsToArray = void 0;
function convertConsToArray([value, next]) {

@@ -10,2 +10,6 @@ if (next === null)

exports.convertConsToArray = convertConsToArray;
function convertArrayToCons([value, ...next]) {
return [value, next.length ? convertArrayToCons(next) : null];
}
exports.convertArrayToCons = convertArrayToCons;
//# sourceMappingURL=cons.js.map
declare type Handler<T> = (value: T) => void;
export declare class Emitter<T> {
#private;
get [Symbol.toStringTag](): string;
on(event: string, handler: Handler<T>): void;

@@ -5,0 +6,0 @@ off(event: string, handler: Handler<T>): void;

@@ -15,5 +15,9 @@ "use strict";

}
get [(_map = new WeakMap(), Symbol.toStringTag)]() {
return this.constructor.name;
}
on(event, handler) {
if (!__classPrivateFieldGet(this, _map).has(event))
if (!__classPrivateFieldGet(this, _map).has(event)) {
__classPrivateFieldGet(this, _map).set(event, new Set());
}
const set = __classPrivateFieldGet(this, _map).get(event);

@@ -23,18 +27,18 @@ set.add(handler);

off(event, handler) {
if (__classPrivateFieldGet(this, _map).has(event)) {
const set = __classPrivateFieldGet(this, _map).get(event);
set.delete(handler);
if (set.size === 0)
__classPrivateFieldGet(this, _map).delete(event);
if (!__classPrivateFieldGet(this, _map).has(event))
return;
const handlers = __classPrivateFieldGet(this, _map).get(event);
handlers.delete(handler);
if (handlers.size === 0) {
__classPrivateFieldGet(this, _map).delete(event);
}
}
emit(event, value) {
if (__classPrivateFieldGet(this, _map).has(event)) {
const set = __classPrivateFieldGet(this, _map).get(event);
set.forEach(cb => cb(value));
}
if (!__classPrivateFieldGet(this, _map).has(event))
return;
const set = __classPrivateFieldGet(this, _map).get(event);
set.forEach(cb => cb(value));
}
}
exports.Emitter = Emitter;
_map = new WeakMap();
//# sourceMappingURL=emitter.js.map

@@ -1,13 +0,13 @@

export declare class HashSet<T> implements Iterable<T> {
export declare class HashSet<V, K = unknown> implements Iterable<V> {
#private;
private hash;
constructor(hash: (value: T) => string);
add(value: T): this;
delete(value: T): boolean;
has(value: T): boolean;
get [Symbol.toStringTag](): string;
get size(): number;
[Symbol.iterator](): IterableIterator<V>;
constructor(hash: (value: V) => K);
add(value: V): this;
delete(value: V): boolean;
has(value: V): boolean;
clear(): void;
values(): IterableIterator<T>;
get size(): number;
get [Symbol.toStringTag](): string;
[Symbol.iterator](): IterableIterator<T>;
values(): Iterable<V>;
}

@@ -16,2 +16,11 @@ "use strict";

}
get [(_map = new WeakMap(), Symbol.toStringTag)]() {
return this.constructor.name;
}
get size() {
return __classPrivateFieldGet(this, _map).size;
}
[Symbol.iterator]() {
return __classPrivateFieldGet(this, _map).values();
}
add(value) {

@@ -33,13 +42,4 @@ __classPrivateFieldGet(this, _map).set(this.hash(value), value);

}
get size() {
return __classPrivateFieldGet(this, _map).size;
}
get [(_map = new WeakMap(), Symbol.toStringTag)]() {
return this.constructor.name;
}
[Symbol.iterator]() {
return __classPrivateFieldGet(this, _map).values();
}
}
exports.HashSet = HashSet;
//# sourceMappingURL=hash-set.js.map

@@ -5,2 +5,3 @@ export * from './cons';

export * from './queue';
export * from './lru';
export * from './lru-map';
export * from './trie-map';

@@ -17,3 +17,4 @@ "use strict";

__exportStar(require("./queue"), exports);
__exportStar(require("./lru"), exports);
__exportStar(require("./lru-map"), exports);
__exportStar(require("./trie-map"), exports);
//# sourceMappingURL=index.js.map

@@ -1,12 +0,9 @@

import { CustomError } from '@blackglory/errors';
export declare class Queue<T> {
#private;
get [Symbol.toStringTag](): string;
get size(): number;
empty(): void;
enqueue(...items: T[]): void;
dequeue(): T;
get size(): number;
dequeue(): T | undefined;
remove(item: T): void;
}
export declare class EmptyQueueError extends CustomError {
constructor();
}

@@ -10,4 +10,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.EmptyQueueError = exports.Queue = void 0;
const errors_1 = require("@blackglory/errors");
exports.Queue = void 0;
class Queue {

@@ -17,2 +16,8 @@ constructor() {

}
get [(_items = new WeakMap(), Symbol.toStringTag)]() {
return this.constructor.name;
}
get size() {
return __classPrivateFieldGet(this, _items).length;
}
empty() {

@@ -25,9 +30,4 @@ __classPrivateFieldGet(this, _items).length = 0;

dequeue() {
if (this.size === 0)
throw new EmptyQueueError();
return __classPrivateFieldGet(this, _items).shift();
}
get size() {
return __classPrivateFieldGet(this, _items).length;
}
remove(item) {

@@ -41,9 +41,2 @@ let index;

exports.Queue = Queue;
_items = new WeakMap();
class EmptyQueueError extends errors_1.CustomError {
constructor() {
super('Queue is empty.');
}
}
exports.EmptyQueueError = EmptyQueueError;
//# sourceMappingURL=queue.js.map
{
"name": "@blackglory/structures",
"version": "0.1.15",
"version": "0.2.0",
"description": "",

@@ -43,5 +43,7 @@ "files": [

"devDependencies": {
"@blackglory/jest-matchers": "^0.1.17",
"@commitlint/cli": "^12.1.4",
"@commitlint/config-conventional": "^12.1.4",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.0",

@@ -56,5 +58,5 @@ "@rollup/plugin-replace": "^2.4.2",

"husky": "^4.3.8",
"iterable-operator": "^0.13.6",
"jest": "^26.6.3",
"npm-run-all": "^4.1.5",
"return-style": "^0.12.3",
"rimraf": "^3.0.2",

@@ -71,4 +73,5 @@ "rollup": "^2.48.0",

"dependencies": {
"@blackglory/errors": "^1.1.2"
"@blackglory/errors": "^1.1.2",
"hotypes": "^0.2.1"
}
}

@@ -1,4 +0,4 @@

# structures
# strctures
Common structures.
Common strctures.

@@ -8,5 +8,97 @@ ## Install

```sh
npm install --save @blackglory/structures
npm install --save @blackglory/strctures
# or
yarn add @blackglory/structures
yarn add @blackglory/strctures
```
## API
### Cons
#### convertConsToArray
```ts
function convertConsToArray<T>([value, next]: Cons<T>): T[]
```
#### convertArrayToCons
```ts
function convertArrayToCons<T>([value, ...next]: T[]): Cons<T>
```
### Emitter
```ts
type Handler<T> = (vale: T) => void
class Emitter<T> {
get [Symbol.toStringTag](): string
on(event: string, handler: Handler<T>): void
off(event: string, handler: Handler<T>): void
emit(event: string, vale: T): void
}
```
### HashSet
```ts
class HashSet<V, K = unknown> implements Iterable<V> {
get [Symbol.toStringTag](): string
get size(): number
[Symbol.iterator](): IterableIterator<V>
constructor(hash: (value: V) => K)
add(value: V): this
delete(value: V): boolean
has(value: V): boolean
clear(): void
values(): Iterable<V>
}
```
### LRUMap
```ts
class LRUMap<K, V> {
get [Symbol.toStringTag](): string
get size(): number
constructor(limit: number)
set(key: K, value: V): this
has(key: K): boolean
get(key: K): V | undefined
delete(key: K): boolean
clear(): void
}
```
### Queue
```ts
class Queue<T> {
get [Symbol.toStringTag](): string
get size(): number
empty(): void
enqueue(...items: T[]): void
dequeue(): T | undefined
remove(item: T): void
}
```
### TrieMap
```ts
class TrieMap<K extends Iterable<T>, V, T = UnpackedIterable<K>> {
get [Symbol.toStringTag](): string
set(key: K, value: V): this
has(key: K): boolean
get(key: K): V | undefined
delete(key: K): boolean
}
```

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 too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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 too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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