@absoluteui/helpers 0.0.0-stage → 0.13.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.
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,49 @@
1
+ /** A stored interval; the object identity is the handle for `remove`. */
2
+ export interface IntervalEntry<T> {
3
+ readonly start: number;
4
+ readonly end: number;
5
+ readonly value: T;
6
+ }
7
+ export interface IntervalTreeOptions {
8
+ /**
9
+ * `'[]'` (default): closed intervals; touching intervals overlap.
10
+ * `'[)'`: half-open, as for bookings: `[9, 10)` and `[10, 11)` do not overlap; empty intervals match nothing.
11
+ */
12
+ readonly bounds?: '[]' | '[)';
13
+ }
14
+ /**
15
+ * Augmented AVL interval tree (each node keeps the max `end` in its subtree).
16
+ * Complexity: `insert`, `remove` O(log n); `search`, `searchPoint` O(log n + k); iteration O(n).
17
+ * Results come back ordered by `start`, then `end`, then insertion order.
18
+ * @example
19
+ * const t = new IntervalTree<string>({ bounds: '[)' });
20
+ * t.insert(9, 10, 'standup');
21
+ * t.insert(10, 11, 'review');
22
+ * t.search(9.5, 10).map((e) => e.value); // => ['standup']
23
+ * t.searchPoint(10).map((e) => e.value); // => ['review']
24
+ */
25
+ export declare class IntervalTree<T> implements Iterable<IntervalEntry<T>> {
26
+ #private;
27
+ readonly bounds: '[]' | '[)';
28
+ constructor(options?: IntervalTreeOptions);
29
+ /** Number of intervals. O(1). */
30
+ get size(): number;
31
+ /** Adds `[start, end]` carrying `value`; duplicates are allowed. Returns the entry handle. O(log n). */
32
+ insert(start: number, end: number, value: T): IntervalEntry<T>;
33
+ /** Removes the entry returned by `insert`. O(log n). */
34
+ remove(entry: IntervalEntry<T>): boolean;
35
+ /** Removes the first interval with exactly `start`, `end`, and `value` (`Object.is`). O(log n + k). */
36
+ delete(start: number, end: number, value: T): boolean;
37
+ /** Intervals overlapping `[start, end]` (or `[start, end)` in half-open mode). O(log n + k). */
38
+ search(start: number, end: number): IntervalEntry<T>[];
39
+ /** Intervals containing `point`. O(log n + k). */
40
+ searchPoint(point: number): IntervalEntry<T>[];
41
+ /** True when any interval overlaps `[start, end]`. O(log n). */
42
+ overlaps(start: number, end: number): boolean;
43
+ /** Removes every interval. */
44
+ clear(): void;
45
+ /** Every entry ordered by start. O(n). */
46
+ toArray(): IntervalEntry<T>[];
47
+ /** Iterates entries ordered by start. */
48
+ [Symbol.iterator](): Iterator<IntervalEntry<T>>;
49
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{ValidationError as f}from"../error/index.js";import{AvlTree as d}from"./avl.js";const h=(t,e)=>t.start-e.start||t.end-e.end||t.seq-e.seq;class v{bounds;#e=new d(h,e=>{e.aug=Math.max(e.key.end,e.left?e.left.aug:-1/0,e.right?e.right.aug:-1/0)});#r=0;constructor(e={}){this.bounds=e.bounds??"[]"}get size(){return this.#e.size}insert(e,n,r){u(e,n);const s={start:e,end:n,value:r,seq:this.#r++};return this.#e.insert(s,void 0),s}remove(e){return!c(e)||this.#e.find(e)?.key!==e?!1:(this.#e.delete(e),!0)}delete(e,n,r){for(const s of this.#e.ascending({key:{start:e,end:n,value:r,seq:-1/0},exclusive:!1})){if(s.key.start!==e||s.key.end!==n)return!1;if(Object.is(s.key.value,r))return this.#e.delete(s.key),!0}return!1}search(e,n){u(e,n);const r=this.bounds==="[)";return this.#n(e,n,r,r)}searchPoint(e){if(Number.isNaN(e))throw new f("HLP_DS_INVALID_INTERVAL","The point must be a number.");return this.#n(e,e,this.bounds==="[)",!1)}overlaps(e,n){u(e,n);const r=this.bounds==="[)";return this.#n(e,n,r,r,1).length>0}clear(){this.#e.clear()}toArray(){return[...this]}*[Symbol.iterator](){for(const e of this.#e.ascending())yield e.key}#n(e,n,r,s,m=1/0){const a=[],y=o=>r?o>e:o>=e,l=[];let i=this.#e.root;for(;l.length>0||i;){for(;i&&y(i.aug);)l.push(i),i=i.left;const o=l.pop();if(!o)break;const b=o.key.start;if((s?b>=n:b>n)||y(o.key.end)&&(a.push(o.key),a.length>=m))break;i=o.right}return a}}function c(t){return typeof t.seq=="number"}function u(t,e){if(Number.isNaN(t)||Number.isNaN(e)||typeof t!="number"||typeof e!="number"||t>e)throw new f("HLP_DS_INVALID_INTERVAL","An interval needs numeric bounds with start <= end.")}export{v as IntervalTree};
@@ -0,0 +1,54 @@
1
+ /** Node handle returned by `LinkedList`; links are read-only to callers. */
2
+ export interface LinkedListNode<T> {
3
+ value: T;
4
+ readonly prev: LinkedListNode<T> | undefined;
5
+ readonly next: LinkedListNode<T> | undefined;
6
+ }
7
+ /**
8
+ * Doubly linked list with node handles for O(1) insertion and removal anywhere.
9
+ * Complexity: `push`, `pop`, `shift`, `unshift`, `insertAfter`, `insertBefore`, `remove` O(1);
10
+ * `find`, `reverse`, iteration O(n).
11
+ * @example
12
+ * const list = new LinkedList([1, 3]);
13
+ * const one = list.find((v) => v === 1)!;
14
+ * list.insertAfter(one, 2);
15
+ * list.toArray(); // => [1, 2, 3]
16
+ */
17
+ export declare class LinkedList<T> implements Iterable<T> {
18
+ #private;
19
+ constructor(items?: Iterable<T>);
20
+ /** Number of nodes. O(1). */
21
+ get size(): number;
22
+ /** First node. */
23
+ get head(): LinkedListNode<T> | undefined;
24
+ /** Last node. */
25
+ get tail(): LinkedListNode<T> | undefined;
26
+ /** True when empty. */
27
+ isEmpty(): boolean;
28
+ /** Appends `value`; returns its node. O(1). */
29
+ push(value: T): LinkedListNode<T>;
30
+ /** Prepends `value`; returns its node. O(1). */
31
+ unshift(value: T): LinkedListNode<T>;
32
+ /** Removes the last value. O(1). */
33
+ pop(): T | undefined;
34
+ /** Removes the first value. O(1). */
35
+ shift(): T | undefined;
36
+ /** Inserts `value` after `node` (which must belong to this list). O(1). */
37
+ insertAfter(node: LinkedListNode<T>, value: T): LinkedListNode<T>;
38
+ /** Inserts `value` before `node` (which must belong to this list). O(1). */
39
+ insertBefore(node: LinkedListNode<T>, value: T): LinkedListNode<T>;
40
+ /** Removes `node` (which must belong to this list); returns its value. O(1). */
41
+ remove(node: LinkedListNode<T>): T;
42
+ /** First node whose value satisfies `predicate`. O(n). */
43
+ find(predicate: (value: T) => boolean): LinkedListNode<T> | undefined;
44
+ /** Reverses the list in place. O(n). */
45
+ reverse(): this;
46
+ /** Removes every node (detached handles become invalid). O(n). */
47
+ clear(): void;
48
+ /** Values head to tail. O(n). */
49
+ toArray(): T[];
50
+ /** Iterates node handles head to tail. */
51
+ nodes(): Generator<LinkedListNode<T>>;
52
+ /** Iterates values head to tail. */
53
+ [Symbol.iterator](): Iterator<T>;
54
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{ValidationError as r}from"../error/index.js";class s{constructor(e,t){this.value=e;this.owner=t}value;prev=void 0;next=void 0;owner}class h{#e;#t;#n=0;constructor(e){if(e)for(const t of e)this.push(t)}get size(){return this.#n}get head(){return this.#e}get tail(){return this.#t}isEmpty(){return this.#n===0}push(e){const t=new s(e,this);return this.#i(this.#t,t),t}unshift(e){const t=new s(e,this);return this.#i(void 0,t),t}pop(){const e=this.#t;if(e)return this.#d(e),e.value}shift(){const e=this.#e;if(e)return this.#d(e),e.value}insertAfter(e,t){const n=this.#s(e),i=new s(t,this);return this.#i(n,i),i}insertBefore(e,t){const n=this.#s(e),i=new s(t,this);return this.#i(n.prev,i),i}remove(e){const t=this.#s(e);return this.#d(t),t.value}find(e){for(let t=this.#e;t;t=t.next)if(e(t.value))return t}reverse(){let e=this.#e;for(;e;){const t=e.next;e.next=e.prev,e.prev=t,e=t}return[this.#e,this.#t]=[this.#t,this.#e],this}clear(){for(let e=this.#e;e;){const t=e.next;e.owner=void 0,e.prev=e.next=void 0,e=t}this.#e=this.#t=void 0,this.#n=0}toArray(){return[...this]}*nodes(){for(let e=this.#e;e;e=e.next)yield e}*[Symbol.iterator](){for(let e=this.#e;e;e=e.next)yield e.value}#s(e){if(!(e instanceof s)||e.owner!==this)throw new r("HLP_DS_FOREIGN_NODE","The node does not belong to this list.");return e}#i(e,t){const n=e?e.next:this.#e;t.prev=e,t.next=n,e?e.next=t:this.#e=t,n?n.prev=t:this.#t=t,this.#n++}#d(e){e.prev?e.prev.next=e.next:this.#e=e.next,e.next?e.next.prev=e.prev:this.#t=e.prev,e.prev=e.next=void 0,e.owner=void 0,this.#n--}}export{h as LinkedList};
@@ -0,0 +1,89 @@
1
+ export interface MultiMapOptions {
2
+ /** Keep each value at most once per key (Set semantics, SameValueZero). Default false (array, duplicates kept). */
3
+ readonly unique?: boolean;
4
+ }
5
+ /**
6
+ * Map from a key to many values. `size` counts values; `keyCount` counts keys.
7
+ * Complexity: `add`, `get`, `has`, `delete` O(1); `hasEntry`, `deleteEntry` O(1) with `unique`, O(values of key) otherwise.
8
+ * @example
9
+ * const m = new MultiMap<string, number>();
10
+ * m.add('a', 1).add('a', 2).add('b', 3);
11
+ * m.get('a'); // => [1, 2]
12
+ * m.size; // => 3
13
+ */
14
+ export declare class MultiMap<K, V> implements Iterable<[K, V]> {
15
+ #private;
16
+ readonly unique: boolean;
17
+ constructor(entries?: Iterable<readonly [K, V]>, options?: MultiMapOptions);
18
+ /** Total number of values. O(1). */
19
+ get size(): number;
20
+ /** Number of keys. O(1). */
21
+ get keyCount(): number;
22
+ /** Adds `value` under `key` (ignored when `unique` and already present). */
23
+ add(key: K, value: V): this;
24
+ /** Values under `key` (a copy; empty when absent). */
25
+ get(key: K): V[];
26
+ /** True when `key` has at least one value. */
27
+ has(key: K): boolean;
28
+ /** True when `value` is stored under `key`. */
29
+ hasEntry(key: K, value: V): boolean;
30
+ /** Removes `key` and all its values. */
31
+ delete(key: K): boolean;
32
+ /** Removes one occurrence of `value` under `key`. */
33
+ deleteEntry(key: K, value: V): boolean;
34
+ /** Removes everything. */
35
+ clear(): void;
36
+ /** Keys in insertion order. */
37
+ keys(): IterableIterator<K>;
38
+ /** `[key, values]` groups in insertion order. */
39
+ groups(): Generator<[K, V[]]>;
40
+ /** Flattened `[key, value]` pairs. */
41
+ toArray(): [K, V][];
42
+ /** Iterates flattened `[key, value]` pairs. */
43
+ [Symbol.iterator](): Iterator<[K, V]>;
44
+ }
45
+ /**
46
+ * Two-way map with unique keys and unique values.
47
+ * Complexity: every operation O(1).
48
+ * @example
49
+ * const codes = new BiMap([['IN', 'India']]);
50
+ * codes.getKey('India'); // => 'IN'
51
+ * codes.set('FR', 'India'); // => throws HLP_DS_BIMAP_DUPLICATE_VALUE
52
+ */
53
+ export declare class BiMap<K, V> implements Iterable<[K, V]> {
54
+ #private;
55
+ constructor(entries?: Iterable<readonly [K, V]>);
56
+ /** Number of pairs. */
57
+ get size(): number;
58
+ /**
59
+ * Maps `key` to `value`, replacing the key's previous value. Throws `HLP_DS_BIMAP_DUPLICATE_VALUE`
60
+ * when `value` already belongs to another key (use `forceSet` to steal it).
61
+ */
62
+ set(key: K, value: V): this;
63
+ /** Maps `key` to `value`, removing any pair that used either. */
64
+ forceSet(key: K, value: V): this;
65
+ /** Value for `key`. */
66
+ get(key: K): V | undefined;
67
+ /** Key for `value`. */
68
+ getKey(value: V): K | undefined;
69
+ /** True when `key` exists. */
70
+ has(key: K): boolean;
71
+ /** True when `value` exists. */
72
+ hasValue(value: V): boolean;
73
+ /** Removes the pair with `key`. */
74
+ delete(key: K): boolean;
75
+ /** Removes the pair with `value`. */
76
+ deleteValue(value: V): boolean;
77
+ /** New `BiMap` with keys and values swapped. */
78
+ inverse(): BiMap<V, K>;
79
+ /** Removes every pair. */
80
+ clear(): void;
81
+ /** Keys in insertion order. */
82
+ keys(): IterableIterator<K>;
83
+ /** Values in insertion order. */
84
+ values(): IterableIterator<V>;
85
+ /** Pairs in insertion order. */
86
+ toArray(): [K, V][];
87
+ /** Iterates pairs in insertion order. */
88
+ [Symbol.iterator](): Iterator<[K, V]>;
89
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{ConflictError as n}from"../error/index.js";class h{unique;#e=new Map;#t=0;constructor(e,t={}){if(this.unique=t.unique??!1,e)for(const[r,s]of e)this.add(r,s)}get size(){return this.#t}get keyCount(){return this.#e.size}add(e,t){let r=this.#e.get(e);if(r||(r=this.unique?new Set:[],this.#e.set(e,r)),r instanceof Set){if(r.has(t))return this;r.add(t)}else r.push(t);return this.#t++,this}get(e){const t=this.#e.get(e);return t?[...t]:[]}has(e){return this.#e.has(e)}hasEntry(e,t){const r=this.#e.get(e);return r instanceof Set?r.has(t):r?.includes(t)??!1}delete(e){const t=this.#e.get(e);return t?(this.#t-=t instanceof Set?t.size:t.length,this.#e.delete(e)):!1}deleteEntry(e,t){const r=this.#e.get(e);if(!r)return!1;if(r instanceof Set){if(!r.delete(t))return!1}else{const s=r.indexOf(t);if(s<0)return!1;r.splice(s,1)}return this.#t--,(r instanceof Set?r.size:r.length)===0&&this.#e.delete(e),!0}clear(){this.#e.clear(),this.#t=0}keys(){return this.#e.keys()}*groups(){for(const[e,t]of this.#e)yield[e,[...t]]}toArray(){return[...this]}*[Symbol.iterator](){for(const[e,t]of this.#e)for(const r of t)yield[e,r]}}class i{#e=new Map;#t=new Map;constructor(e){if(e)for(const[t,r]of e)this.set(t,r)}get size(){return this.#e.size}set(e,t){const r=this.#t.get(t);if(this.#t.has(t)&&r!==e)throw new n("HLP_DS_BIMAP_DUPLICATE_VALUE","The value is already mapped to another key.");return this.forceSet(e,t)}forceSet(e,t){return this.delete(e),this.deleteValue(t),this.#e.set(e,t),this.#t.set(t,e),this}get(e){return this.#e.get(e)}getKey(e){return this.#t.get(e)}has(e){return this.#e.has(e)}hasValue(e){return this.#t.has(e)}delete(e){return this.#e.has(e)?(this.#t.delete(this.#e.get(e)),this.#e.delete(e),!0):!1}deleteValue(e){return this.#t.has(e)?(this.#e.delete(this.#t.get(e)),this.#t.delete(e),!0):!1}inverse(){return new i(this.#t)}clear(){this.#e.clear(),this.#t.clear()}keys(){return this.#e.keys()}values(){return this.#e.values()}toArray(){return[...this.#e]}[Symbol.iterator](){return this.#e.entries()}}export{i as BiMap,h as MultiMap};
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Double-ended queue on a growable ring buffer.
3
+ * Complexity: `push`, `pop`, `shift`, `unshift`, `at` O(1) amortized; iteration O(n).
4
+ * @example
5
+ * const d = new Deque<number>();
6
+ * d.push(2); d.unshift(1);
7
+ * d.shift(); // => 1
8
+ * d.pop(); // => 2
9
+ */
10
+ export declare class Deque<T> implements Iterable<T> {
11
+ #private;
12
+ constructor(items?: Iterable<T>);
13
+ /** Number of items. O(1). */
14
+ get size(): number;
15
+ /** True when empty. O(1). */
16
+ isEmpty(): boolean;
17
+ /** Adds to the back. O(1) amortized. */
18
+ push(item: T): this;
19
+ /** Adds to the front. O(1) amortized. */
20
+ unshift(item: T): this;
21
+ /** Removes from the back. O(1). */
22
+ pop(): T | undefined;
23
+ /** Removes from the front. O(1). */
24
+ shift(): T | undefined;
25
+ /** Front item. O(1). */
26
+ peekFront(): T | undefined;
27
+ /** Back item. O(1). */
28
+ peekBack(): T | undefined;
29
+ /** Item at `index` from the front; negative indexes count from the back. O(1). */
30
+ at(index: number): T | undefined;
31
+ /** Removes every item. O(1). */
32
+ clear(): void;
33
+ /** Items front to back. O(n). */
34
+ toArray(): T[];
35
+ /** Iterates front to back. */
36
+ [Symbol.iterator](): Iterator<T>;
37
+ }
38
+ /**
39
+ * FIFO queue on a growable ring buffer (no O(n) `Array#shift`).
40
+ * Complexity: `enqueue`, `dequeue`, `peek` O(1) amortized; iteration O(n).
41
+ * @example
42
+ * const q = new Queue(['a']);
43
+ * q.enqueue('b');
44
+ * q.dequeue(); // => 'a'
45
+ */
46
+ export declare class Queue<T> implements Iterable<T> {
47
+ #private;
48
+ constructor(items?: Iterable<T>);
49
+ /** Number of items. O(1). */
50
+ get size(): number;
51
+ /** True when empty. O(1). */
52
+ isEmpty(): boolean;
53
+ /** Adds to the back. O(1) amortized. */
54
+ enqueue(item: T): this;
55
+ /** Removes from the front. O(1). */
56
+ dequeue(): T | undefined;
57
+ /** Front item without removing it. O(1). */
58
+ peek(): T | undefined;
59
+ /** Removes every item. O(1). */
60
+ clear(): void;
61
+ /** Items front to back. O(n). */
62
+ toArray(): T[];
63
+ /** Iterates front to back without removing. */
64
+ [Symbol.iterator](): Iterator<T>;
65
+ }
66
+ /**
67
+ * Fixed-capacity buffer that overwrites the oldest item when full (logs, sliding windows, undo history).
68
+ * Complexity: `push`, `shift`, `pop`, `at` O(1); iteration O(n).
69
+ * @example
70
+ * const b = new CircularBuffer<number>(2);
71
+ * b.push(1); b.push(2); b.push(3); // evicts 1
72
+ * b.toArray(); // => [2, 3]
73
+ */
74
+ export declare class CircularBuffer<T> implements Iterable<T> {
75
+ #private;
76
+ constructor(capacity: number);
77
+ /** Maximum number of items. */
78
+ get capacity(): number;
79
+ /** Number of items. O(1). */
80
+ get size(): number;
81
+ /** True when `size === capacity`. */
82
+ isFull(): boolean;
83
+ /** True when empty. */
84
+ isEmpty(): boolean;
85
+ /** Appends `item`; when full, overwrites and returns the oldest item. O(1). */
86
+ push(item: T): T | undefined;
87
+ /** Removes and returns the oldest item. O(1). */
88
+ shift(): T | undefined;
89
+ /** Removes and returns the newest item. O(1). */
90
+ pop(): T | undefined;
91
+ /** Item at `index` (0 = oldest); negative indexes count from the newest. O(1). */
92
+ at(index: number): T | undefined;
93
+ /** Removes every item. O(capacity). */
94
+ clear(): void;
95
+ /** Items oldest to newest. O(n). */
96
+ toArray(): T[];
97
+ /** Iterates oldest to newest. */
98
+ [Symbol.iterator](): Iterator<T>;
99
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{ValidationError as r}from"../error/index.js";import{assertCapacity as u}from"./internal.js";const n=8;class h{buf=new Array(n);head=0;length=0;get mask(){return this.buf.length-1}grow(){const t=this.buf,e=new Array(t.length*2);for(let i=0;i<this.length;i++)e[i]=t[this.head+i&this.mask];this.buf=e,this.head=0}pushBack(t){this.length===this.buf.length&&this.grow(),this.buf[this.head+this.length&this.mask]=t,this.length++}pushFront(t){this.length===this.buf.length&&this.grow(),this.head=this.head-1&this.mask,this.buf[this.head]=t,this.length++}popFront(){if(this.length===0)return;const t=this.buf[this.head];return this.buf[this.head]=void 0,this.head=this.head+1&this.mask,this.length--,t}popBack(){if(this.length===0)return;const t=this.head+this.length-1&this.mask,e=this.buf[t];return this.buf[t]=void 0,this.length--,e}at(t){const e=t<0?this.length+t:t;if(!(!Number.isInteger(e)||e<0||e>=this.length))return this.buf[this.head+e&this.mask]}clear(){this.buf=new Array(n),this.head=0,this.length=0}*values(){for(let t=0;t<this.length;t++)yield this.buf[this.head+t&this.mask]}}class o{#t=new h;constructor(t){if(t)for(const e of t)this.#t.pushBack(e)}get size(){return this.#t.length}isEmpty(){return this.#t.length===0}push(t){return this.#t.pushBack(t),this}unshift(t){return this.#t.pushFront(t),this}pop(){return this.#t.popBack()}shift(){return this.#t.popFront()}peekFront(){return this.#t.at(0)}peekBack(){return this.#t.at(-1)}at(t){return this.#t.at(t)}clear(){this.#t.clear()}toArray(){return[...this.#t.values()]}[Symbol.iterator](){return this.#t.values()}}class l{#t=new h;constructor(t){if(t)for(const e of t)this.#t.pushBack(e)}get size(){return this.#t.length}isEmpty(){return this.#t.length===0}enqueue(t){return this.#t.pushBack(t),this}dequeue(){return this.#t.popFront()}peek(){return this.#t.at(0)}clear(){this.#t.clear()}toArray(){return[...this.#t.values()]}[Symbol.iterator](){return this.#t.values()}}class f{#t;#i=0;#e=0;constructor(t){if(u(t),t>2**30)throw new r("HLP_DS_INVALID_CAPACITY","Capacity is too large.");this.#t=new Array(t)}get capacity(){return this.#t.length}get size(){return this.#e}isFull(){return this.#e===this.#t.length}isEmpty(){return this.#e===0}push(t){const e=this.#t.length;if(this.#e<e){this.#t[(this.#i+this.#e)%e]=t,this.#e++;return}const i=this.#t[this.#i];return this.#t[this.#i]=t,this.#i=(this.#i+1)%e,i}shift(){if(this.#e===0)return;const t=this.#t[this.#i];return this.#t[this.#i]=void 0,this.#i=(this.#i+1)%this.#t.length,this.#e--,t}pop(){if(this.#e===0)return;const t=(this.#i+this.#e-1)%this.#t.length,e=this.#t[t];return this.#t[t]=void 0,this.#e--,e}at(t){const e=t<0?this.#e+t:t;if(!(!Number.isInteger(e)||e<0||e>=this.#e))return this.#t[(this.#i+e)%this.#t.length]}clear(){this.#t.fill(void 0),this.#i=0,this.#e=0}toArray(){return[...this]}*[Symbol.iterator](){for(let t=0;t<this.#e;t++)yield this.#t[(this.#i+t)%this.#t.length]}}export{f as CircularBuffer,o as Deque,l as Queue};
@@ -0,0 +1,104 @@
1
+ import { type Comparer } from './internal.js';
2
+ /** Bound inclusion for range queries: `'[]'` both ends (default), `'[)'`, `'(]'`, `'()'`. */
3
+ export type RangeBounds = '[]' | '[)' | '(]' | '()';
4
+ /**
5
+ * Map ordered by key on a balanced (AVL) tree with a custom comparer.
6
+ * Complexity: `get`, `set`, `has`, `delete`, `floor`, `ceiling`, `lower`, `higher`, `first`, `last` O(log n);
7
+ * `between` O(log n + k); full iteration O(n). Modifying the map while iterating throws
8
+ * `HLP_DS_CONCURRENT_MODIFICATION` (updating an existing key's value is allowed).
9
+ * @example
10
+ * const m = new SortedMap<number, string>([[3, 'c'], [1, 'a']]);
11
+ * m.set(2, 'b');
12
+ * [...m.keys()]; // => [1, 2, 3]
13
+ * m.floor(2.5); // => [2, 'b']
14
+ * [...m.between(2, 3)]; // => [[2, 'b'], [3, 'c']]
15
+ */
16
+ export declare class SortedMap<K, V> implements Iterable<[K, V]> {
17
+ #private;
18
+ constructor(entries?: Iterable<readonly [K, V]>, comparer?: Comparer<K>);
19
+ /** Number of entries. O(1). */
20
+ get size(): number;
21
+ /** Value for `key`. O(log n). */
22
+ get(key: K): V | undefined;
23
+ /** True when `key` is present. O(log n). */
24
+ has(key: K): boolean;
25
+ /** Inserts or replaces. O(log n). */
26
+ set(key: K, value: V): this;
27
+ /** Removes `key`. O(log n). */
28
+ delete(key: K): boolean;
29
+ /** Removes every entry. */
30
+ clear(): void;
31
+ /** Smallest entry. O(log n). */
32
+ first(): [K, V] | undefined;
33
+ /** Largest entry. O(log n). */
34
+ last(): [K, V] | undefined;
35
+ /** Greatest entry with key <= `key`. O(log n). */
36
+ floor(key: K): [K, V] | undefined;
37
+ /** Least entry with key >= `key`. O(log n). */
38
+ ceiling(key: K): [K, V] | undefined;
39
+ /** Greatest entry with key < `key`. O(log n). */
40
+ lower(key: K): [K, V] | undefined;
41
+ /** Least entry with key > `key`. O(log n). */
42
+ higher(key: K): [K, V] | undefined;
43
+ /** Removes and returns the smallest entry. O(log n). */
44
+ shift(): [K, V] | undefined;
45
+ /** Removes and returns the largest entry. O(log n). */
46
+ pop(): [K, V] | undefined;
47
+ /** Entries with `lo`..`hi` keys in ascending order. O(log n + k). */
48
+ between(lo: K, hi: K, bounds?: RangeBounds): Generator<[K, V]>;
49
+ /** Keys in ascending order. */
50
+ keys(): Generator<K>;
51
+ /** Values in ascending key order. */
52
+ values(): Generator<V>;
53
+ /** Entries in ascending key order. */
54
+ entries(): Generator<[K, V]>;
55
+ /** Entries in descending key order. */
56
+ reversed(): Generator<[K, V]>;
57
+ /** Entries in ascending key order. O(n). */
58
+ toArray(): [K, V][];
59
+ /** Iterates entries in ascending key order. */
60
+ [Symbol.iterator](): Generator<[K, V]>;
61
+ }
62
+ /**
63
+ * Set ordered by a custom comparer on a balanced (AVL) tree.
64
+ * Complexity: `add`, `has`, `delete`, `floor`, `ceiling`, `first`, `last` O(log n); `between` O(log n + k).
65
+ * @example
66
+ * const s = new SortedSet(['pear', 'apple']);
67
+ * s.add('fig');
68
+ * s.toArray(); // => ['apple', 'fig', 'pear']
69
+ * s.ceiling('b'); // => 'fig'
70
+ */
71
+ export declare class SortedSet<T> implements Iterable<T> {
72
+ #private;
73
+ constructor(items?: Iterable<T>, comparer?: Comparer<T>);
74
+ /** Number of items. O(1). */
75
+ get size(): number;
76
+ /** Adds `item` (no-op when an equal item exists). O(log n). */
77
+ add(item: T): this;
78
+ /** True when an equal item exists. O(log n). */
79
+ has(item: T): boolean;
80
+ /** Removes `item`. O(log n). */
81
+ delete(item: T): boolean;
82
+ /** Removes every item. */
83
+ clear(): void;
84
+ /** Smallest item. O(log n). */
85
+ first(): T | undefined;
86
+ /** Largest item. O(log n). */
87
+ last(): T | undefined;
88
+ /** Greatest item <= `item`. O(log n). */
89
+ floor(item: T): T | undefined;
90
+ /** Least item >= `item`. O(log n). */
91
+ ceiling(item: T): T | undefined;
92
+ /** Greatest item < `item`. O(log n). */
93
+ lower(item: T): T | undefined;
94
+ /** Least item > `item`. O(log n). */
95
+ higher(item: T): T | undefined;
96
+ /** Items between `lo` and `hi` in ascending order. O(log n + k). */
97
+ between(lo: T, hi: T, bounds?: RangeBounds): Generator<T>;
98
+ /** Items in descending order. */
99
+ reversed(): Generator<T>;
100
+ /** Items in ascending order. O(n). */
101
+ toArray(): T[];
102
+ /** Iterates items in ascending order. */
103
+ [Symbol.iterator](): Generator<T>;
104
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ import{AvlTree as a}from"./avl.js";import{naturalCompare as f}from"./internal.js";class c{#e;constructor(e,n=f){if(this.#e=new a(n),e)for(const[t,o]of e)this.#e.insert(t,o)}get size(){return this.#e.size}get(e){return this.#e.find(e)?.value}has(e){return this.#e.find(e)!==void 0}set(e,n){return this.#e.insert(e,n),this}delete(e){return this.#e.delete(e)!==void 0}clear(){this.#e.clear()}first(){return i(this.#e.min())}last(){return i(this.#e.max())}floor(e){return i(this.#e.below(e,!0))}ceiling(e){return i(this.#e.above(e,!0))}lower(e){return i(this.#e.below(e,!1))}higher(e){return i(this.#e.above(e,!1))}shift(){const e=this.#e.min();if(e)return this.#e.delete(e.key),[e.key,e.value]}pop(){const e=this.#e.max();if(e)return this.#e.delete(e.key),[e.key,e.value]}*between(e,n,t="[]"){const o=this.#e.cmp,u=t.endsWith(")");for(const r of this.#e.ascending({key:e,exclusive:t.startsWith("(")})){const d=o(r.key,n);if(d>0||d===0&&u)return;yield[r.key,r.value]}}*keys(){for(const e of this.#e.ascending())yield e.key}*values(){for(const e of this.#e.ascending())yield e.value}entries(){return this[Symbol.iterator]()}*reversed(){for(const e of this.#e.descending())yield[e.key,e.value]}toArray(){return[...this]}*[Symbol.iterator](){for(const e of this.#e.ascending())yield[e.key,e.value]}}function i(s){return s?[s.key,s.value]:void 0}class y{#e;constructor(e,n=f){if(this.#e=new a(n),e)for(const t of e)this.#e.insert(t,void 0)}get size(){return this.#e.size}add(e){return this.#e.find(e)||this.#e.insert(e,void 0),this}has(e){return this.#e.find(e)!==void 0}delete(e){return this.#e.delete(e)!==void 0}clear(){this.#e.clear()}first(){return this.#e.min()?.key}last(){return this.#e.max()?.key}floor(e){return this.#e.below(e,!0)?.key}ceiling(e){return this.#e.above(e,!0)?.key}lower(e){return this.#e.below(e,!1)?.key}higher(e){return this.#e.above(e,!1)?.key}*between(e,n,t="[]"){const o=this.#e.cmp,u=t.endsWith(")");for(const r of this.#e.ascending({key:e,exclusive:t.startsWith("(")})){const d=o(r.key,n);if(d>0||d===0&&u)return;yield r.key}}*reversed(){for(const e of this.#e.descending())yield e.key}toArray(){return[...this]}*[Symbol.iterator](){for(const e of this.#e.ascending())yield e.key}}export{c as SortedMap,y as SortedSet};
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Array-backed LIFO stack.
3
+ * Complexity: `push`, `pop`, `peek` O(1) amortized; iteration O(n).
4
+ * @example
5
+ * const s = new Stack([1, 2]);
6
+ * s.push(3);
7
+ * s.pop(); // => 3
8
+ */
9
+ export declare class Stack<T> implements Iterable<T> {
10
+ #private;
11
+ constructor(items?: Iterable<T>);
12
+ /** Number of items. O(1). */
13
+ get size(): number;
14
+ /** True when empty. O(1). */
15
+ isEmpty(): boolean;
16
+ /** Pushes `item` on top. O(1) amortized. */
17
+ push(item: T): this;
18
+ /** Removes and returns the top item. O(1). */
19
+ pop(): T | undefined;
20
+ /** Returns the top item without removing it. O(1). */
21
+ peek(): T | undefined;
22
+ /** Removes every item. O(1). */
23
+ clear(): void;
24
+ /** Items in pop order (top first). O(n). */
25
+ toArray(): T[];
26
+ /** Iterates in pop order (top first) without removing. */
27
+ [Symbol.iterator](): Iterator<T>;
28
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ class s{#t=[];constructor(t){if(t)for(const e of t)this.#t.push(e)}get size(){return this.#t.length}isEmpty(){return this.#t.length===0}push(t){return this.#t.push(t),this}pop(){return this.#t.pop()}peek(){return this.#t[this.#t.length-1]}clear(){this.#t=[]}toArray(){return this.#t.slice().reverse()}*[Symbol.iterator](){for(let t=this.#t.length-1;t>=0;t--)yield this.#t[t]}}export{s as Stack};
@@ -0,0 +1,84 @@
1
+ export interface TrieOptions {
2
+ /** Fold case for matching (`'default'` uses `toLowerCase`; a locale uses `toLocaleLowerCase`). Default: exact. */
3
+ readonly caseFold?: boolean | string;
4
+ }
5
+ /**
6
+ * Prefix tree mapping string keys to values. Walks by code point (surrogate-pair safe); every
7
+ * operation is iterative, so very long keys cannot overflow the stack.
8
+ * Complexity (m = key length, k = results): `set`, `get`, `has`, `delete`, `hasPrefix`, `countPrefix` O(m);
9
+ * `entriesWithPrefix` O(m + subtree size) with children visited in code-unit order.
10
+ * @example
11
+ * const t = new TrieMap<number>(undefined, { caseFold: true });
12
+ * t.set('Apple', 1).set('apricot', 2);
13
+ * t.get('APPLE'); // => 1
14
+ * t.keysWithPrefix('ap'); // => ['Apple', 'apricot']
15
+ */
16
+ export declare class TrieMap<V> implements Iterable<[string, V]> {
17
+ #private;
18
+ constructor(entries?: Iterable<readonly [string, V]>, options?: TrieOptions);
19
+ /** Number of keys. O(1). */
20
+ get size(): number;
21
+ /** Inserts or replaces `key`. The latest spelling is kept when case folding. O(m). */
22
+ set(key: string, value: V): this;
23
+ /** Value for `key`. O(m). */
24
+ get(key: string): V | undefined;
25
+ /** True when `key` is stored. O(m). */
26
+ has(key: string): boolean;
27
+ /** Removes `key`, pruning empty branches. O(m). */
28
+ delete(key: string): boolean;
29
+ /** True when any key starts with `prefix` (the empty prefix matches any non-empty trie). O(m). */
30
+ hasPrefix(prefix: string): boolean;
31
+ /** Number of keys starting with `prefix`. O(m). */
32
+ countPrefix(prefix: string): number;
33
+ /** Entries whose key starts with `prefix`, in code-unit order, at most `limit`. */
34
+ entriesWithPrefix(prefix: string, limit?: number): [string, V][];
35
+ /** Keys starting with `prefix`, in code-unit order, at most `limit`. */
36
+ keysWithPrefix(prefix: string, limit?: number): string[];
37
+ /** Longest prefix shared by every stored key (folded form). O(length of the prefix). */
38
+ longestCommonPrefix(): string;
39
+ /** Longest stored key that is a prefix of `text` (tokenizers, routing). O(length of text). */
40
+ longestPrefixOf(text: string): string | undefined;
41
+ /** Removes every key. */
42
+ clear(): void;
43
+ /** All entries in code-unit order. O(n). */
44
+ toArray(): [string, V][];
45
+ /** Iterates all entries in code-unit order. */
46
+ [Symbol.iterator](): Iterator<[string, V]>;
47
+ }
48
+ /**
49
+ * Set of strings as a prefix tree (autocomplete, prefix checks).
50
+ * Complexity as `TrieMap`.
51
+ * @example
52
+ * const t = new Trie(['car', 'cart', 'cat']);
53
+ * t.startsWith('ca'); // => true
54
+ * t.findByPrefix('car'); // => ['car', 'cart']
55
+ * t.longestCommonPrefix(); // => 'ca'
56
+ */
57
+ export declare class Trie implements Iterable<string> {
58
+ #private;
59
+ constructor(words?: Iterable<string>, options?: TrieOptions);
60
+ /** Number of words. O(1). */
61
+ get size(): number;
62
+ /** Adds `word`. O(m). */
63
+ insert(word: string): this;
64
+ /** True when `word` is stored. O(m). */
65
+ has(word: string): boolean;
66
+ /** Removes `word`. O(m). */
67
+ delete(word: string): boolean;
68
+ /** True when any word starts with `prefix`. O(m). */
69
+ startsWith(prefix: string): boolean;
70
+ /** Words starting with `prefix` in code-unit order, at most `limit`. */
71
+ findByPrefix(prefix: string, limit?: number): string[];
72
+ /** Number of words starting with `prefix`. O(m). */
73
+ countPrefix(prefix: string): number;
74
+ /** Longest prefix shared by every word. */
75
+ longestCommonPrefix(): string;
76
+ /** Longest stored word that prefixes `text`. */
77
+ longestPrefixOf(text: string): string | undefined;
78
+ /** Removes every word. */
79
+ clear(): void;
80
+ /** Words in code-unit order. */
81
+ toArray(): string[];
82
+ /** Iterates words in code-unit order. */
83
+ [Symbol.iterator](): Iterator<string>;
84
+ }
@@ -0,0 +1,2 @@
1
+ /*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
2
+ const f=()=>({children:void 0,entry:void 0,count:0});class c{#e=f();#t;constructor(e,t={}){const n=t.caseFold;if(this.#t=n===void 0||n===!1?r=>r:n===!0?r=>r.toLowerCase():r=>r.toLocaleLowerCase(n),e)for(const[r,s]of e)this.set(r,s)}get size(){return this.#e.count}set(e,t){const n=[this.#e];let r=this.#e;for(const i of this.#t(e)){r.children??=new Map;let o=r.children.get(i);o||(o=f(),r.children.set(i,o)),r=o,n.push(r)}const s=r.entry===void 0;if(r.entry={key:e,value:t},s)for(const i of n)i.count++;return this}get(e){return this.#r(this.#t(e))?.entry?.value}has(e){return this.#r(this.#t(e))?.entry!==void 0}delete(e){const t=[];let n=this.#e;for(const r of this.#t(e)){const s=n.children?.get(r);if(!s)return!1;t.push([n,r]),n=s}if(n.entry===void 0)return!1;n.entry=void 0;for(const[r]of t)r.count--;n.count--;for(const[r,s]of t.reverse()){const i=r.children?.get(s);if(!i||i.count>0)break;r.children?.delete(s),r.children?.size===0&&(r.children=void 0)}return!0}hasPrefix(e){return(this.#r(this.#t(e))?.count??0)>0}countPrefix(e){return this.#r(this.#t(e))?.count??0}entriesWithPrefix(e,t=1/0){const n=[],r=this.#r(this.#t(e));if(!r||t<=0)return n;const s=[r];for(let i=s.pop();i&&!(i.entry&&(n.push([i.entry.key,i.entry.value]),n.length>=t));i=s.pop())if(i.children){const o=[...i.children.keys()].sort().reverse();for(const u of o){const d=i.children.get(u);d&&s.push(d)}}return n}keysWithPrefix(e,t=1/0){return this.entriesWithPrefix(e,t).map(([n])=>n)}longestCommonPrefix(){if(this.#e.count===0)return"";let e="",t=this.#e;for(;!t.entry&&t.children?.size===1;){const n=t.children.entries().next();if(n.done)break;const[r,s]=n.value;e+=r,t=s}return e}longestPrefixOf(e){let t=this.#e,n=t.entry?.key;for(const r of this.#t(e)){if(t=t.children?.get(r),!t)break;t.entry&&(n=t.entry.key)}return n}clear(){this.#e=f()}toArray(){return this.entriesWithPrefix("")}[Symbol.iterator](){return this.toArray()[Symbol.iterator]()}#r(e){let t=this.#e;for(const n of e)if(t=t.children?.get(n),!t)return;return t}}class l{#e;constructor(e,t={}){if(this.#e=new c(void 0,t),e)for(const n of e)this.#e.set(n,!0)}get size(){return this.#e.size}insert(e){return this.#e.set(e,!0),this}has(e){return this.#e.has(e)}delete(e){return this.#e.delete(e)}startsWith(e){return this.#e.hasPrefix(e)}findByPrefix(e,t=1/0){return this.#e.keysWithPrefix(e,t)}countPrefix(e){return this.#e.countPrefix(e)}longestCommonPrefix(){return this.#e.longestCommonPrefix()}longestPrefixOf(e){return this.#e.longestPrefixOf(e)}clear(){this.#e.clear()}toArray(){return this.#e.keysWithPrefix("")}[Symbol.iterator](){return this.toArray()[Symbol.iterator]()}}export{l as Trie,c as TrieMap};