@absoluteui/helpers 0.0.0-stage → 0.13.1

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.
Files changed (221) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +5 -0
  3. package/README.md +47 -2
  4. package/SECURITY.md +102 -0
  5. package/dist/array/compare.d.ts +8 -0
  6. package/dist/array/compare.js +2 -0
  7. package/dist/array/index.d.ts +328 -0
  8. package/dist/array/index.js +2 -0
  9. package/dist/array/tree.d.ts +48 -0
  10. package/dist/array/tree.js +2 -0
  11. package/dist/async/batch.d.ts +103 -0
  12. package/dist/async/batch.js +2 -0
  13. package/dist/async/concurrency.d.ts +92 -0
  14. package/dist/async/concurrency.js +2 -0
  15. package/dist/async/control.d.ts +77 -0
  16. package/dist/async/control.js +2 -0
  17. package/dist/async/index.d.ts +8 -0
  18. package/dist/async/index.js +2 -0
  19. package/dist/async/signal.d.ts +95 -0
  20. package/dist/async/signal.js +2 -0
  21. package/dist/boolean/index.d.ts +83 -0
  22. package/dist/boolean/index.js +2 -0
  23. package/dist/business-calendar/days.d.ts +397 -0
  24. package/dist/business-calendar/days.js +2 -0
  25. package/dist/business-calendar/describe.d.ts +45 -0
  26. package/dist/business-calendar/describe.js +2 -0
  27. package/dist/business-calendar/engine.d.ts +305 -0
  28. package/dist/business-calendar/engine.js +2 -0
  29. package/dist/business-calendar/hours.d.ts +96 -0
  30. package/dist/business-calendar/hours.js +2 -0
  31. package/dist/business-calendar/index.d.ts +29 -0
  32. package/dist/business-calendar/index.js +2 -0
  33. package/dist/business-calendar/internal.d.ts +44 -0
  34. package/dist/business-calendar/internal.js +2 -0
  35. package/dist/business-calendar/rules.d.ts +260 -0
  36. package/dist/business-calendar/rules.js +2 -0
  37. package/dist/color/index.d.ts +200 -0
  38. package/dist/color/index.js +2 -0
  39. package/dist/color/named.d.ts +4 -0
  40. package/dist/color/named.js +2 -0
  41. package/dist/compare/index.d.ts +186 -0
  42. package/dist/compare/index.js +2 -0
  43. package/dist/convert/index.d.ts +152 -0
  44. package/dist/convert/index.js +2 -0
  45. package/dist/csv/index.d.ts +6 -0
  46. package/dist/csv/index.js +2 -0
  47. package/dist/csv/parse.d.ts +85 -0
  48. package/dist/csv/parse.js +12 -0
  49. package/dist/csv/stringify.d.ts +48 -0
  50. package/dist/csv/stringify.js +5 -0
  51. package/dist/date/calendar.d.ts +339 -0
  52. package/dist/date/calendar.js +2 -0
  53. package/dist/date/format.d.ts +66 -0
  54. package/dist/date/format.js +2 -0
  55. package/dist/date/index.d.ts +26 -0
  56. package/dist/date/index.js +2 -0
  57. package/dist/date/intervals.d.ts +110 -0
  58. package/dist/date/intervals.js +2 -0
  59. package/dist/date/intl-cache.d.ts +10 -0
  60. package/dist/date/intl-cache.js +2 -0
  61. package/dist/date/locale.d.ts +58 -0
  62. package/dist/date/locale.js +2 -0
  63. package/dist/date/plain-date.d.ts +105 -0
  64. package/dist/date/plain-date.js +2 -0
  65. package/dist/date/plain-time.d.ts +121 -0
  66. package/dist/date/plain-time.js +2 -0
  67. package/dist/date/zone.d.ts +121 -0
  68. package/dist/date/zone.js +2 -0
  69. package/dist/decimal/index.d.ts +149 -0
  70. package/dist/decimal/index.js +2 -0
  71. package/dist/ds/avl.d.ts +50 -0
  72. package/dist/ds/avl.js +2 -0
  73. package/dist/ds/bitset.d.ts +46 -0
  74. package/dist/ds/bitset.js +2 -0
  75. package/dist/ds/bloom.d.ts +41 -0
  76. package/dist/ds/bloom.js +2 -0
  77. package/dist/ds/caches.d.ts +141 -0
  78. package/dist/ds/caches.js +2 -0
  79. package/dist/ds/disjoint-set.d.ts +38 -0
  80. package/dist/ds/disjoint-set.js +2 -0
  81. package/dist/ds/emitter.d.ts +53 -0
  82. package/dist/ds/emitter.js +2 -0
  83. package/dist/ds/graph.d.ts +84 -0
  84. package/dist/ds/graph.js +2 -0
  85. package/dist/ds/heap.d.ts +49 -0
  86. package/dist/ds/heap.js +2 -0
  87. package/dist/ds/index.d.ts +20 -0
  88. package/dist/ds/index.js +2 -0
  89. package/dist/ds/internal.d.ts +19 -0
  90. package/dist/ds/internal.js +2 -0
  91. package/dist/ds/interval-tree.d.ts +49 -0
  92. package/dist/ds/interval-tree.js +2 -0
  93. package/dist/ds/linked-list.d.ts +54 -0
  94. package/dist/ds/linked-list.js +2 -0
  95. package/dist/ds/maps.d.ts +89 -0
  96. package/dist/ds/maps.js +2 -0
  97. package/dist/ds/ring.d.ts +99 -0
  98. package/dist/ds/ring.js +2 -0
  99. package/dist/ds/sorted.d.ts +104 -0
  100. package/dist/ds/sorted.js +2 -0
  101. package/dist/ds/stack.d.ts +28 -0
  102. package/dist/ds/stack.js +2 -0
  103. package/dist/ds/trie.d.ts +84 -0
  104. package/dist/ds/trie.js +2 -0
  105. package/dist/duration/index.d.ts +146 -0
  106. package/dist/duration/index.js +2 -0
  107. package/dist/encoding/index.d.ts +144 -0
  108. package/dist/encoding/index.js +2 -0
  109. package/dist/error/index.d.ts +316 -0
  110. package/dist/error/index.js +2 -0
  111. package/dist/fn/index.d.ts +129 -0
  112. package/dist/fn/index.js +2 -0
  113. package/dist/fn/memo.d.ts +46 -0
  114. package/dist/fn/memo.js +2 -0
  115. package/dist/fn/timing.d.ts +64 -0
  116. package/dist/fn/timing.js +2 -0
  117. package/dist/http/headers.d.ts +160 -0
  118. package/dist/http/headers.js +2 -0
  119. package/dist/http/index.d.ts +10 -0
  120. package/dist/http/index.js +2 -0
  121. package/dist/http/problem.d.ts +37 -0
  122. package/dist/http/problem.js +2 -0
  123. package/dist/http/response.d.ts +43 -0
  124. package/dist/http/response.js +2 -0
  125. package/dist/http/status.d.ts +169 -0
  126. package/dist/http/status.js +2 -0
  127. package/dist/index.d.ts +34 -0
  128. package/dist/index.js +2 -0
  129. package/dist/internal/keys.d.ts +6 -0
  130. package/dist/internal/keys.js +2 -0
  131. package/dist/is/index.d.ts +219 -0
  132. package/dist/is/index.js +2 -0
  133. package/dist/json/index.d.ts +9 -0
  134. package/dist/json/index.js +2 -0
  135. package/dist/json/internal.d.ts +12 -0
  136. package/dist/json/internal.js +2 -0
  137. package/dist/json/ndjson.d.ts +28 -0
  138. package/dist/json/ndjson.js +4 -0
  139. package/dist/json/parse.d.ts +45 -0
  140. package/dist/json/parse.js +2 -0
  141. package/dist/json/patch.d.ts +62 -0
  142. package/dist/json/patch.js +2 -0
  143. package/dist/json/pointer.d.ts +43 -0
  144. package/dist/json/pointer.js +2 -0
  145. package/dist/json/stringify.d.ts +42 -0
  146. package/dist/json/stringify.js +2 -0
  147. package/dist/linq/enumerable.d.ts +208 -0
  148. package/dist/linq/enumerable.js +2 -0
  149. package/dist/linq/index.d.ts +6 -0
  150. package/dist/linq/index.js +2 -0
  151. package/dist/linq/operators.d.ts +503 -0
  152. package/dist/linq/operators.js +2 -0
  153. package/dist/number/core.d.ts +164 -0
  154. package/dist/number/core.js +2 -0
  155. package/dist/number/format.d.ts +80 -0
  156. package/dist/number/format.js +2 -0
  157. package/dist/number/index.d.ts +12 -0
  158. package/dist/number/index.js +2 -0
  159. package/dist/number/internal.d.ts +18 -0
  160. package/dist/number/internal.js +2 -0
  161. package/dist/number/parse.d.ts +45 -0
  162. package/dist/number/parse.js +2 -0
  163. package/dist/number/words.d.ts +19 -0
  164. package/dist/number/words.js +2 -0
  165. package/dist/object/basic.d.ts +130 -0
  166. package/dist/object/basic.js +2 -0
  167. package/dist/object/deep.d.ts +90 -0
  168. package/dist/object/deep.js +2 -0
  169. package/dist/object/diff.d.ts +57 -0
  170. package/dist/object/diff.js +2 -0
  171. package/dist/object/index.d.ts +8 -0
  172. package/dist/object/index.js +2 -0
  173. package/dist/object/internal.d.ts +21 -0
  174. package/dist/object/internal.js +2 -0
  175. package/dist/object/path.d.ts +17 -0
  176. package/dist/object/path.js +2 -0
  177. package/dist/random/core.d.ts +14 -0
  178. package/dist/random/core.js +2 -0
  179. package/dist/random/index.d.ts +167 -0
  180. package/dist/random/index.js +2 -0
  181. package/dist/random/seeded.d.ts +27 -0
  182. package/dist/random/seeded.js +2 -0
  183. package/dist/sanitize/index.d.ts +8 -0
  184. package/dist/sanitize/index.js +2 -0
  185. package/dist/sanitize/pii.d.ts +48 -0
  186. package/dist/sanitize/pii.js +2 -0
  187. package/dist/sanitize/records.d.ts +100 -0
  188. package/dist/sanitize/records.js +2 -0
  189. package/dist/sanitize/text.d.ts +101 -0
  190. package/dist/sanitize/text.js +2 -0
  191. package/dist/set/index.d.ts +162 -0
  192. package/dist/set/index.js +2 -0
  193. package/dist/stats/index.d.ts +190 -0
  194. package/dist/stats/index.js +2 -0
  195. package/dist/string/index.d.ts +494 -0
  196. package/dist/string/index.js +8 -0
  197. package/dist/string/internal.d.ts +33 -0
  198. package/dist/string/internal.js +2 -0
  199. package/dist/string/words.d.ts +14 -0
  200. package/dist/string/words.js +2 -0
  201. package/dist/timezone/index.d.ts +76 -0
  202. package/dist/timezone/index.js +2 -0
  203. package/dist/url/index.d.ts +178 -0
  204. package/dist/url/index.js +2 -0
  205. package/dist/validate/builders.d.ts +6 -0
  206. package/dist/validate/builders.js +2 -0
  207. package/dist/validate/formats.d.ts +237 -0
  208. package/dist/validate/formats.js +2 -0
  209. package/dist/validate/index.d.ts +13 -0
  210. package/dist/validate/index.js +2 -0
  211. package/dist/validate/schema.d.ts +220 -0
  212. package/dist/validate/schema.js +2 -0
  213. package/dist/zip/index.d.ts +8 -0
  214. package/dist/zip/index.js +2 -0
  215. package/dist/zip/internal.d.ts +69 -0
  216. package/dist/zip/internal.js +2 -0
  217. package/dist/zip/reader.d.ts +56 -0
  218. package/dist/zip/reader.js +2 -0
  219. package/dist/zip/writer.d.ts +65 -0
  220. package/dist/zip/writer.js +2 -0
  221. package/package.json +150 -4
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Internal AVL tree used by `SortedMap`, `SortedSet`, and `IntervalTree`.
3
+ * Height is at most ~1.44|log2(n), so the recursive insert/delete depth stays tiny (< 64 for any
4
+ * array-sized input); traversals are iterative.
5
+ */
6
+ import { type Comparer } from './internal.js';
7
+ export declare class AvlNode<K, V> {
8
+ key: K;
9
+ value: V;
10
+ left: AvlNode<K, V> | undefined;
11
+ right: AvlNode<K, V> | undefined;
12
+ height: number;
13
+ /** Augmented value maintained by the tree's `augment` hook (IntervalTree: max end). */
14
+ aug: number;
15
+ constructor(key: K, value: V);
16
+ }
17
+ export declare class AvlTree<K, V> {
18
+ #private;
19
+ root: AvlNode<K, V> | undefined;
20
+ size: number;
21
+ /** Incremented on structural change; iterators use it to detect concurrent modification. */
22
+ version: number;
23
+ readonly cmp: Comparer<K>;
24
+ constructor(cmp: Comparer<K>, augment?: (node: AvlNode<K, V>) => void);
25
+ find(key: K): AvlNode<K, V> | undefined;
26
+ /** Inserts or replaces; returns true when a new node was added. */
27
+ insert(key: K, value: V): boolean;
28
+ /** Removes `key`; returns the removed node. */
29
+ delete(key: K): AvlNode<K, V> | undefined;
30
+ clear(): void;
31
+ min(): AvlNode<K, V> | undefined;
32
+ max(): AvlNode<K, V> | undefined;
33
+ /** Greatest node with key < `key` (or <= when `inclusive`). */
34
+ below(key: K, inclusive: boolean): AvlNode<K, V> | undefined;
35
+ /** Least node with key > `key` (or >= when `inclusive`). */
36
+ above(key: K, inclusive: boolean): AvlNode<K, V> | undefined;
37
+ /**
38
+ * In-order nodes starting at the first key >= `lo` (> when `loExclusive`); all nodes when `lo` is omitted.
39
+ * Iterative; O(log n) to start, O(1) amortized per step.
40
+ */
41
+ ascending(lo?: {
42
+ readonly key: K;
43
+ readonly exclusive: boolean;
44
+ }): Generator<AvlNode<K, V>>;
45
+ /** Reverse in-order nodes starting at the last key <= `hi` (< when exclusive). */
46
+ descending(hi?: {
47
+ readonly key: K;
48
+ readonly exclusive: boolean;
49
+ }): Generator<AvlNode<K, V>>;
50
+ }
package/dist/ds/avl.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{concurrentModification as d}from"./internal.js";class f{constructor(e,t){this.key=e;this.value=t}key;value;left=void 0;right=void 0;height=1;aug=0}const l=h=>h?h.height:0;class u{root=void 0;size=0;version=0;cmp;#t;#r;constructor(e,t){this.cmp=e,this.#t=t}find(e){let t=this.root;for(;t;){const i=this.cmp(e,t.key);if(i===0)return t;t=i<0?t.left:t.right}}insert(e,t){const i=this.size;return this.root=this.#o(this.root,e,t),this.size!==i&&this.version++,this.size!==i}delete(e){this.root=this.#s(this.root,e);const t=this.#r;return this.#r=void 0,t&&(this.size--,this.version++),t}clear(){this.root=void 0,this.size=0,this.version++}min(){let e=this.root;for(;e?.left;)e=e.left;return e}max(){let e=this.root;for(;e?.right;)e=e.right;return e}below(e,t){let i=this.root,o;for(;i;){const r=this.cmp(i.key,e);if(r<0||t&&r===0){if(o=i,r===0)return i;i=i.right}else i=i.left}return o}above(e,t){let i=this.root,o;for(;i;){const r=this.cmp(i.key,e);if(r>0||t&&r===0){if(o=i,r===0)return i;i=i.left}else i=i.right}return o}*ascending(e){const t=[];let i=this.root;for(;i;){if(e===void 0){t.push(i),i=i.left;continue}const r=this.cmp(i.key,e.key);r>0||r===0&&!e.exclusive?(t.push(i),i=i.left):i=i.right}const o=this.version;for(let r=t.pop();r;r=t.pop()){if(yield r,o!==this.version)throw d();for(let s=r.right;s;s=s.left)t.push(s)}}*descending(e){const t=[];let i=this.root;for(;i;){if(e===void 0){t.push(i),i=i.right;continue}const r=this.cmp(i.key,e.key);r<0||r===0&&!e.exclusive?(t.push(i),i=i.right):i=i.left}const o=this.version;for(let r=t.pop();r;r=t.pop()){if(yield r,o!==this.version)throw d();for(let s=r.left;s;s=s.right)t.push(s)}}#e(e){e.height=1+Math.max(l(e.left),l(e.right)),this.#t?.(e)}#l(e){const t=e.left;return t?(e.left=t.right,t.right=e,this.#e(e),this.#e(t),t):e}#h(e){const t=e.right;return t?(e.right=t.left,t.left=e,this.#e(e),this.#e(t),t):e}#i(e){this.#e(e);const t=l(e.left)-l(e.right);return t>1&&e.left?(l(e.left.left)<l(e.left.right)&&(e.left=this.#h(e.left)),this.#l(e)):t<-1&&e.right?(l(e.right.right)<l(e.right.left)&&(e.right=this.#l(e.right)),this.#h(e)):e}#o(e,t,i){if(!e){this.size++;const r=new f(t,i);return this.#t?.(r),r}const o=this.cmp(t,e.key);if(o<0)e.left=this.#o(e.left,t,i);else if(o>0)e.right=this.#o(e.right,t,i);else return e.value=i,this.#t?.(e),e;return this.#i(e)}#s(e,t){if(!e)return;const i=this.cmp(t,e.key);if(i<0)e.left=this.#s(e.left,t);else if(i>0)e.right=this.#s(e.right,t);else{if(this.#r=e,!e.left)return e.right;if(!e.right)return e.left;let o=e.right;for(;o.left;)o=o.left;const r=this.#d(e.right);return o.left=e.left,o.right=r,this.#i(o)}return this.#i(e)}#d(e){return e.left?(e.left=this.#d(e.left),this.#i(e)):e.right}}export{f as AvlNode,u as AvlTree};
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Growable bit set on a `Uint32Array`. `size` is the number of set bits.
3
+ * Complexity: `set`, `clear(i)`, `has`, `toggle` O(1) amortized; `count`, set algebra, iteration O(words).
4
+ * @example
5
+ * const b = new BitSet();
6
+ * b.set(3).set(64);
7
+ * b.has(3); // => true
8
+ * [...b]; // => [3, 64]
9
+ * b.union(BitSet.from([1])).toArray(); // => [1, 3, 64]
10
+ */
11
+ export declare class BitSet implements Iterable<number> {
12
+ #private;
13
+ constructor(capacity?: number);
14
+ /** Builds a bit set with the given indexes set. */
15
+ static from(indexes: Iterable<number>): BitSet;
16
+ /** Allocated bits (grows on demand). */
17
+ get capacity(): number;
18
+ /** Number of set bits. O(words). */
19
+ get size(): number;
20
+ /** Sets bit `index`. */
21
+ set(index: number): this;
22
+ /** Clears bit `index`, or every bit when called without an index. */
23
+ clear(index?: number): this;
24
+ /** True when bit `index` is set. */
25
+ has(index: number): boolean;
26
+ /** Flips bit `index`; returns its new state. */
27
+ toggle(index: number): boolean;
28
+ /** Number of set bits (popcount). O(words). */
29
+ count(): number;
30
+ /** New set with bits in either. */
31
+ union(other: BitSet): BitSet;
32
+ /** New set with bits in both. */
33
+ intersect(other: BitSet): BitSet;
34
+ /** New set with bits in this but not `other`. */
35
+ difference(other: BitSet): BitSet;
36
+ /** New set with bits in exactly one. */
37
+ xor(other: BitSet): BitSet;
38
+ /** True when both have the same set bits. */
39
+ equals(other: BitSet): boolean;
40
+ /** Independent copy. */
41
+ clone(): BitSet;
42
+ /** Set bit indexes in ascending order. */
43
+ toArray(): number[];
44
+ /** Iterates set bit indexes in ascending order. */
45
+ [Symbol.iterator](): Iterator<number>;
46
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{ValidationError as a}from"../error/index.js";const l=2**31;function m(i){let t=i-(i>>>1&1431655765);return t=(t&858993459)+(t>>>2&858993459),Math.imul(t+(t>>>4)&252645135,16843009)>>>24}function b(i){if(!Number.isInteger(i)||i<0||i>=l)throw new a("HLP_DS_INVALID_INDEX","Bit index must be a non-negative integer below 2^31.")}class u{#t;constructor(t=32){if(!Number.isInteger(t)||t<0||t>l)throw new a("HLP_DS_INVALID_CAPACITY","Capacity must be an integer between 0 and 2^31.");this.#t=new Uint32Array(Math.max(1,Math.ceil(t/32)))}static from(t){const e=new u;for(const r of t)e.set(r);return e}get capacity(){return this.#t.length*32}get size(){return this.count()}set(t){b(t),this.#r(t);const e=t>>>5;return this.#t[e]=((this.#t[e]??0)|1<<(t&31))>>>0,this}clear(t){if(t===void 0)return this.#t.fill(0),this;b(t);const e=t>>>5;return e<this.#t.length&&(this.#t[e]=((this.#t[e]??0)&~(1<<(t&31)))>>>0),this}has(t){if(!Number.isInteger(t)||t<0)return!1;const e=t>>>5;return e<this.#t.length&&((this.#t[e]??0)&1<<(t&31))!==0}toggle(t){return this.has(t)?(this.clear(t),!1):(this.set(t),!0)}count(){let t=0;for(const e of this.#t)t+=m(e);return t}union(t){return this.#e(t,(e,r)=>e|r)}intersect(t){return this.#e(t,(e,r)=>e&r)}difference(t){return this.#e(t,(e,r)=>e&~r)}xor(t){return this.#e(t,(e,r)=>e^r)}equals(t){const e=this.#t,r=t.#t,n=Math.max(e.length,r.length);for(let s=0;s<n;s++)if((e[s]??0)!==(r[s]??0))return!1;return!0}clone(){const t=new u(0);return t.#t=this.#t.slice(),t}toArray(){return[...this]}*[Symbol.iterator](){const t=this.#t;for(let e=0;e<t.length;e++){let r=t[e]??0;for(;r!==0;){const n=r&-r;yield e*32+(31-Math.clz32(n)),r=(r^n)>>>0}}}#r(t){const e=(t>>>5)+1;if(e<=this.#t.length)return;const r=new Uint32Array(Math.min(Math.max(e,this.#t.length*2),l/32));r.set(this.#t),this.#t=r}#e(t,e){const r=this.#t,n=t.#t,s=new u(0),h=new Uint32Array(Math.max(r.length,n.length));for(let o=0;o<h.length;o++)h[o]=e(r[o]??0,n[o]??0)>>>0;return s.#t=h,s}}export{u as BitSet};
@@ -0,0 +1,41 @@
1
+ export interface BloomFilterOptions<T> {
2
+ /** Expected number of distinct items (sizes the filter). */
3
+ readonly expectedItems: number;
4
+ /** Target false-positive rate in (0, 1). Default 0.01. */
5
+ readonly falsePositiveRate?: number;
6
+ /**
7
+ * Converts an item to hashable input. Default: strings as is; numbers, bigints, and booleans via `String`;
8
+ * `Uint8Array` as bytes. Other types throw `HLP_DS_BLOOM_UNSUPPORTED` without a custom `key`.
9
+ */
10
+ readonly key?: (item: T) => string | Uint8Array;
11
+ }
12
+ /**
13
+ * Probabilistic set membership: `has` may return false positives at about the configured rate, never
14
+ * false negatives. Sized from expected items and target rate; hashing is FNV-1a and MurmurHash3
15
+ * combined by double hashing (not cryptographic; do not use against adversarial inputs for security decisions).
16
+ * Complexity: `add`, `has` O(k) with k hash functions; memory m bits.
17
+ * Not iterable: a Bloom filter cannot list its items.
18
+ * @example
19
+ * const seen = new BloomFilter<string>({ expectedItems: 10_000, falsePositiveRate: 0.001 });
20
+ * seen.add('alice@example.com');
21
+ * seen.has('alice@example.com'); // => true
22
+ * seen.has('bob@example.com'); // => false // almost certainly
23
+ */
24
+ export declare class BloomFilter<T = string> {
25
+ #private;
26
+ /** Number of bits (m). */
27
+ readonly bits: number;
28
+ /** Number of hash functions (k). */
29
+ readonly hashCount: number;
30
+ constructor(options: BloomFilterOptions<T>);
31
+ /** Number of `add` calls (including repeats). */
32
+ get size(): number;
33
+ /** Adds `item`. O(k). */
34
+ add(item: T): this;
35
+ /** False when `item` was definitely never added; true when it probably was. O(k). */
36
+ has(item: T): boolean;
37
+ /** Estimated current false-positive rate from the fill ratio. */
38
+ estimatedFalsePositiveRate(): number;
39
+ /** Resets every bit. */
40
+ clear(): void;
41
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{LimitError as c,ValidationError as l}from"../error/index.js";const f=2**31;let u;function m(e){let i=2166136261;for(const t of e)i=Math.imul(i^t,16777619);return i>>>0}function d(e,i){let t=i>>>0;const n=e.length,o=n&-4;for(let a=0;a<o;a+=4){let s=(e[a]??0)|(e[a+1]??0)<<8|(e[a+2]??0)<<16|(e[a+3]??0)<<24;s=Math.imul(s,3432918353),s=s<<15|s>>>17,s=Math.imul(s,461845907),t^=s,t=t<<13|t>>>19,t=Math.imul(t,5)+3864292196|0}let r=0;const h=n&3;return h===3&&(r^=(e[o+2]??0)<<16),h>=2&&(r^=(e[o+1]??0)<<8),h>=1&&(r^=e[o]??0,r=Math.imul(r,3432918353),r=r<<15|r>>>17,r=Math.imul(r,461845907),t^=r),t^=n,t^=t>>>16,t=Math.imul(t,2246822507),t^=t>>>13,t=Math.imul(t,3266489909),t^=t>>>16,t>>>0}function b(e){if(typeof e=="string")return e;if(typeof e=="number"||typeof e=="bigint"||typeof e=="boolean")return String(e);if(e instanceof Uint8Array)return e;throw new l("HLP_DS_BLOOM_UNSUPPORTED","Provide a key function for this item type.")}class x{bits;hashCount;#t;#i;#e=0;constructor(i){const t=i.expectedItems,n=i.falsePositiveRate??.01;if(!Number.isSafeInteger(t)||t<1)throw new l("HLP_DS_BLOOM_INVALID","expectedItems must be a positive integer.");if(!(n>0&&n<1))throw new l("HLP_DS_BLOOM_INVALID","falsePositiveRate must be between 0 and 1.");const o=Math.ceil(-t*Math.log(n)/Math.LN2**2);if(o>f)throw new c("HLP_DS_BLOOM_TOO_LARGE","The requested Bloom filter exceeds the size limit.");this.bits=Math.max(32,o),this.hashCount=Math.max(1,Math.round(this.bits/t*Math.LN2)),this.#t=new Uint32Array(Math.ceil(this.bits/32)),this.#i=i.key??b}get size(){return this.#e}add(i){const[t,n]=this.#n(i);for(let o=0;o<this.hashCount;o++){const r=(t+o*n)%this.bits,h=r>>>5;this.#t[h]=((this.#t[h]??0)|1<<(r&31))>>>0}return this.#e++,this}has(i){const[t,n]=this.#n(i);for(let o=0;o<this.hashCount;o++){const r=(t+o*n)%this.bits;if(((this.#t[r>>>5]??0)&1<<(r&31))===0)return!1}return!0}estimatedFalsePositiveRate(){let i=0;for(const t of this.#t){let n=t;for(;n!==0;)n&=n-1,i++}return(i/this.bits)**this.hashCount}clear(){this.#t.fill(0),this.#e=0}#n(i){const t=this.#i(i);u??=new TextEncoder;const n=typeof t=="string"?u.encode(t):t;return[m(n),(d(n,2538058380)|1)>>>0]}}export{x as BloomFilter};
@@ -0,0 +1,141 @@
1
+ /** Why a cache dropped an entry on its own. */
2
+ export type EvictionReason = 'capacity' | 'expired';
3
+ export interface LRUCacheOptions<K, V> {
4
+ /** Maximum entries. Default 1000. */
5
+ readonly maxSize?: number;
6
+ /** Default time to live per entry in ms. Expiry is lazy (checked on access or `prune`). */
7
+ readonly ttlMs?: number;
8
+ /** Called when an entry is evicted for capacity or found expired. Not called on `delete`/`clear`. */
9
+ readonly onEvict?: (key: K, value: V, reason: EvictionReason) => void;
10
+ /** Clock in ms, injectable for tests. Default `Date.now`. */
11
+ readonly now?: () => number;
12
+ }
13
+ /**
14
+ * Least-recently-used cache on an insertion-ordered `Map`.
15
+ * Complexity: `get`, `set`, `has`, `peek`, `delete` O(1); `prune` and iteration O(n).
16
+ * Iteration runs least to most recently used and skips expired entries.
17
+ * @example
18
+ * const c = new LRUCache<string, number>({ maxSize: 2 });
19
+ * c.set('a', 1).set('b', 2);
20
+ * c.get('a');
21
+ * c.set('c', 3); // evicts 'b'
22
+ */
23
+ export declare class LRUCache<K, V> implements Iterable<[K, V]> {
24
+ #private;
25
+ readonly maxSize: number;
26
+ constructor(options?: LRUCacheOptions<K, V>);
27
+ /** Stored entries, possibly including expired ones not yet pruned. O(1). */
28
+ get size(): number;
29
+ /** Value for `key`, marking it most recently used. O(1). */
30
+ get(key: K): V | undefined;
31
+ /** Value for `key` without changing recency. O(1). */
32
+ peek(key: K): V | undefined;
33
+ /** True when `key` is present and not expired; does not change recency. O(1). */
34
+ has(key: K): boolean;
35
+ /** Stores `value` as most recently used; `ttlMs` overrides the default for this entry. O(1). */
36
+ set(key: K, value: V, options?: {
37
+ readonly ttlMs?: number;
38
+ }): this;
39
+ /** Removes `key`. O(1). */
40
+ delete(key: K): boolean;
41
+ /** Removes every entry. */
42
+ clear(): void;
43
+ /** Removes expired entries now; returns how many were removed. O(n). */
44
+ prune(): number;
45
+ /** Live keys, least to most recently used. */
46
+ keys(): Generator<K>;
47
+ /** Live values, least to most recently used. */
48
+ values(): Generator<V>;
49
+ /** Live entries, least to most recently used. O(n). */
50
+ toArray(): [K, V][];
51
+ /** Iterates live entries, least to most recently used. */
52
+ [Symbol.iterator](): Iterator<[K, V]>;
53
+ }
54
+ export interface LFUCacheOptions<K, V> {
55
+ /** Maximum entries (required). */
56
+ readonly maxSize: number;
57
+ /** Called when an entry is evicted for capacity. */
58
+ readonly onEvict?: (key: K, value: V) => void;
59
+ }
60
+ /**
61
+ * Least-frequently-used cache with O(1) operations (frequency buckets in a linked list;
62
+ * ties broken by least recent use within a bucket).
63
+ * Complexity: `get`, `set`, `has`, `peek`, `delete` O(1); iteration O(n).
64
+ * @example
65
+ * const c = new LFUCache<string, number>({ maxSize: 2 });
66
+ * c.set('a', 1).set('b', 2);
67
+ * c.get('a'); c.get('a');
68
+ * c.set('c', 3); // evicts 'b' (used least)
69
+ */
70
+ export declare class LFUCache<K, V> implements Iterable<[K, V]> {
71
+ #private;
72
+ readonly maxSize: number;
73
+ constructor(options: LFUCacheOptions<K, V>);
74
+ /** Number of entries. O(1). */
75
+ get size(): number;
76
+ /** Value for `key`, incrementing its use count. O(1). */
77
+ get(key: K): V | undefined;
78
+ /** Value without counting a use. O(1). */
79
+ peek(key: K): V | undefined;
80
+ /** True when `key` is present. O(1). */
81
+ has(key: K): boolean;
82
+ /** Use count for `key` (0 when absent). O(1). */
83
+ frequency(key: K): number;
84
+ /** Stores `value`; updating an existing key counts as a use. O(1). */
85
+ set(key: K, value: V): this;
86
+ /** Removes `key`. O(1). */
87
+ delete(key: K): boolean;
88
+ /** Removes every entry. */
89
+ clear(): void;
90
+ /** Entries from least to most frequently used. O(n). */
91
+ toArray(): [K, V][];
92
+ /** Iterates entries from least to most frequently used. */
93
+ [Symbol.iterator](): Iterator<[K, V]>;
94
+ }
95
+ export interface TTLCacheOptions<K, V> {
96
+ /** Default time to live in ms (required). */
97
+ readonly ttlMs: number;
98
+ /** Optional capacity; the oldest inserted entry is evicted first. */
99
+ readonly maxSize?: number;
100
+ /** Called when an entry expires (on access or `prune`) or is evicted for capacity. */
101
+ readonly onEvict?: (key: K, value: V, reason: EvictionReason) => void;
102
+ /** Clock in ms, injectable for tests. Default `Date.now`. */
103
+ readonly now?: () => number;
104
+ }
105
+ /**
106
+ * Cache whose entries expire after a per-entry time to live. Expiry is lazy; call `prune()`
107
+ * periodically to reclaim memory. Access does not refresh the TTL (use `touch`).
108
+ * Complexity: `get`, `set`, `has`, `delete`, `touch` O(1); `prune` and iteration O(n).
109
+ * @example
110
+ * const c = new TTLCache<string, string>({ ttlMs: 60_000 });
111
+ * c.set('token', 'abc', { ttlMs: 5_000 });
112
+ * c.get('token'); // 'abc' until 5 s later
113
+ */
114
+ export declare class TTLCache<K, V> implements Iterable<[K, V]> {
115
+ #private;
116
+ constructor(options: TTLCacheOptions<K, V>);
117
+ /** Stored entries, possibly including expired ones not yet pruned. */
118
+ get size(): number;
119
+ /** Stores `value` with `ttlMs` (default from options). O(1). */
120
+ set(key: K, value: V, options?: {
121
+ readonly ttlMs?: number;
122
+ }): this;
123
+ /** Live value for `key`. O(1). */
124
+ get(key: K): V | undefined;
125
+ /** True when `key` is present and not expired. O(1). */
126
+ has(key: K): boolean;
127
+ /** Milliseconds until `key` expires, or `undefined` when absent. */
128
+ ttlRemaining(key: K): number | undefined;
129
+ /** Restarts the TTL of a live entry; returns false when absent. */
130
+ touch(key: K, ttlMs?: number): boolean;
131
+ /** Removes `key`. */
132
+ delete(key: K): boolean;
133
+ /** Removes every entry. */
134
+ clear(): void;
135
+ /** Removes expired entries now; returns how many were removed. O(n). */
136
+ prune(): number;
137
+ /** Live entries in insertion order. */
138
+ toArray(): [K, V][];
139
+ /** Iterates live entries in insertion order. */
140
+ [Symbol.iterator](): Iterator<[K, V]>;
141
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{assertCapacity as a,assertTtl as o}from"./internal.js";class h{maxSize;#e=new Map;#i;#r;#t;constructor(e={}){this.maxSize=e.maxSize??1e3,a(this.maxSize),e.ttlMs!==void 0&&o(e.ttlMs),this.#i=e.ttlMs,this.#r=e.onEvict,this.#t=e.now??Date.now}get size(){return this.#e.size}get(e){const t=this.#n(e);if(t)return this.#e.delete(e),this.#e.set(e,t),t.value}peek(e){return this.#n(e)?.value}has(e){return this.#n(e)!==void 0}set(e,t,n={}){const i=n.ttlMs??this.#i;for(n.ttlMs!==void 0&&o(n.ttlMs),this.#e.delete(e),this.#e.set(e,{value:t,expires:i===void 0?1/0:this.#t()+i});this.#e.size>this.maxSize;){const r=this.#e.entries().next();if(r.done)break;const[s,d]=r.value;this.#e.delete(s),this.#r?.(s,d.value,d.expires<=this.#t()?"expired":"capacity")}return this}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}prune(){const e=this.#t();let t=0;for(const[n,i]of[...this.#e])i.expires<=e&&(this.#e.delete(n),t++,this.#r?.(n,i.value,"expired"));return t}*keys(){for(const[e]of this)yield e}*values(){for(const[,e]of this)yield e}toArray(){return[...this]}*[Symbol.iterator](){const e=this.#t();for(const[t,n]of[...this.#e])n.expires>e&&(yield[t,n.value])}#n(e){const t=this.#e.get(e);if(t){if(t.expires<=this.#t()){this.#e.delete(e),this.#r?.(e,t.value,"expired");return}return t}}}class f{maxSize;#e=new Map;#i={freq:0,keys:new Set,prev:void 0,next:void 0};#r;constructor(e){a(e.maxSize),this.maxSize=e.maxSize,this.#r=e.onEvict}get size(){return this.#e.size}get(e){const t=this.#e.get(e);if(t)return this.#t(e,t),t.value}peek(e){return this.#e.get(e)?.value}has(e){return this.#e.has(e)}frequency(e){return this.#e.get(e)?.node.freq??0}set(e,t){const n=this.#e.get(e);if(n)return n.value=t,this.#t(e,n),this;this.#e.size>=this.maxSize&&this.#n();let i=this.#i.next;return i?.freq!==1&&(i=this.#s(this.#i,1)),i.keys.add(e),this.#e.set(e,{value:t,node:i}),this}delete(e){const t=this.#e.get(e);return t?(this.#e.delete(e),t.node.keys.delete(e),t.node.keys.size===0&&this.#o(t.node),!0):!1}clear(){this.#e.clear(),this.#i.next=void 0}toArray(){return[...this]}*[Symbol.iterator](){const e=[];for(let t=this.#i.next;t;t=t.next)for(const n of t.keys){const i=this.#e.get(n);i&&e.push([n,i.value])}yield*e}#t(e,t){const n=t.node;let i=n.next;i?.freq!==n.freq+1&&(i=this.#s(n,n.freq+1)),n.keys.delete(e),i.keys.add(e),t.node=i,n.keys.size===0&&this.#o(n)}#n(){const e=this.#i.next;if(!e)return;const t=e.keys.values().next();if(t.done)return;const n=t.value,i=this.#e.get(n);this.delete(n),i&&this.#r?.(n,i.value)}#s(e,t){const n={freq:t,keys:new Set,prev:e,next:e.next};return e.next&&(e.next.prev=n),e.next=n,n}#o(e){e.prev&&(e.prev.next=e.next),e.next&&(e.next.prev=e.prev),e.prev=e.next=void 0}}class c{#e=new Map;#i;#r;#t;#n;constructor(e){o(e.ttlMs),e.maxSize!==void 0&&a(e.maxSize),this.#i=e.ttlMs,this.#r=e.maxSize,this.#t=e.onEvict,this.#n=e.now??Date.now}get size(){return this.#e.size}set(e,t,n={}){const i=n.ttlMs??this.#i;if(o(i),this.#e.delete(e),this.#e.set(e,{value:t,expires:this.#n()+i}),this.#r!==void 0)for(;this.#e.size>this.#r;){const r=this.#e.entries().next();if(r.done)break;const[s,d]=r.value;this.#e.delete(s),this.#t?.(s,d.value,"capacity")}return this}get(e){return this.#s(e)?.value}has(e){return this.#s(e)!==void 0}ttlRemaining(e){const t=this.#s(e);return t?t.expires-this.#n():void 0}touch(e,t=this.#i){o(t);const n=this.#s(e);return n?(n.expires=this.#n()+t,!0):!1}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}prune(){const e=this.#n();let t=0;for(const[n,i]of[...this.#e])i.expires<=e&&(this.#e.delete(n),t++,this.#t?.(n,i.value,"expired"));return t}toArray(){return[...this]}*[Symbol.iterator](){const e=this.#n();for(const[t,n]of[...this.#e])n.expires>e&&(yield[t,n.value])}#s(e){const t=this.#e.get(e);if(t){if(t.expires<=this.#n()){this.#e.delete(e),this.#t?.(e,t.value,"expired");return}return t}}}export{f as LFUCache,h as LRUCache,c as TTLCache};
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Union-find with path compression and union by rank.
3
+ * Complexity: `add`, `find`, `union`, `connected`, `sizeOf` O(α(n)) amortized (effectively constant);
4
+ * `sets` O(n). `find` is iterative.
5
+ * @example
6
+ * const ds = new DisjointSet(['a', 'b', 'c']);
7
+ * ds.union('a', 'b');
8
+ * ds.connected('a', 'b'); // => true
9
+ * ds.setCount; // => 2
10
+ */
11
+ export declare class DisjointSet<T> implements Iterable<T> {
12
+ #private;
13
+ constructor(items?: Iterable<T>);
14
+ /** Number of elements. O(1). */
15
+ get size(): number;
16
+ /** Number of disjoint sets. O(1). */
17
+ get setCount(): number;
18
+ /** Adds `item` as a singleton set if absent. */
19
+ add(item: T): this;
20
+ /** True when `item` has been added. */
21
+ has(item: T): boolean;
22
+ /** Representative of `item`'s set, or `undefined` when absent. */
23
+ find(item: T): T | undefined;
24
+ /** Merges the sets of `a` and `b` (adding either if absent). Returns false when already joined. */
25
+ union(a: T, b: T): boolean;
26
+ /** True when `a` and `b` are in the same set. */
27
+ connected(a: T, b: T): boolean;
28
+ /** Size of `item`'s set (0 when absent). */
29
+ sizeOf(item: T): number;
30
+ /** Every set as an array, in first-seen order. O(n). */
31
+ sets(): T[][];
32
+ /** Removes every element. */
33
+ clear(): void;
34
+ /** Elements in insertion order. */
35
+ toArray(): T[];
36
+ /** Iterates elements in insertion order. */
37
+ [Symbol.iterator](): Iterator<T>;
38
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ class u{#t=new Map;#e=new Map;#s=new Map;#r=0;constructor(t){if(t)for(const s of t)this.add(s)}get size(){return this.#t.size}get setCount(){return this.#r}add(t){return this.#t.has(t)||(this.#t.set(t,t),this.#e.set(t,0),this.#s.set(t,1),this.#r++),this}has(t){return this.#t.has(t)}find(t){if(!this.#t.has(t))return;let s=t;for(let e=this.#t.get(s);e!==s;e=this.#t.get(s))s=e;for(let e=t;e!==s;){const r=this.#t.get(e);this.#t.set(e,s),e=r}return s}union(t,s){this.add(t).add(s);const e=this.find(t),r=this.find(s);if(e===r)return!1;const n=this.#e.get(e)??0,a=this.#e.get(r)??0,[i,h]=n>=a?[e,r]:[r,e];return this.#t.set(h,i),n===a&&this.#e.set(i,n+1),this.#s.set(i,(this.#s.get(i)??0)+(this.#s.get(h)??0)),this.#s.delete(h),this.#r--,!0}connected(t,s){return this.#t.has(t)&&this.#t.has(s)&&this.find(t)===this.find(s)}sizeOf(t){return this.#t.has(t)?this.#s.get(this.find(t))??0:0}sets(){const t=new Map;for(const s of this.#t.keys()){const e=this.find(s),r=t.get(e);r?r.push(s):t.set(e,[s])}return[...t.values()]}clear(){this.#t.clear(),this.#e.clear(),this.#s.clear(),this.#r=0}toArray(){return[...this.#t.keys()]}[Symbol.iterator](){return this.#t.keys()}}export{u as DisjointSet};
@@ -0,0 +1,53 @@
1
+ /** Event map: event name -> listener argument tuple, e.g. `{ change: [value: number]; close: [] }`. */
2
+ export type EventMap<E> = {
3
+ [K in keyof E]: unknown[];
4
+ };
5
+ /** Listener for event `K`. */
6
+ export type Listener<E extends EventMap<E>, K extends keyof E> = (...args: E[K]) => void;
7
+ export interface TypedEventEmitterOptions {
8
+ /**
9
+ * Catch listener errors so every listener runs; errors go to `onError`. Default false: the first
10
+ * throwing listener stops the emit and the error propagates to the `emit` caller.
11
+ */
12
+ readonly isolateErrors?: boolean;
13
+ /** Receives isolated listener errors. */
14
+ readonly onError?: (error: Error, event: PropertyKey) => void;
15
+ /** Listener count per event above which `onMaxListeners` fires once per event. Default 10; 0 disables. */
16
+ readonly maxListeners?: number;
17
+ /** Called (not logged) when an event first exceeds `maxListeners`, a common leak signal. */
18
+ readonly onMaxListeners?: (event: PropertyKey, count: number) => void;
19
+ }
20
+ /**
21
+ * Strongly typed event emitter. `on` returns an unsubscribe function; listeners are snapshotted per
22
+ * `emit`, so adding or removing listeners during an emit is safe.
23
+ * Complexity: `on`, `emit` O(listeners of the event); `off` O(listeners of the event).
24
+ * Not iterable and has no `size`; use `listenerCount`.
25
+ * @example
26
+ * const bus = new TypedEventEmitter<{ saved: [id: string]; reset: [] }>();
27
+ * const messages: string[] = [];
28
+ * const stop = bus.on('saved', (id) => { messages.push(`Saved ${id}`); });
29
+ * bus.emit('saved', 'e-42');
30
+ * stop();
31
+ * bus.emit('saved', 'e-43'); // no listener any more
32
+ * messages; // => ['Saved e-42']
33
+ */
34
+ export declare class TypedEventEmitter<E extends EventMap<E>> {
35
+ #private;
36
+ constructor(options?: TypedEventEmitterOptions);
37
+ /** Subscribes `listener` to `event`; returns an unsubscribe function. */
38
+ on<K extends keyof E>(event: K, listener: Listener<E, K>): () => void;
39
+ /** Subscribes for a single emit; returns an unsubscribe function. */
40
+ once<K extends keyof E>(event: K, listener: Listener<E, K>): () => void;
41
+ /** Removes one registration of `listener` from `event`. */
42
+ off<K extends keyof E>(event: K, listener: Listener<E, K>): boolean;
43
+ /** Calls every listener of `event` with `args`; returns true when there were listeners. */
44
+ emit<K extends keyof E>(event: K, ...args: E[K]): boolean;
45
+ /** Number of listeners for `event`, or for all events when omitted. */
46
+ listenerCount(event?: keyof E): number;
47
+ /** Event names that have listeners. */
48
+ eventNames(): (keyof E)[];
49
+ /** Removes all listeners of `event`, or of every event when omitted. */
50
+ removeAllListeners(event?: keyof E): void;
51
+ /** Alias of `removeAllListeners()`. */
52
+ clear(): void;
53
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{toError as o}from"../error/index.js";class E{#e=new Map;#t=new Set;#r;constructor(e={}){this.#r=e}on(e,r){let t=this.#e.get(e);t||(t=[],this.#e.set(e,t)),t.push(r);const s=this.#r.maxListeners??10;return s>0&&t.length>s&&!this.#t.has(e)&&(this.#t.add(e),this.#r.onMaxListeners?.(e,t.length)),()=>{this.off(e,r)}}once(e,r){const t=(...n)=>{s(),r(...n)},s=this.on(e,t);return s}off(e,r){const t=this.#e.get(e);if(!t)return!1;const s=t.indexOf(r);return s<0?!1:(t.splice(s,1),t.length===0&&(this.#e.delete(e),this.#t.delete(e)),!0)}emit(e,...r){const t=this.#e.get(e);if(!t||t.length===0)return!1;for(const s of t.slice()){if(!this.#r.isolateErrors){s(...r);continue}try{s(...r)}catch(n){this.#r.onError?.(o(n),e)}}return!0}listenerCount(e){if(e!==void 0)return this.#e.get(e)?.length??0;let r=0;for(const t of this.#e.values())r+=t.length;return r}eventNames(){return[...this.#e.keys()]}removeAllListeners(e){e===void 0?(this.#e.clear(),this.#t.clear()):(this.#e.delete(e),this.#t.delete(e))}clear(){this.removeAllListeners()}}export{E as TypedEventEmitter};
@@ -0,0 +1,84 @@
1
+ export interface GraphOptions {
2
+ /** Directed edges (default true). Undirected edges are stored in both directions and counted once. */
3
+ readonly directed?: boolean;
4
+ }
5
+ /** Result of `shortestPath`. */
6
+ export interface ShortestPath<N> {
7
+ readonly path: N[];
8
+ readonly distance: number;
9
+ }
10
+ /**
11
+ * Directed or undirected weighted graph on adjacency maps. Nodes are compared with `Map` semantics
12
+ * (SameValueZero). Every algorithm is iterative, so deep or long graphs cannot overflow the stack.
13
+ * Complexity (V nodes, E edges): `addNode`, `addEdge`, `removeEdge`, `hasEdge`, `weight` O(1);
14
+ * `removeNode` O(degree); `bfs`, `dfs`, `topologicalSort`, `hasCycle`, `findCycle`, `connectedComponents`,
15
+ * `stronglyConnectedComponents` O(V + E); `shortestPath` O((V + E) log V).
16
+ * @example
17
+ * const g = new Graph<string>();
18
+ * g.addEdge('shirt', 'tie').addEdge('tie', 'jacket').addEdge('trousers', 'jacket');
19
+ * g.topologicalSort(); // => ['shirt', 'trousers', 'tie', 'jacket']
20
+ */
21
+ export declare class Graph<N> implements Iterable<N> {
22
+ #private;
23
+ readonly directed: boolean;
24
+ constructor(options?: GraphOptions);
25
+ /** Number of nodes. O(1). */
26
+ get size(): number;
27
+ /** Number of edges (undirected edges count once). O(1). */
28
+ get edgeCount(): number;
29
+ /** Adds `node` if absent. O(1). */
30
+ addNode(node: N): this;
31
+ /** True when `node` exists. O(1). */
32
+ hasNode(node: N): boolean;
33
+ /** Adds or re-weights the edge `from -> to` (both ways when undirected), adding missing nodes. O(1). */
34
+ addEdge(from: N, to: N, weight?: number): this;
35
+ /** True when the edge `from -> to` exists. O(1). */
36
+ hasEdge(from: N, to: N): boolean;
37
+ /** Weight of `from -> to`, or `undefined`. O(1). */
38
+ weight(from: N, to: N): number | undefined;
39
+ /** Removes the edge `from -> to` (both ways when undirected). O(1). */
40
+ removeEdge(from: N, to: N): boolean;
41
+ /** Removes `node` and its edges. O(degree). */
42
+ removeNode(node: N): boolean;
43
+ /** Out-neighbours of `node` (all neighbours when undirected). O(degree). */
44
+ neighbors(node: N): N[];
45
+ /** In-neighbours of `node` (same as `neighbors` when undirected). O(degree). */
46
+ inNeighbors(node: N): N[];
47
+ /** Every node in insertion order. */
48
+ nodes(): N[];
49
+ /** Every edge as `[from, to, weight]` (undirected edges once). */
50
+ edges(): Generator<[N, N, number]>;
51
+ /** Removes every node and edge. */
52
+ clear(): void;
53
+ /** Nodes in insertion order. */
54
+ toArray(): N[];
55
+ /** Iterates nodes in insertion order. */
56
+ [Symbol.iterator](): Iterator<N>;
57
+ /** Breadth-first nodes reachable from `start` (nothing when absent). */
58
+ bfs(start: N): Generator<N>;
59
+ /** Depth-first (pre-order) nodes reachable from `start`, visiting neighbours in insertion order. */
60
+ dfs(start: N): Generator<N>;
61
+ /**
62
+ * Kahn's topological order (ties in insertion order). Directed graphs only.
63
+ * Throws `HLP_DS_GRAPH_CYCLE` with `details.cycle` (node ids) when a cycle exists.
64
+ */
65
+ topologicalSort(): N[];
66
+ /** True when the graph has a cycle (self-loops count). O(V + E). */
67
+ hasCycle(): boolean;
68
+ /**
69
+ * One cycle as its nodes in edge order (`[a, b, c]` means a -> b -> c -> a), or `undefined`.
70
+ * Undirected graphs need at least three distinct nodes (or a self-loop) to form a cycle.
71
+ */
72
+ findCycle(): N[] | undefined;
73
+ /**
74
+ * Dijkstra's shortest path from `from` to `to`, or `undefined` when unreachable or absent.
75
+ * Throws `HLP_DS_GRAPH_NEGATIVE_WEIGHT` when it meets a negative edge.
76
+ */
77
+ shortestPath(from: N, to: N): ShortestPath<N> | undefined;
78
+ /** Shortest distances from `from` to every reachable node (Dijkstra). */
79
+ distancesFrom(from: N): Map<N, number>;
80
+ /** Connected components (weakly connected for directed graphs), each in BFS order. O(V + E). */
81
+ connectedComponents(): N[][];
82
+ /** Strongly connected components (iterative Tarjan), in reverse topological order. O(V + E). */
83
+ stronglyConnectedComponents(): N[][];
84
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{HelperError as w,ValidationError as g}from"../error/index.js";import{BinaryHeap as y}from"./heap.js";import{Queue as m}from"./ring.js";class v{directed;#e=new Map;#t;#n=0;constructor(e={}){this.directed=e.directed??!0,this.#t=this.directed?new Map:this.#e}get size(){return this.#e.size}get edgeCount(){return this.#n}addNode(e){return this.#e.has(e)||(this.#e.set(e,new Map),this.directed&&this.#t.set(e,new Map)),this}hasNode(e){return this.#e.has(e)}addEdge(e,t,n=1){if(Number.isNaN(n))throw new g("HLP_DS_GRAPH_INVALID_WEIGHT","Edge weight must be a number.");this.addNode(e).addNode(t);const s=this.#e.get(e);return s?(s.has(t)||this.#n++,s.set(t,n),this.#t.get(t)?.set(e,n),this):this}hasEdge(e,t){return this.#e.get(e)?.has(t)??!1}weight(e,t){return this.#e.get(e)?.get(t)}removeEdge(e,t){return this.#e.get(e)?.delete(t)?(this.#t.get(t)?.delete(e),this.#n--,!0):!1}removeNode(e){const t=this.#e.get(e);if(!t)return!1;if(this.directed){const n=this.#t.get(e)??new Map;this.#n-=t.size+n.size-(t.has(e)?1:0);for(const s of t.keys())this.#t.get(s)?.delete(e);for(const s of n.keys())this.#e.get(s)?.delete(e);this.#t.delete(e)}else{this.#n-=t.size;for(const n of t.keys())n!==e&&this.#e.get(n)?.delete(e)}return this.#e.delete(e),!0}neighbors(e){return[...this.#e.get(e)?.keys()??[]]}inNeighbors(e){return[...this.#t.get(e)?.keys()??[]]}nodes(){return[...this.#e.keys()]}*edges(){const e=this.directed?void 0:new Set;for(const[t,n]of this.#e){for(const[s,i]of n)e?.has(s)||(yield[t,s,i]);e?.add(t)}}clear(){this.#e.clear(),this.#t.clear(),this.#n=0}toArray(){return this.nodes()}[Symbol.iterator](){return this.#e.keys()}*bfs(e){if(!this.#e.has(e))return;const t=new Set([e]),n=new m([e]);for(;n.size>0;){const s=n.dequeue();yield s;for(const i of this.#e.get(s)?.keys()??[])t.has(i)||(t.add(i),n.enqueue(i))}}*dfs(e){if(!this.#e.has(e))return;const t=new Set,n=[e];for(;n.length>0;){const s=n.pop();if(t.has(s))continue;t.add(s),yield s;const i=this.neighbors(s);for(let r=i.length-1;r>=0;r--){const o=i[r];t.has(o)||n.push(o)}}}topologicalSort(){this.#i();const e=new Map;for(const[s,i]of this.#t)e.set(s,i.size);const t=new m;for(const[s,i]of e)i===0&&t.enqueue(s);const n=[];for(;t.size>0;){const s=t.dequeue();n.push(s);for(const i of this.#e.get(s)?.keys()??[]){const r=(e.get(i)??0)-1;e.set(i,r),r===0&&t.enqueue(i)}}if(n.length<this.#e.size)throw new w("HLP_DS_GRAPH_CYCLE","The graph contains a cycle.",{kind:"conflict",details:{cycle:this.findCycle()??[]}});return n}hasCycle(){return this.findCycle()!==void 0}findCycle(){return this.directed?this.#r():this.#o()}shortestPath(e,t){if(!this.#e.has(e)||!this.#e.has(t))return;const{dist:n,prev:s}=this.#s(e,t),i=n.get(t);if(i===void 0)return;const r=[t];for(let o=t;o!==e&&s.has(o);)o=s.get(o),r.push(o);return{path:r.reverse(),distance:i}}distancesFrom(e){return this.#e.has(e)?this.#s(e,void 0).dist:new Map}connectedComponents(){const e=new Set,t=[];for(const n of this.#e.keys()){if(e.has(n))continue;e.add(n);const s=[],i=new m([n]);for(;i.size>0;){const r=i.dequeue();s.push(r);for(const o of[this.#e.get(r),this.directed?this.#t.get(r):void 0])for(const h of o?.keys()??[])e.has(h)||(e.add(h),i.enqueue(h))}t.push(s)}return t}stronglyConnectedComponents(){if(!this.directed)return this.connectedComponents();let e=0;const t=new Map,n=new Map,s=new Set,i=[],r=[];for(const o of this.#e.keys()){if(t.has(o))continue;const h=[],a=d=>{t.set(d,e),n.set(d,e),e++,i.push(d),s.add(d),h.push([d,(this.#e.get(d)??new Map).keys()])};a(o);for(let d=h.at(-1);d;d=h.at(-1)){const[c,u]=d,N=u.next();if(!N.done){const f=N.value;t.has(f)?s.has(f)&&n.set(c,Math.min(n.get(c)??0,t.get(f)??0)):a(f);continue}h.pop();const p=h[h.length-1];if(p&&n.set(p[0],Math.min(n.get(p[0])??0,n.get(c)??0)),n.get(c)===t.get(c)){const f=[];for(;;){const l=i.pop();if(s.delete(l),f.push(l),l===c)break}r.push(f)}}}return r}#i(){if(!this.directed)throw new g("HLP_DS_GRAPH_UNDIRECTED","This operation needs a directed graph.")}#s(e,t){const n=new Map([[e,0]]),s=new Map,i=new Set,r=new y([[0,e]],(o,h)=>o[0]-h[0]);for(let o=r.pop();o;o=r.pop()){const[h,a]=o;if(!i.has(a)){if(i.add(a),t!==void 0&&a===t)break;for(const[d,c]of this.#e.get(a)??[]){if(c<0)throw new g("HLP_DS_GRAPH_NEGATIVE_WEIGHT","Shortest path needs non-negative edge weights.");const u=h+c,N=n.get(d);(N===void 0||u<N)&&(n.set(d,u),s.set(d,a),r.push([u,d]))}}}if(t!==void 0)for(const o of[...n.keys()])!i.has(o)&&o!==t&&n.delete(o);return{dist:n,prev:s}}#r(){const e=new Map,t=new Map;for(const n of this.#e.keys()){if(e.has(n))continue;const s=[[n,(this.#e.get(n)??new Map).keys()]];e.set(n,1);for(let i=s.at(-1);i;i=s.at(-1)){const[r,o]=i,h=o.next();if(h.done){e.set(r,2),s.pop();continue}const a=h.value,d=e.get(a);if(d===1){const c=[r];for(let u=r;u!==a;)u=t.get(u),c.push(u);return c.reverse()}d===void 0&&(e.set(a,1),t.set(a,r),s.push([a,(this.#e.get(a)??new Map).keys()]))}}}#o(){const e=new Set,t=new Map;for(const n of this.#e.keys()){if(e.has(n))continue;e.add(n);const s=[[n,(this.#e.get(n)??new Map).keys()]];for(let i=s.at(-1);i;i=s.at(-1)){const[r,o]=i,h=o.next();if(h.done){s.pop();continue}const a=h.value;if(a===r)return[r];if(!(t.has(r)&&t.get(r)===a)){if(e.has(a)){const d=[r];for(let c=r;c!==a;)c=t.get(c),d.push(c);return d.reverse()}e.add(a),t.set(a,r),s.push([a,(this.#e.get(a)??new Map).keys()])}}}}}export{v as Graph};
@@ -0,0 +1,49 @@
1
+ import { type Comparer } from './internal.js';
2
+ /**
3
+ * Array-backed binary min-heap ordered by `comparer` (pass a reversed comparer for a max-heap).
4
+ * Complexity: `push`, `pop`, `replace` O(log n); `peek` O(1); construction from an iterable O(n);
5
+ * `remove` O(n). Iteration order is the internal heap order; use `drain()` for sorted order.
6
+ * @example
7
+ * const h = new BinaryHeap([5, 1, 3]);
8
+ * h.pop(); // => 1
9
+ * const byPriority = new BinaryHeap<{ p: number }>([], (a, b) => a.p - b.p);
10
+ */
11
+ export declare class BinaryHeap<T> implements Iterable<T> {
12
+ #private;
13
+ constructor(items?: Iterable<T>, comparer?: Comparer<T>);
14
+ /** Builds a heap from `items` in O(n). */
15
+ static from<T>(items: Iterable<T>, comparer?: Comparer<T>): BinaryHeap<T>;
16
+ /** Number of items. O(1). */
17
+ get size(): number;
18
+ /** True when empty. */
19
+ isEmpty(): boolean;
20
+ /** Adds `item`. O(log n). */
21
+ push(item: T): this;
22
+ /** Smallest item without removing it. O(1). */
23
+ peek(): T | undefined;
24
+ /** Removes and returns the smallest item. O(log n). */
25
+ pop(): T | undefined;
26
+ /** Pops the smallest item and pushes `item` in one sift. Returns the popped item (undefined if it was empty). O(log n). */
27
+ replace(item: T): T | undefined;
28
+ /** Removes the first item equal to `item` (by `equals`, default `Object.is`). O(n). */
29
+ remove(item: T, equals?: (a: T, b: T) => boolean): boolean;
30
+ /** Removes every item. */
31
+ clear(): void;
32
+ /** Items in internal heap order (not sorted). O(n). */
33
+ toArray(): T[];
34
+ /** Items in ascending order without modifying the heap. O(n log n). */
35
+ toSortedArray(): T[];
36
+ /** Pops every item in ascending order, emptying the heap. */
37
+ drain(): Generator<T>;
38
+ /** Iterates in internal heap order without removing. */
39
+ [Symbol.iterator](): Iterator<T>;
40
+ }
41
+ /**
42
+ * Priority queue (alias of `BinaryHeap`): lowest value per `comparer` comes out first.
43
+ * @example
44
+ * const pq = new PriorityQueue<[number, string]>([], (a, b) => a[0] - b[0]);
45
+ * pq.push([2, 'b']).push([1, 'a']);
46
+ * pq.pop(); // => [1, 'a']
47
+ */
48
+ export declare class PriorityQueue<T> extends BinaryHeap<T> {
49
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{naturalCompare as T}from"./internal.js";class a{#t;#e;constructor(e,t=T){this.#e=t,this.#t=e?[...e]:[];for(let s=(this.#t.length>>1)-1;s>=0;s--)this.#s(s)}static from(e,t=T){return new a(e,t)}get size(){return this.#t.length}isEmpty(){return this.#t.length===0}push(e){return this.#t.push(e),this.#r(this.#t.length-1),this}peek(){return this.#t[0]}pop(){const e=this.#t;if(e.length===0)return;const t=e[0],s=e.pop();return e.length>0&&(e[0]=s,this.#s(0)),t}replace(e){const t=this.#t;if(t.length===0){t.push(e);return}const s=t[0];return t[0]=e,this.#s(0),s}remove(e,t=Object.is){const s=this.#t,r=s.findIndex(n=>t(n,e));if(r<0)return!1;const i=s.pop();return r<s.length&&(s[r]=i,this.#s(r),this.#r(r)),!0}clear(){this.#t=[]}toArray(){return this.#t.slice()}toSortedArray(){return this.#t.slice().sort(this.#e)}*drain(){for(;this.#t.length>0;)yield this.pop()}[Symbol.iterator](){return this.#t.slice()[Symbol.iterator]()}#r(e){const t=this.#t,s=t[e];let r=e;for(;r>0;){const i=r-1>>1,n=t[i];if(this.#e(s,n)>=0)break;t[r]=n,r=i}t[r]=s}#s(e){const t=this.#t,s=t.length,r=t[e];let i=e;for(;;){const n=2*i+1;if(n>=s)break;const o=n+1;let h=n;o<s&&this.#e(t[o],t[n])<0&&(h=o);const l=t[h];if(this.#e(l,r)>=0)break;t[i]=l,i=h}t[i]=r}}class u extends a{}export{a as BinaryHeap,u as PriorityQueue};
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Data structures (docs/PLAN-HELPERS.md section 2 `ds`). Each class documents its Big-O in TSDoc.
3
+ * Algorithms are iterative (or bounded by O(log n) recursion) so large inputs cannot overflow the stack.
4
+ */
5
+ export type { Comparer } from './internal.js';
6
+ export { naturalCompare } from './internal.js';
7
+ export { Stack } from './stack.js';
8
+ export { Deque, Queue, CircularBuffer } from './ring.js';
9
+ export { BinaryHeap, PriorityQueue } from './heap.js';
10
+ export { LinkedList, type LinkedListNode } from './linked-list.js';
11
+ export { LRUCache, LFUCache, TTLCache, type EvictionReason, type LRUCacheOptions, type LFUCacheOptions, type TTLCacheOptions } from './caches.js';
12
+ export { SortedMap, SortedSet, type RangeBounds } from './sorted.js';
13
+ export { IntervalTree, type IntervalEntry, type IntervalTreeOptions } from './interval-tree.js';
14
+ export { Trie, TrieMap, type TrieOptions } from './trie.js';
15
+ export { Graph, type GraphOptions, type ShortestPath } from './graph.js';
16
+ export { DisjointSet } from './disjoint-set.js';
17
+ export { BitSet } from './bitset.js';
18
+ export { MultiMap, BiMap, type MultiMapOptions } from './maps.js';
19
+ export { BloomFilter, type BloomFilterOptions } from './bloom.js';
20
+ export { TypedEventEmitter, type EventMap, type Listener, type TypedEventEmitterOptions } from './emitter.js';
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{naturalCompare as r}from"./internal.js";import{Stack as p}from"./stack.js";import{Deque as a,Queue as n,CircularBuffer as m}from"./ring.js";import{BinaryHeap as f,PriorityQueue as s}from"./heap.js";import{LinkedList as l}from"./linked-list.js";import{LRUCache as L,LFUCache as T,TTLCache as h}from"./caches.js";import{SortedMap as C,SortedSet as O}from"./sorted.js";import{IntervalTree as M}from"./interval-tree.js";import{Trie as B,TrieMap as E}from"./trie.js";import{Graph as F}from"./graph.js";import{DisjointSet as U}from"./disjoint-set.js";import{BitSet as I}from"./bitset.js";import{MultiMap as D,BiMap as G}from"./maps.js";import{BloomFilter as Q}from"./bloom.js";import{TypedEventEmitter as q}from"./emitter.js";export{G as BiMap,f as BinaryHeap,I as BitSet,Q as BloomFilter,m as CircularBuffer,a as Deque,U as DisjointSet,F as Graph,M as IntervalTree,T as LFUCache,L as LRUCache,l as LinkedList,D as MultiMap,s as PriorityQueue,n as Queue,C as SortedMap,O as SortedSet,p as Stack,h as TTLCache,B as Trie,E as TrieMap,q as TypedEventEmitter,r as naturalCompare};
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Shared internals for `ds`: default ordering, validation, and error helpers. Not a public entry.
3
+ */
4
+ import { HelperError } from '../error/index.js';
5
+ /** Three-way comparer: negative when `a` sorts before `b`, zero when equal, positive otherwise. */
6
+ export type Comparer<T> = (a: T, b: T) => number;
7
+ /**
8
+ * Natural ordering for numbers, strings (code-unit order), bigints, booleans, and `Date`s.
9
+ * `NaN` sorts after every other number. Mixed or unsupported types throw `HLP_DS_NOT_COMPARABLE`.
10
+ * @example
11
+ * [3, 1, 2].sort(naturalCompare); // => [1, 2, 3]
12
+ */
13
+ export declare function naturalCompare(a: unknown, b: unknown): number;
14
+ /** Throws `HLP_DS_INVALID_CAPACITY` unless `n` is a positive safe integer (or zero when allowed). */
15
+ export declare function assertCapacity(n: number, allowZero?: boolean): void;
16
+ /** Throws `HLP_DS_INVALID_TTL` unless `ms` is a finite number greater than zero. */
17
+ export declare function assertTtl(ms: number): void;
18
+ /** Error thrown when a structure is modified while one of its iterators is active. */
19
+ export declare function concurrentModification(): HelperError;
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{HelperError as n,ValidationError as t}from"../error/index.js";function o(e,r){if(typeof e=="number"&&typeof r=="number")return e<r?-1:e>r?1:e===r?0:Number.isNaN(e)?Number.isNaN(r)?0:1:-1;if(typeof e=="string"&&typeof r=="string"||typeof e=="bigint"&&typeof r=="bigint"||typeof e=="boolean"&&typeof r=="boolean")return e<r?-1:e>r?1:0;if(e instanceof Date&&r instanceof Date)return o(e.getTime(),r.getTime());throw new t("HLP_DS_NOT_COMPARABLE","Values are not comparable without a custom comparer.")}function u(e,r=!1){if(!Number.isSafeInteger(e)||e<(r?0:1))throw new t("HLP_DS_INVALID_CAPACITY","Capacity must be a positive integer.")}function f(e){if(!Number.isFinite(e)||e<=0)throw new t("HLP_DS_INVALID_TTL","TTL must be a finite number of milliseconds greater than zero.")}function a(){return new n("HLP_DS_CONCURRENT_MODIFICATION","The collection was modified during iteration.",{kind:"conflict"})}export{u as assertCapacity,f as assertTtl,a as concurrentModification,o as naturalCompare};