@blackglory/structures 0.14.11 → 0.14.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/unique-queue.d.ts +9 -0
- package/lib/unique-queue.js +30 -0
- package/lib/unique-queue.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/unique-queue.ts +34 -0
package/README.md
CHANGED
|
@@ -318,6 +318,23 @@ class Queue<T> {
|
|
|
318
318
|
empty(): void
|
|
319
319
|
enqueue(...items: T[]): void
|
|
320
320
|
dequeue(): T | undefined
|
|
321
|
+
|
|
322
|
+
// O(n)
|
|
323
|
+
remove(item: T): void
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### UniqueQueue
|
|
328
|
+
```ts
|
|
329
|
+
class UniqueQueue<T> {
|
|
330
|
+
get [Symbol.toStringTag](): string
|
|
331
|
+
get size(): number
|
|
332
|
+
|
|
333
|
+
empty(): void
|
|
334
|
+
enqueue(...items: T[]): void
|
|
335
|
+
dequeue(): T | undefined
|
|
336
|
+
|
|
337
|
+
// Better than O(n)
|
|
321
338
|
remove(item: T): void
|
|
322
339
|
}
|
|
323
340
|
```
|
package/lib/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from './big-set.js';
|
|
|
9
9
|
export * from './hash-map.js';
|
|
10
10
|
export * from './hash-set.js';
|
|
11
11
|
export * from './queue.js';
|
|
12
|
+
export * from './unique-queue.js';
|
|
12
13
|
export * from './lru-map.js';
|
|
13
14
|
export * from './expirable-map.js';
|
|
14
15
|
export * from './tlru-map.js';
|
package/lib/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from './big-set.js';
|
|
|
9
9
|
export * from './hash-map.js';
|
|
10
10
|
export * from './hash-set.js';
|
|
11
11
|
export * from './queue.js';
|
|
12
|
+
export * from './unique-queue.js';
|
|
12
13
|
export * from './lru-map.js';
|
|
13
14
|
export * from './expirable-map.js';
|
|
14
15
|
export * from './tlru-map.js';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,cAAc,iBAAiB,CAAA;AAC/B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAC5D,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isntUndefined } from 'extra-utils';
|
|
2
|
+
import { first } from 'iterable-operator';
|
|
3
|
+
export class UniqueQueue {
|
|
4
|
+
items = new Set();
|
|
5
|
+
get [Symbol.toStringTag]() {
|
|
6
|
+
return this.constructor.name;
|
|
7
|
+
}
|
|
8
|
+
get size() {
|
|
9
|
+
return this.items.size;
|
|
10
|
+
}
|
|
11
|
+
empty() {
|
|
12
|
+
this.items.clear();
|
|
13
|
+
}
|
|
14
|
+
enqueue(...items) {
|
|
15
|
+
for (const item of items) {
|
|
16
|
+
if (!this.items.has(item))
|
|
17
|
+
this.items.add(item);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
dequeue() {
|
|
21
|
+
const value = first(this.items);
|
|
22
|
+
if (isntUndefined(value))
|
|
23
|
+
this.items.delete(value);
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
remove(item) {
|
|
27
|
+
this.items.delete(item);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=unique-queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unique-queue.js","sourceRoot":"","sources":["../src/unique-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAEzC,MAAM,OAAO,WAAW;IACd,KAAK,GAAW,IAAI,GAAG,EAAE,CAAA;IAEjC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;QACtB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAA;IAC9B,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAA;IACxB,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;IAED,OAAO,CAAC,GAAG,KAAU;QACnB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC;gBAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;IAED,OAAO;QACL,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QAC/B,IAAI,aAAa,CAAC,KAAK,CAAC;YAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAClD,OAAO,KAAK,CAAA;IACd,CAAC;IAED,MAAM,CAAC,IAAO;QACZ,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;CACF"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isntUndefined } from 'extra-utils'
|
|
2
|
+
import { first } from 'iterable-operator'
|
|
3
|
+
|
|
4
|
+
export class UniqueQueue<T> {
|
|
5
|
+
private items: Set<T> = new Set()
|
|
6
|
+
|
|
7
|
+
get [Symbol.toStringTag](): string {
|
|
8
|
+
return this.constructor.name
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get size(): number {
|
|
12
|
+
return this.items.size
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
empty(): void {
|
|
16
|
+
this.items.clear()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
enqueue(...items: T[]): void {
|
|
20
|
+
for (const item of items) {
|
|
21
|
+
if (!this.items.has(item)) this.items.add(item)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
dequeue(): T | undefined {
|
|
26
|
+
const value = first(this.items)
|
|
27
|
+
if (isntUndefined(value)) this.items.delete(value)
|
|
28
|
+
return value
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
remove(item: T): void {
|
|
32
|
+
this.items.delete(item)
|
|
33
|
+
}
|
|
34
|
+
}
|