@deepseek-ai/dsh-deque 0.2.2-alpha.3 → 0.2.2-rc.2

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;GAIG;AACH,qBAAa,KAAK,CAAC,CAAC;IAClB,OAAO,CAAC,MAAM,CAAyC;IACvD,OAAO,CAAC,IAAI,CAAI;IAChB,OAAO,CAAC,KAAK,CAAI;IAEjB,6CAA6C;IAC7C,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAOxB;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAOzB;;;;;OAKG;IACH,QAAQ,IAAI,CAAC,GAAG,SAAS;IAWzB,gEAAgE;IAChE,KAAK,IAAI,IAAI;IAMb,OAAO,CAAC,cAAc;IAKtB,OAAO,CAAC,OAAO;IAUf,OAAO,CAAC,MAAM;CAWf"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,YAAY,GAAG,EAAE,CAAA;AAEvB;;;;GAIG;AACH,MAAM,OAAO,KAAK;IACR,MAAM,GAAG,IAAI,KAAK,CAAgB,YAAY,CAAC,CAAA;IAC/C,IAAI,GAAG,CAAC,CAAA;IACR,KAAK,GAAG,CAAC,CAAA;IAEjB,6CAA6C;IAC7C,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAA;IACnB,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,KAAQ;QACf,IAAI,CAAC,cAAc,EAAE,CAAA;QACrB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAA;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CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/dsh-deque",
3
3
  "description": "Zero-dependency circular deque with amortized constant-time end operations and bounded vacant storage",
4
- "version": "0.2.2-alpha.3",
4
+ "version": "0.2.2-rc.2",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -23,13 +23,16 @@
23
23
  },
24
24
  "files": [
25
25
  "lib/index.js",
26
- "lib/types/**/*.d.ts"
26
+ "lib/types/**/*.d.ts",
27
+ "lib/types/**/*.d.ts.map",
28
+ "lib/**/*.js.map",
29
+ "src"
27
30
  ],
28
31
  "license": "MIT",
29
32
  "peerDependencies": {
30
- "@deepseek-ai/cordis": "~4.0.6-alpha.2"
33
+ "@deepseek-ai/cordis": "~4.1.0"
31
34
  },
32
35
  "devDependencies": {
33
- "@deepseek-ai/cordis": "~4.0.6-alpha.2"
36
+ "@deepseek-ai/cordis": "~4.1.0"
34
37
  }
35
38
  }
package/src/index.ts ADDED
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Zero-dependency circular deque for queues that retain entries across asynchronous work.
3
+ * @module @deepseek-ai/dsh-deque
4
+ */
5
+
6
+ const MIN_CAPACITY = 16
7
+
8
+ /**
9
+ * A circular deque with amortized constant-time insertion and removal.
10
+ * Removed entries are cleared immediately, and sparse storage shrinks after
11
+ * the live entry count reaches one quarter of its capacity.
12
+ */
13
+ export class Deque<T> {
14
+ private buffer = new Array<T | undefined>(MIN_CAPACITY)
15
+ private head = 0
16
+ private count = 0
17
+
18
+ /** Number of entries available to remove. */
19
+ get size(): number {
20
+ return this.count
21
+ }
22
+
23
+ /**
24
+ * Append one entry after the current tail.
25
+ * @param value - entry to append.
26
+ */
27
+ pushBack(value: T): void {
28
+ this.ensureCapacity()
29
+ const tail = this.head + this.count
30
+ this.buffer[tail < this.buffer.length ? tail : tail - this.buffer.length] = value
31
+ this.count += 1
32
+ }
33
+
34
+ /**
35
+ * Insert one entry before the current head.
36
+ * @param value - entry to prepend.
37
+ */
38
+ pushFront(value: T): void {
39
+ this.ensureCapacity()
40
+ this.head = this.head === 0 ? this.buffer.length - 1 : this.head - 1
41
+ this.buffer[this.head] = value
42
+ this.count += 1
43
+ }
44
+
45
+ /**
46
+ * Remove the current head entry and clear its retained reference.
47
+ * Callers whose element type includes `undefined` use {@link size} to
48
+ * distinguish an empty deque from an `undefined` entry.
49
+ * @returns the removed entry, or `undefined` when the deque is empty.
50
+ */
51
+ popFront(): T | undefined {
52
+ if (this.count === 0) return undefined
53
+ const value = this.buffer[this.head] as T
54
+ this.buffer[this.head] = undefined
55
+ this.head += 1
56
+ if (this.head === this.buffer.length) this.head = 0
57
+ this.count -= 1
58
+ this.compact()
59
+ return value
60
+ }
61
+
62
+ /** Drop every entry and release the current backing storage. */
63
+ clear(): void {
64
+ this.buffer = new Array<T | undefined>(MIN_CAPACITY)
65
+ this.head = 0
66
+ this.count = 0
67
+ }
68
+
69
+ private ensureCapacity(): void {
70
+ if (this.count < this.buffer.length) return
71
+ this.resize(this.buffer.length * 2)
72
+ }
73
+
74
+ private compact(): void {
75
+ if (this.count === 0) {
76
+ this.head = 0
77
+ return
78
+ }
79
+ if (this.buffer.length > MIN_CAPACITY && this.count <= this.buffer.length / 4) {
80
+ this.resize(Math.max(MIN_CAPACITY, this.buffer.length / 2))
81
+ }
82
+ }
83
+
84
+ private resize(capacity: number): void {
85
+ const next = new Array<T | undefined>(capacity)
86
+ let source = this.head
87
+ for (let index = 0; index < this.count; index += 1) {
88
+ next[index] = this.buffer[source]
89
+ source += 1
90
+ if (source === this.buffer.length) source = 0
91
+ }
92
+ this.buffer = next
93
+ this.head = 0
94
+ }
95
+ }