elseware-nodejs 1.0.10 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1713 -1
- package/dist/index.d.ts +1713 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1 +1,103 @@
|
|
|
1
|
-
# elseware-nodejs
|
|
1
|
+
# elseware-nodejs
|
|
2
|
+
|
|
3
|
+
## Data Stuctures
|
|
4
|
+
```
|
|
5
|
+
data-structures/
|
|
6
|
+
├── array/
|
|
7
|
+
│ ├── StaticArray.ts ✅
|
|
8
|
+
│ ├── DynamicArray.ts ✅
|
|
9
|
+
│ └── CircularArray.ts ✅
|
|
10
|
+
│
|
|
11
|
+
├── linked-list/
|
|
12
|
+
│ ├── SinglyLinkedList.ts ✅
|
|
13
|
+
│ ├── DoublyLinkedList.ts ✅
|
|
14
|
+
│ └── CircularLinkedList.ts ✅
|
|
15
|
+
│
|
|
16
|
+
├── stack/
|
|
17
|
+
│ ├── Stack.ts ✅
|
|
18
|
+
│ ├── MinStack.ts ✅
|
|
19
|
+
│ └── MaxStack.ts ✅
|
|
20
|
+
│
|
|
21
|
+
├── queue/
|
|
22
|
+
│ ├── Queue.ts ✅
|
|
23
|
+
│ ├── CircularQueue.ts ✅
|
|
24
|
+
│ ├── Deque.ts ✅
|
|
25
|
+
│ └── PriorityQueue.ts ✅
|
|
26
|
+
│
|
|
27
|
+
├── hash/
|
|
28
|
+
│ ├── HashMap.ts ✅
|
|
29
|
+
│ ├── HashSet.ts ✅
|
|
30
|
+
│ ├── LRUCache.ts ✅
|
|
31
|
+
│ ├── LFUCache.ts ✅
|
|
32
|
+
│ └── ConsistentHash.ts ✅
|
|
33
|
+
│
|
|
34
|
+
├── tree/
|
|
35
|
+
│ ├── binary/
|
|
36
|
+
│ │ ├── BinaryTree.ts ✅
|
|
37
|
+
│ │ └── BinarySearchTree.ts ✅
|
|
38
|
+
│ │
|
|
39
|
+
│ ├── balanced/
|
|
40
|
+
│ │ ├── AVLTree.ts ✅
|
|
41
|
+
│ │ ├── RedBlackTree.ts ✅
|
|
42
|
+
│ │ └── SplayTree.ts ✅
|
|
43
|
+
│ │
|
|
44
|
+
│ ├── prefix/
|
|
45
|
+
│ │ ├── Trie.ts ✅
|
|
46
|
+
│ │ ├── RadixTree.ts ✅
|
|
47
|
+
│ │ └── TernarySearchTree.ts ✅
|
|
48
|
+
│ │
|
|
49
|
+
│ ├── multiway/
|
|
50
|
+
│ │ ├── BTree.ts ✅
|
|
51
|
+
│ │ └── BPlusTree.ts ✅
|
|
52
|
+
│ │
|
|
53
|
+
│ └── range/
|
|
54
|
+
│ ├── SegmentTree.ts ✅
|
|
55
|
+
│ ├── FenwickTree.ts ✅
|
|
56
|
+
│ └── IntervalTree.ts ✅
|
|
57
|
+
│
|
|
58
|
+
├── heap/
|
|
59
|
+
│ ├── BinaryHeap.ts ✅
|
|
60
|
+
│ ├── MinHeap.ts ✅
|
|
61
|
+
│ ├── MaxHeap.ts ✅
|
|
62
|
+
│ ├── FibonacciHeap.ts ✅
|
|
63
|
+
│ └── PairingHeap.ts ✅
|
|
64
|
+
│
|
|
65
|
+
├── graph/
|
|
66
|
+
│ ├── Graph.ts ✅
|
|
67
|
+
│ ├── DirectedGraph.ts ✅
|
|
68
|
+
│ ├── AdjacencyList.ts ✅
|
|
69
|
+
│ └── AdjacencyMatrix.ts ✅
|
|
70
|
+
│
|
|
71
|
+
├── set/
|
|
72
|
+
│ ├── Set.ts ✅
|
|
73
|
+
│ ├── OrderedSet.ts ✅
|
|
74
|
+
│ ├── MultiSet.ts ✅
|
|
75
|
+
│ └── DisjointSetUnion.ts ✅
|
|
76
|
+
│
|
|
77
|
+
├── string/
|
|
78
|
+
│ ├── SuffixArray.ts ✅
|
|
79
|
+
│ └── SuffixTree.ts ✅
|
|
80
|
+
│
|
|
81
|
+
├── spatial/
|
|
82
|
+
│ ├── KDTree.ts ✅
|
|
83
|
+
│ └── QuadTree.ts ✅
|
|
84
|
+
│
|
|
85
|
+
├── probabilistic/
|
|
86
|
+
│ ├── BloomFilter.ts ✅
|
|
87
|
+
│ ├── CountMinSketch.ts ✅
|
|
88
|
+
│ └── HyperLogLog.ts ✅
|
|
89
|
+
│
|
|
90
|
+
├── table/
|
|
91
|
+
│ └── SparseTable.ts ✅
|
|
92
|
+
│
|
|
93
|
+
├── union-find/
|
|
94
|
+
│ └── UnionFind.ts ✅
|
|
95
|
+
│
|
|
96
|
+
└── interfaces/
|
|
97
|
+
├── ICollection.ts
|
|
98
|
+
├── IStack.ts
|
|
99
|
+
├── IQueue.ts
|
|
100
|
+
├── ITree.ts
|
|
101
|
+
├── IGraph.ts
|
|
102
|
+
└── IHeap.ts
|
|
103
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
${
|
|
3
|
-
${w(t)}`):this.output(`\u274C ${e}`);}log(e){this.output(`\u2022 ${e}`);}},u=new h;async function W(r){try{y__default.default.set("strictQuery",!0),await y__default.default.connect(r.uri),u.success("Database connected successfully"),process.on("SIGINT",async()=>{await y__default.default.connection.close(),u.success("Database connection closed"),process.exit(0);});}catch(e){u.danger("Database connection failed"),e instanceof Error&&u.danger(e.message),process.exit(1);}}b__default.default.config();function Y(r){let{value:e,error:t}=r.validate(process.env,{abortEarly:false,allowUnknown:true});if(t)throw new Error(`\u274C Env validation error: ${t.message}`);return u.success("Configurations passed"),e}function O(r={}){let{origins:e,defaults:t=["http://localhost:3000"]}=r,o=[];return typeof e=="string"&&(o=e.split(",").map(n=>n.trim()).filter(Boolean)),Array.isArray(e)&&(o=e.map(n=>n.trim()).filter(Boolean)),o.length===0&&(o=[...t]),o}function T(r){return {origin(e,t){return !e||r.includes(e)?t(null,true):t(new Error(`CORS blocked: ${e} is not allowed`))},credentials:true,methods:["GET","POST","PUT","PATCH","DELETE","OPTIONS"],allowedHeaders:["Content-Type","Authorization","X-Requested-With","Accept"],exposedHeaders:["Set-Cookie"],optionsSuccessStatus:204}}var me=(r,e,t)=>{t();};var E=r=>new i(`Invalid ${r.path}: ${r.value}`,400,{code:"INVALID_ID"}),R=r=>{let e=r.keyValue?JSON.stringify(r.keyValue):"duplicate value";return new i(`Duplicate field value: ${e}`,400,{code:"DUPLICATE_FIELD"})},q=r=>{let e=Object.values(r.errors).map(t=>t.message);return new i("Invalid input data",400,{code:"VALIDATION_ERROR",details:e})},k=()=>new i("Invalid token. Please log in again.",401),A=()=>new i("Your token has expired. Please log in again.",401),we=(r=false)=>(e,t,o,n)=>{let s;return e instanceof i?s=e:e instanceof Error?(s=new i(e.message,500),s.isOperational=false):(s=new i("Internal Server Error",500),s.isOperational=false),e&&e.name==="CastError"&&(s=E(e)),e&&typeof e=="object"&&e.code===11e3&&(s=R(e)),e&&e.name==="ValidationError"&&(s=q(e)),e?.name==="JsonWebTokenError"&&(s=k()),e?.name==="TokenExpiredError"&&(s=A()),s.isOperational?u.danger("Operational error",{message:s.message}):u.danger("Programming error",e),r?a.send(o,{success:false,statusCode:s.statusCode,message:s.isOperational?s.message:"Something went wrong"}):a.send(o,{success:false,statusCode:s.statusCode,message:s.message,data:{stack:e?.stack,details:s.details}})};var be=r=>(e,t,o)=>{let{error:n}=r.validate(e.body);if(n)return o(n);o();};var x=class{model;resourceName;constructor(e,t){this.model=e,this.resourceName=t;}async create(e){return await this.model.create(e)}async findAll(){return this.model.find()}async findById(e){let t=await this.model.findById(e);if(!t)throw new i(`${this.resourceName} not found`,404,{code:`${this.resourceName.toUpperCase()}_NOT_FOUND`});return t}async updateById(e,t){let o=await this.model.findByIdAndUpdate(e,t,{new:true,runValidators:true});if(!o)throw new i(`${this.resourceName} not found`,404,{code:`${this.resourceName.toUpperCase()}_NOT_FOUND`});return o}async deleteById(e){let t=await this.model.findByIdAndDelete(e);if(!t)throw new i(`${this.resourceName} not found`,404,{code:`${this.resourceName.toUpperCase()}_NOT_FOUND`});return t}};function Ce(r){return r}function Pe(r){return r*1e3}function Fe(r){return r*6e4}function Ie(r){return r*36e5}function $e(r){return r*864e5}function De(r){return r/1e3}function Me(r){return r/6e4}function Ue(r){return r/36e5}function Be(r){return new Promise(e=>setTimeout(e,r))}
|
|
4
|
-
exports.APIFactory=
|
|
1
|
+
'use strict';var storageBlob=require('@azure/storage-blob'),M=require('fs'),P=require('mongoose'),_t=require('dotenv');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var M__default=/*#__PURE__*/_interopDefault(M);var P__default=/*#__PURE__*/_interopDefault(P);var _t__default=/*#__PURE__*/_interopDefault(_t);var l=class extends Error{statusCode;status;isOperational;code;details;constructor(t,e=500,r){super(t),this.statusCode=e,this.status=`${e}`.startsWith("4")?"fail":"error",this.isOperational=true,this.code=r?.code,this.details=r?.details,Error.captureStackTrace(this,this.constructor);}};var d=class n{static send(t,e){let{statusCode:r=200,success:i=true,message:s="Success",data:o,meta:a}=e;if(r===204)return t.status(204).send();let h={success:i,message:s};return o!==void 0&&(h.data=o),a!==void 0&&(h.meta=a),t.status(r).json(h)}static ok(t,e,r,i){return n.send(t,{statusCode:200,data:e,message:r,meta:i})}static created(t,e,r){return n.send(t,{statusCode:201,data:e,message:r})}static noContent(t){return n.send(t,{statusCode:204})}static error(t,e,r=500){return n.send(t,{success:false,statusCode:r,message:e})}};var m=n=>(t,e,r)=>Promise.resolve(n(t,e,r)).catch(r);var R=class{query;queryString;page;limit;constructor(t,e){this.query=t,this.queryString=e,this.page=1,this.limit=100;}filter(){let t={...this.queryString};["page","sort","limit","fields"].forEach(r=>delete t[r]);let e=JSON.stringify(t);return e=e.replace(/\b(gte|gt|lte|lt|in)\b/g,r=>`$${r}`),this.query=this.query.find(JSON.parse(e)),this}sort(){if(this.queryString.sort){let t=String(this.queryString.sort).split(",").join(" ");this.query=this.query.sort(t);}else this.query=this.query.sort("-createdAt");return this}limitFields(){if(this.queryString.fields){let t=String(this.queryString.fields).split(",").join(" ");this.query=this.query.select(t);}else this.query=this.query.select("-__v");return this}paginate(){this.page=Number(this.queryString.page)||1,this.limit=Number(this.queryString.limit)||100;let t=(this.page-1)*this.limit;return this.query=this.query.skip(t).limit(this.limit),this}populate(t){return t&&(this.query=this.query.populate(t)),this}},L=R;var B=class{static getAll(t,e={}){return m(async(r,i)=>{let s=e.filter?e.filter(r):{},o=new L(t.find(s),r.query).filter().sort().limitFields().paginate().populate(e.populate),a=await o.query;d.ok(i,a,e.message??"Records fetched successfully",{count:a.length,page:o.page,limit:o.limit});})}static getOne(t,e={}){return m(async(r,i)=>{let s=t.findById(r.params.id);e.populate&&(s=s.populate(e.populate));let o=await s;if(!o)throw new l(e.notFoundMessage??"Resource not found",404,{code:"RESOURCE_NOT_FOUND"});d.ok(i,o);})}static createOne(t,e={}){return m(async(r,i)=>{let s=await t.create(r.body);d.created(i,s,e.message??"Resource created successfully");})}static updateOne(t,e={}){return m(async(r,i)=>{let s=await t.findByIdAndUpdate(r.params.id,r.body,{new:true,runValidators:true});if(!s)throw new l(e.notFoundMessage??"Resource not found",404);d.ok(i,s,e.message??"Resource updated successfully");})}static deleteOne(t,e={}){return m(async(r,i)=>{if(!await t.findByIdAndDelete(r.params.id))throw new l(e.notFoundMessage??"Resource not found",404);d.noContent(i);})}};var W=class{containerName;blobServiceClient;containerClient;sharedKeyCredential;constructor(t){let{connectionString:e,accountName:r,accountKey:i,containerName:s}=t;this.containerName=s,this.blobServiceClient=storageBlob.BlobServiceClient.fromConnectionString(e),this.containerClient=this.blobServiceClient.getContainerClient(s),this.sharedKeyCredential=new storageBlob.StorageSharedKeyCredential(r,i);}async uploadFile(t,e,r){let i=this.containerClient.getBlockBlobClient(e),s=M__default.default.statSync(t).size,o=M__default.default.createReadStream(t);return await i.uploadStream(o,4*1024*1024,20,{onProgress:a=>{if(r){let h=(a.loadedBytes/s*100).toFixed(2);r(h);}}}),i.url}async downloadFile(t,e,r){let s=await this.containerClient.getBlobClient(t).download(),o=s.contentLength||0,a=0;return new Promise((h,u)=>{let c=M__default.default.createWriteStream(e);s.readableStreamBody?.on("data",T=>{if(a+=T.length,r&&o>0){let Ht=(a/o*100).toFixed(2);r(Ht);}}),s.readableStreamBody?.pipe(c),c.on("finish",h),c.on("error",u);})}async deleteFile(t){return await this.containerClient.getBlobClient(t).deleteIfExists(),true}async listFiles(t=""){let e=[];for await(let r of this.containerClient.listBlobsFlat({prefix:t}))e.push(r.name);return e}async blobExists(t){return this.containerClient.getBlobClient(t).exists()}};function U(n){if(n instanceof Error)return `${n.name}: ${n.message}
|
|
2
|
+
${n.stack??""}`;if(typeof n=="object")try{return JSON.stringify(n,null,2)}catch{return "[Unserializable object]"}return String(n)}var I=class{timestamp=true;enabled=true;configure(t={}){this.timestamp=t.timestamp??this.timestamp,this.enabled=t.enabled??this.enabled;}format(t){return this.timestamp?`[${new Date().toISOString()}] ${t}`:t}output(t){this.enabled&&console.log(this.format(t));}success(t){this.output(`\u2705 ${t}`);}info(t){this.output(`\u2139\uFE0F ${t}`);}warning(t){this.output(`\u26A0\uFE0F ${t}`);}danger(t,e){e?this.output(`\u274C ${t}
|
|
3
|
+
${U(e)}`):this.output(`\u274C ${t}`);}log(t){this.output(`\u2022 ${t}`);}},f=new I;async function Re(n){try{P__default.default.set("strictQuery",!0),await P__default.default.connect(n.uri),f.success("Database connected successfully"),process.on("SIGINT",async()=>{await P__default.default.connection.close(),f.success("Database connection closed"),process.exit(0);});}catch(t){f.danger("Database connection failed"),t instanceof Error&&f.danger(t.message),process.exit(1);}}_t__default.default.config({quiet:true});function Ie(n){let{value:t,error:e}=n.validate(process.env,{abortEarly:false,allowUnknown:true});if(e)throw new Error(`\u274C Env validation error: ${e.message}`);return f.success("Configurations passed"),t}function Qt(n={}){let{origins:t,defaults:e=["http://localhost:3000"]}=n,r=[];return typeof t=="string"&&(r=t.split(",").map(i=>i.trim()).filter(Boolean)),Array.isArray(t)&&(r=t.map(i=>i.trim()).filter(Boolean)),r.length===0&&(r=[...e]),r}function Jt(n){return {origin(t,e){return !t||n.includes(t)?e(null,true):e(new Error(`CORS blocked: ${t} is not allowed`))},credentials:true,methods:["GET","POST","PUT","PATCH","DELETE","OPTIONS"],allowedHeaders:["Content-Type","Authorization","X-Requested-With","Accept"],exposedHeaders:["Set-Cookie"],optionsSuccessStatus:204}}var _=class{capacity;data;head;tail;length;constructor(t){if(!Number.isInteger(t)||t<=0)throw new Error("CircularArray capacity must be a positive integer");this.capacity=t,this.data=new Array(t),this.head=0,this.tail=0,this.length=0;}size(){return this.length}getCapacity(){return this.capacity}isEmpty(){return this.length===0}isFull(){return this.length===this.capacity}enqueue(t){if(this.isFull())throw new Error("CircularArray is full");this.data[this.tail]=t,this.tail=(this.tail+1)%this.capacity,this.length++;}dequeue(){if(this.isEmpty())return;let t=this.data[this.head];return this.data[this.head]=void 0,this.head=(this.head+1)%this.capacity,this.length--,t}peek(){return this.isEmpty()?void 0:this.data[this.head]}clear(){this.data=new Array(this.capacity),this.head=0,this.tail=0,this.length=0;}toArray(){let t=[];for(let e=0;e<this.length;e++){let r=(this.head+e)%this.capacity;t.push(this.data[r]);}return t}*[Symbol.iterator](){for(let t=0;t<this.length;t++){let e=(this.head+t)%this.capacity;yield this.data[e];}}toString(){return `CircularArray(size=${this.length}, capacity=${this.capacity}) [${this.toArray().join(", ")}]`}};var Q=class{data;capacity;length;constructor(t=4){if(!Number.isInteger(t)||t<=0)throw new Error("Initial capacity must be a positive integer");this.capacity=t,this.length=0,this.data=new Array(this.capacity);}size(){return this.length}getCapacity(){return this.capacity}checkBounds(t){if(!Number.isInteger(t))throw new Error("Index must be an integer");if(t<0||t>=this.length)throw new RangeError(`Index ${t} out of bounds (0 - ${this.length-1})`)}resize(t){let e=new Array(t);for(let r=0;r<this.length;r++)e[r]=this.data[r];this.data=e,this.capacity=t;}get(t){return this.checkBounds(t),this.data[t]}set(t,e){this.checkBounds(t),this.data[t]=e;}push(t){this.length===this.capacity&&this.resize(this.capacity*2),this.data[this.length]=t,this.length++;}pop(){if(this.length===0)return;let t=this.data[this.length-1];return this.data[this.length-1]=void 0,this.length--,this.length>0&&this.length<=this.capacity/4&&this.resize(Math.max(4,Math.floor(this.capacity/2))),t}insert(t,e){if(t<0||t>this.length)throw new RangeError(`Index ${t} out of bounds`);this.length===this.capacity&&this.resize(this.capacity*2);for(let r=this.length;r>t;r--)this.data[r]=this.data[r-1];this.data[t]=e,this.length++;}removeAt(t){this.checkBounds(t);let e=this.data[t];for(let r=t;r<this.length-1;r++)this.data[r]=this.data[r+1];return this.data[this.length-1]=void 0,this.length--,e}contains(t){for(let e=0;e<this.length;e++)if(this.data[e]===t)return true;return false}toArray(){return this.data.slice(0,this.length)}clear(){this.data=new Array(this.capacity),this.length=0;}*[Symbol.iterator](){for(let t=0;t<this.length;t++)yield this.data[t];}toString(){return `DynamicArray(size=${this.length}, capacity=${this.capacity}) [${this.toArray().join(", ")}]`}};var J=class n{capacity;data;constructor(t,e){if(!Number.isInteger(t)||t<=0)throw new Error("StaticArray size must be a positive integer");this.capacity=t,this.data=new Array(t),e!==void 0&&this.fill(e);}size(){return this.capacity}checkBounds(t){if(!Number.isInteger(t))throw new Error("Index must be an integer");if(t<0||t>=this.capacity)throw new RangeError(`Index ${t} out of bounds (0 - ${this.capacity-1})`)}get(t){return this.checkBounds(t),this.data[t]}set(t,e){this.checkBounds(t),this.data[t]=e;}fill(t){for(let e=0;e<this.capacity;e++)this.data[e]=t;}clear(){for(let t=0;t<this.capacity;t++)this.data[t]=void 0;}contains(t){for(let e=0;e<this.capacity;e++)if(this.data[e]===t)return true;return false}indexOf(t){for(let e=0;e<this.capacity;e++)if(this.data[e]===t)return e;return -1}toArray(){return [...this.data]}*[Symbol.iterator](){for(let t=0;t<this.capacity;t++){let e=this.data[t];e!==void 0&&(yield e);}}forEach(t){for(let e=0;e<this.capacity;e++)t(this.data[e],e);}clone(){let t=new n(this.capacity);for(let e=0;e<this.capacity;e++)t.data[e]=this.data[e];return t}toString(){return `StaticArray(${this.capacity}) [${this.data.join(", ")}]`}};var X=class{list=new Map;addVertex(t){this.list.has(t)||this.list.set(t,[]);}removeVertex(t){this.list.delete(t);for(let e of this.list.values())for(let r=e.length-1;r>=0;r--)e[r].to===t&&e.splice(r,1);}hasVertex(t){return this.list.has(t)}getVertices(){return Array.from(this.list.keys())}addEdge(t,e,r){this.addVertex(t),this.addVertex(e),this.list.get(t).push({to:e,weight:r});}removeEdge(t,e){let r=this.list.get(t);if(r)for(let i=r.length-1;i>=0;i--)r[i].to===e&&r.splice(i,1);}hasEdge(t,e){return this.list.get(t)?.some(r=>r.to===e)??false}getEdges(t){return this.list.get(t)?.slice()??[]}clear(){this.list.clear();}size(){return this.list.size}};var Y=class{directed;matrix;vertices=[];indexMap=new Map;constructor(t=false){this.directed=t,this.matrix=[];}addVertex(t){if(this.indexMap.has(t))return;let e=this.vertices.length;this.vertices.push(t),this.indexMap.set(t,e);for(let r of this.matrix)r.push(0);this.matrix.push(new Array(e+1).fill(0));}removeVertex(t){let e=this.indexMap.get(t);if(e!==void 0){this.vertices.splice(e,1),this.indexMap.delete(t),this.matrix.splice(e,1);for(let r of this.matrix)r.splice(e,1);for(let r=e;r<this.vertices.length;r++)this.indexMap.set(this.vertices[r],r);}}hasVertex(t){return this.indexMap.has(t)}getVertices(){return [...this.vertices]}addEdge(t,e,r=1){this.addVertex(t),this.addVertex(e);let i=this.indexMap.get(t),s=this.indexMap.get(e);this.matrix[i][s]=r,this.directed||(this.matrix[s][i]=r);}removeEdge(t,e){let r=this.indexMap.get(t),i=this.indexMap.get(e);r===void 0||i===void 0||(this.matrix[r][i]=0,this.directed||(this.matrix[i][r]=0));}hasEdge(t,e){let r=this.indexMap.get(t),i=this.indexMap.get(e);return r===void 0||i===void 0?false:this.matrix[r][i]!==0}getWeight(t,e){let r=this.indexMap.get(t),i=this.indexMap.get(e);if(!(r===void 0||i===void 0))return this.matrix[r][i]||void 0}size(){return this.vertices.length}clear(){this.vertices=[],this.indexMap.clear(),this.matrix=[];}isDirected(){return this.directed}toMatrix(){return this.matrix.map(t=>[...t])}};var Z=class{adjList=new Map;addVertex(t){this.adjList.has(t)||this.adjList.set(t,[]);}removeVertex(t){this.adjList.delete(t);for(let e of this.adjList.values())for(let r=e.length-1;r>=0;r--)e[r].to===t&&e.splice(r,1);}hasVertex(t){return this.adjList.has(t)}getVertices(){return Array.from(this.adjList.keys())}addEdge(t,e,r){this.addVertex(t),this.addVertex(e),this.adjList.get(t).push({to:e,weight:r});}removeEdge(t,e){let r=this.adjList.get(t);if(r)for(let i=r.length-1;i>=0;i--)r[i].to===e&&r.splice(i,1);}hasEdge(t,e){return this.adjList.get(t)?.some(r=>r.to===e)??false}getEdges(t){return this.adjList.get(t)?.slice()??[]}bfs(t){if(!this.adjList.has(t))return [];let e=new Set,r=[],i=[];for(e.add(t),r.push(t);r.length>0;){let s=r.shift();i.push(s);for(let o of this.adjList.get(s))e.has(o.to)||(e.add(o.to),r.push(o.to));}return i}dfs(t){if(!this.adjList.has(t))return [];let e=new Set,r=[],i=s=>{e.add(s),r.push(s);for(let o of this.adjList.get(s))e.has(o.to)||i(o.to);};return i(t),r}clear(){this.adjList.clear();}size(){return this.adjList.size}isDirected(){return true}};var G=class{directed;adjList=new Map;constructor(t=false){this.directed=t;}addVertex(t){this.adjList.has(t)||this.adjList.set(t,[]);}removeVertex(t){this.adjList.delete(t);for(let e of this.adjList.values())for(let r=e.length-1;r>=0;r--)e[r].to===t&&e.splice(r,1);}hasVertex(t){return this.adjList.has(t)}getVertices(){return Array.from(this.adjList.keys())}addEdge(t,e,r){this.addVertex(t),this.addVertex(e),this.adjList.get(t).push({to:e,weight:r}),this.directed||this.adjList.get(e).push({to:t,weight:r});}removeEdge(t,e){let r=this.adjList.get(t);if(r)for(let i=r.length-1;i>=0;i--)r[i].to===e&&r.splice(i,1);if(!this.directed){let i=this.adjList.get(e);if(i)for(let s=i.length-1;s>=0;s--)i[s].to===t&&i.splice(s,1);}}hasEdge(t,e){return this.adjList.get(t)?.some(r=>r.to===e)??false}getEdges(t){return this.adjList.get(t)?.slice()??[]}bfs(t){if(!this.adjList.has(t))return [];let e=new Set,r=[],i=[];for(e.add(t),r.push(t);r.length>0;){let s=r.shift();i.push(s);for(let o of this.adjList.get(s))e.has(o.to)||(e.add(o.to),r.push(o.to));}return i}dfs(t){if(!this.adjList.has(t))return [];let e=new Set,r=[],i=s=>{e.add(s),r.push(s);for(let o of this.adjList.get(s))e.has(o.to)||i(o.to);};return i(t),r}clear(){this.adjList.clear();}size(){return this.adjList.size}isDirected(){return this.directed}};var tt=class{ring=new Map;sortedKeys=[];replicas;constructor(t=100){if(t<=0)throw new Error("Replicas must be greater than 0");this.replicas=t;}addNode(t){for(let e=0;e<this.replicas;e++){let r=this.hash(`${t}:${e}`);this.ring.set(r,t),this.sortedKeys.push(r);}this.sortRing();}removeNode(t){for(let e=0;e<this.replicas;e++){let r=this.hash(`${t}:${e}`);this.ring.delete(r);let i=this.sortedKeys.indexOf(r);i!==-1&&this.sortedKeys.splice(i,1);}}getNode(t){if(this.ring.size===0)return;let e=this.hash(String(t)),r=this.findClosestIndex(e),i=this.sortedKeys[r];return this.ring.get(i)}getNodes(){return Array.from(new Set(this.ring.values()))}size(){return this.getNodes().length}clear(){this.ring.clear(),this.sortedKeys=[];}hash(t){let e=0;for(let r=0;r<t.length;r++)e=e*31+t.charCodeAt(r)>>>0;return e}sortRing(){this.sortedKeys.sort((t,e)=>t-e);}findClosestIndex(t){let e=0,r=this.sortedKeys.length-1;for(;e<=r;){let i=Math.floor((e+r)/2);if(this.sortedKeys[i]===t)return i;this.sortedKeys[i]<t?e=i+1:r=i-1;}return e<this.sortedKeys.length?e:0}};var O=class{buckets;capacity;size;LOAD_FACTOR=.75;constructor(t=16){if(t<=0)throw new Error("Initial capacity must be greater than 0");this.capacity=t,this.size=0,this.buckets=Array.from({length:this.capacity},()=>[]);}set(t,e){let r=this.hash(t),i=this.buckets[r];for(let s of i)if(s.key===t){s.value=e;return}i.push({key:t,value:e}),this.size++,this.size/this.capacity>this.LOAD_FACTOR&&this.resize();}get(t){let e=this.hash(t),r=this.buckets[e];for(let i of r)if(i.key===t)return i.value}has(t){return this.get(t)!==void 0}delete(t){let e=this.hash(t),r=this.buckets[e],i=r.findIndex(s=>s.key===t);return i===-1?false:(r.splice(i,1),this.size--,true)}clear(){this.buckets=Array.from({length:this.capacity},()=>[]),this.size=0;}keys(){return this.buckets.flatMap(t=>t.map(e=>e.key))}values(){return this.buckets.flatMap(t=>t.map(e=>e.value))}entries(){return this.buckets.flatMap(t=>t.map(e=>[e.key,e.value]))}getSize(){return this.size}getCapacity(){return this.capacity}hash(t){let e=String(t),r=0;for(let i=0;i<e.length;i++)r=(r*31+e.charCodeAt(i))%this.capacity;return r}resize(){let t=this.buckets;this.capacity*=2,this.size=0,this.buckets=Array.from({length:this.capacity},()=>[]);for(let e of t)for(let r of e)this.set(r.key,r.value);}},et=O;var rt=class{map;constructor(t=16){this.map=new et(t);}add(t){this.map.set(t,true);}has(t){return this.map.has(t)}delete(t){return this.map.delete(t)}clear(){this.map.clear();}size(){return this.map.getSize()}values(){return this.map.keys()}isEmpty(){return this.size()===0}};var p=class{value;next=null;prev=null;constructor(t){this.value=t;}};var w=class{head=null;tail=null;length=0;size(){return this.length}add(t){let e=new p(t);this.head?(e.prev=this.tail,this.tail.next=e,this.tail=e):this.head=this.tail=e,this.length++;}remove(t){let e=this.head;for(;e;){if(e.value===t)return e.prev?e.prev.next=e.next:this.head=e.next,e.next?e.next.prev=e.prev:this.tail=e.prev,this.length--,true;e=e.next;}return false}toArray(){return [...this]}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.value,t=t.next;}};var it=class{capacity;size=0;minFreq=0;cache=new Map;freqMap=new Map;constructor(t){if(t<=0)throw new Error("Capacity must be greater than 0");this.capacity=t;}get(t){let e=this.cache.get(t);if(e)return this.updateFrequency(e),e.value}put(t,e){if(this.capacity===0)return;let r=this.cache.get(t);if(r){r.value=e,this.updateFrequency(r);return}this.size>=this.capacity&&this.evictLFU();let i={key:t,value:e,freq:1};this.cache.set(t,i),this.getFreqList(1).add(i),this.minFreq=1,this.size++;}has(t){return this.cache.has(t)}sizeOf(){return this.size}clear(){this.cache.clear(),this.freqMap.clear(),this.size=0,this.minFreq=0;}updateFrequency(t){let e=t.freq,r=this.freqMap.get(e);r.remove(t),e===this.minFreq&&r.size()===0&&this.minFreq++,t.freq++,this.getFreqList(t.freq).add(t);}evictLFU(){let t=this.freqMap.get(this.minFreq);if(!t)return;let[e]=t.toArray();e&&(t.remove(e),this.cache.delete(e.key),this.size--);}getFreqList(t){let e=this.freqMap.get(t);return e||(e=new w,this.freqMap.set(t,e)),e}};var st=class{capacity;cache;head;tail;constructor(t){if(t<=0)throw new Error("Capacity must be greater than 0");this.capacity=t,this.cache=new Map,this.head=null,this.tail=null;}get(t){let e=this.cache.get(t);if(e)return this.moveToFront(e),e.value}put(t,e){let r=this.cache.get(t);if(r){r.value=e,this.moveToFront(r);return}let i={key:t,value:e,prev:null,next:null};this.cache.set(t,i),this.addToFront(i),this.cache.size>this.capacity&&this.evictLeastRecentlyUsed();}has(t){return this.cache.has(t)}size(){return this.cache.size}clear(){this.cache.clear(),this.head=null,this.tail=null;}addToFront(t){t.prev=null,t.next=this.head,this.head&&(this.head.prev=t),this.head=t,this.tail||(this.tail=t);}removeNode(t){t.prev?t.prev.next=t.next:this.head=t.next,t.next?t.next.prev=t.prev:this.tail=t.prev,t.prev=null,t.next=null;}moveToFront(t){t!==this.head&&(this.removeNode(t),this.addToFront(t));}evictLeastRecentlyUsed(){if(!this.tail)return;let t=this.tail.key;this.removeNode(this.tail),this.cache.delete(t);}};var z=class{heap=[];compare;constructor(t,e){this.compare=t??((r,i)=>r<i?-1:r>i?1:0),e&&e.length>0&&(this.heap=[...e],this.heapify());}insert(t){this.heap.push(t),this.siftUp(this.heap.length-1);}extract(){if(this.heap.length===0)return;if(this.heap.length===1)return this.heap.pop();let t=this.heap[0];return this.heap[0]=this.heap.pop(),this.siftDown(0),t}peek(){return this.heap[0]}size(){return this.heap.length}isEmpty(){return this.heap.length===0}clear(){this.heap=[];}toArray(){return [...this.heap]}heapify(){for(let t=Math.floor(this.heap.length/2)-1;t>=0;t--)this.siftDown(t);}siftUp(t){let e=t;for(;e>0;){let r=Math.floor((e-1)/2);if(this.compare(this.heap[e],this.heap[r])>=0)break;this.swap(e,r),e=r;}}siftDown(t){let e=t,r=this.heap.length;for(;;){let i=e*2+1,s=e*2+2,o=e;if(i<r&&this.compare(this.heap[i],this.heap[o])<0&&(o=i),s<r&&this.compare(this.heap[s],this.heap[o])<0&&(o=s),o===e)break;this.swap(e,o),e=o;}}swap(t,e){[this.heap[t],this.heap[e]]=[this.heap[e],this.heap[t]];}},k=z;var q=class{key;parent=null;children=[];mark=false;constructor(t){this.key=t;}},nt=class{roots=[];minNode=null;_size=0;compare;constructor(t){this.compare=t??((e,r)=>e<r?-1:e>r?1:0);}insert(t){let e=new q(t);return this.roots.push(e),(!this.minNode||this.compare(t,this.minNode.key)<0)&&(this.minNode=e),this._size++,e}findMin(){return this.minNode?.key}size(){return this._size}isEmpty(){return this._size===0}merge(t){for(let e of t.roots)this.roots.push(e);t.minNode&&(!this.minNode||this.compare(t.minNode.key,this.minNode.key)<0)&&(this.minNode=t.minNode),this._size+=t._size,t.clear();}extractMin(){if(!this.minNode)return;let t=this.minNode;for(let e of t.children)e.parent=null,this.roots.push(e);return this.roots=this.roots.filter(e=>e!==t),this._size--,this.roots.length===0?(this.minNode=null,t.key):(this.consolidate(),t.key)}decreaseKey(t,e){if(this.compare(e,t.key)>0)throw new Error("New key is greater than current key");t.key=e;let r=t.parent;r&&this.compare(t.key,r.key)<0&&(this.cut(t,r),this.cascadingCut(r)),this.minNode&&this.compare(t.key,this.minNode.key)<0&&(this.minNode=t);}clear(){this.roots=[],this.minNode=null,this._size=0;}consolidate(){let t=new Map;for(let e of [...this.roots]){let r=e,i=r.children.length;for(;t.has(i);){let s=t.get(i);this.compare(s.key,r.key)<0&&([r,s]=[s,r]),this.link(s,r),t.delete(i),i=r.children.length;}t.set(i,r);}this.roots=[],this.minNode=null;for(let e of t.values())this.roots.push(e),(!this.minNode||this.compare(e.key,this.minNode.key)<0)&&(this.minNode=e);}link(t,e){this.roots=this.roots.filter(r=>r!==t),t.parent=e,t.mark=false,e.children.push(t);}cut(t,e){e.children=e.children.filter(r=>r!==t),t.parent=null,t.mark=false,this.roots.push(t);}cascadingCut(t){let e=t.parent;e&&(t.mark?(this.cut(t,e),this.cascadingCut(e)):t.mark=true);}};var ot=class extends k{constructor(t){super((e,r)=>e>r?-1:e<r?1:0,t);}};var at=class extends k{constructor(t){super((e,r)=>e<r?-1:e>r?1:0,t);}};var F=class{key;child=null;sibling=null;parent=null;constructor(t){this.key=t;}},ht=class{root=null;_size=0;compare;constructor(t){this.compare=t??((e,r)=>e<r?-1:e>r?1:0);}insert(t){let e=new F(t);return this.root=this.mergeNodes(this.root,e),this._size++,e}findMin(){return this.root?.key}size(){return this._size}isEmpty(){return this._size===0}merge(t){t.root&&(this.root=this.mergeNodes(this.root,t.root),this._size+=t._size,t.clear());}extractMin(){if(!this.root)return;let t=this.root.key;return this.root.child?(this.root=this.combineSiblings(this.root.child),this.root.parent=null):this.root=null,this._size--,t}decreaseKey(t,e){if(this.compare(e,t.key)>0)throw new Error("New key is greater than current key");t.key=e,t!==this.root&&(this.cut(t),this.root=this.mergeNodes(this.root,t));}clear(){this.root=null,this._size=0;}mergeNodes(t,e){return t?e?this.compare(t.key,e.key)<=0?(e.parent=t,e.sibling=t.child,t.child=e,t):(t.parent=e,t.sibling=e.child,e.child=t,e):t:e}combineSiblings(t){let e=[],r=t;for(;r;){let o=r.sibling;r.sibling=null,e.push(r),r=o;}let i=[];for(let o=0;o<e.length;o+=2)o+1<e.length?i.push(this.mergeNodes(e[o],e[o+1])):i.push(e[o]);let s=i[i.length-1];for(let o=i.length-2;o>=0;o--)s=this.mergeNodes(i[o],s);return s}cut(t){let e=t.parent;if(e){if(e.child===t)e.child=t.sibling;else {let r=e.child;for(;r&&r.sibling!==t;)r=r.sibling;r&&(r.sibling=t.sibling);}t.parent=null,t.sibling=null;}}};var lt=class{tail=null;length=0;size(){return this.length}add(t){let e=new p(t);this.tail?(e.next=this.tail.next,this.tail.next=e,this.tail=e):(e.next=e,this.tail=e),this.length++;}remove(t){if(!this.tail)return false;let e=this.tail.next,r=this.tail;do{if(e.value===t)return e===this.tail&&e.next===e?this.tail=null:(r.next=e.next,e===this.tail&&(this.tail=r)),this.length--,true;r=e,e=e.next;}while(e!==this.tail.next);return false}toArray(){return [...this]}*[Symbol.iterator](){if(!this.tail)return;let t=this.tail.next;do yield t.value,t=t.next;while(t!==this.tail.next)}};var ut=class{head=null;tail=null;length=0;size(){return this.length}isEmpty(){return this.length===0}add(t){let e=new p(t);this.head?(this.tail.next=e,this.tail=e):this.head=this.tail=e,this.length++;}remove(t){if(!this.head)return false;if(this.head.value===t)return this.head=this.head.next,this.head||(this.tail=null),this.length--,true;let e=this.head;for(;e.next;){if(e.next.value===t)return e.next===this.tail&&(this.tail=e),e.next=e.next.next,this.length--,true;e=e.next;}return false}contains(t){for(let e of this)if(e===t)return true;return false}toArray(){return [...this]}*[Symbol.iterator](){let t=this.head;for(;t;)yield t.value,t=t.next;}};var ct=class{size;hashCount;bits;constructor(t,e){if(t<=0||e<=0)throw new Error("BloomFilter size and hashCount must be > 0");this.size=t,this.hashCount=e,this.bits=new Uint8Array(t);}add(t){let e=this.getHashes(t);for(let r of e)this.bits[r]=1;}contains(t){let e=this.getHashes(t);for(let r of e)if(this.bits[r]===0)return false;return true}clear(){this.bits.fill(0);}getHashes(t){let e=[],r=this.hash(t,5381),i=this.hash(t,52711);for(let s=0;s<this.hashCount;s++){let o=(r+s*i)%this.size;e.push(o);}return e}hash(t,e){let r=e;for(let i=0;i<t.length;i++)r=r*33^t.charCodeAt(i);return Math.abs(r)%this.size}};var dt=class{width;depth;table;seeds;constructor(t,e){if(t<=0||e<=0)throw new Error("Width and depth must be greater than 0");this.width=t,this.depth=e,this.table=Array.from({length:e},()=>Array(t).fill(0)),this.seeds=Array.from({length:e},(r,i)=>i*73856093+17);}update(t,e=1){if(!(e<=0))for(let r=0;r<this.depth;r++){let i=this.hash(t,this.seeds[r]);this.table[r][i]+=e;}}estimate(t){let e=1/0;for(let r=0;r<this.depth;r++){let i=this.hash(t,this.seeds[r]);e=Math.min(e,this.table[r][i]);}return e===1/0?0:e}clear(){for(let t=0;t<this.depth;t++)this.table[t].fill(0);}hash(t,e){let r=e;for(let i=0;i<t.length;i++)r=r*31+t.charCodeAt(i)>>>0;return r%this.width}};var ft=class{p;m;registers;alpha;constructor(t=10){if(t<4||t>16)throw new Error("p must be between 4 and 16");this.p=t,this.m=1<<t,this.registers=new Uint8Array(this.m),this.alpha=this.getAlpha(this.m);}add(t){let e=this.hash(t),r=e>>>32-this.p,i=e<<this.p|1<<this.p-1,s=this.countLeadingZeros(i)+1;this.registers[r]=Math.max(this.registers[r],s);}count(){let t=0,e=0;for(let i of this.registers)t+=Math.pow(2,-i),i===0&&e++;let r=this.alpha*this.m*this.m/t;return r<=2.5*this.m&&e>0&&(r=this.m*Math.log(this.m/e)),Math.round(r)}clear(){this.registers.fill(0);}hash(t){let e=2166136261;for(let r=0;r<t.length;r++)e^=t.charCodeAt(r),e=Math.imul(e,16777619);return e>>>0}countLeadingZeros(t){return Math.clz32(t)}getAlpha(t){switch(t){case 16:return .673;case 32:return .697;case 64:return .709;default:return .7213/(1+1.079/t)}}};var pt=class{constructor(t){this.capacity=t;if(!Number.isInteger(t)||t<=0)throw new Error("Capacity must be a positive integer");this.data=new Array(t);}data;head=0;tail=0;length=0;size(){return this.length}isEmpty(){return this.length===0}isFull(){return this.length===this.capacity}enqueue(t){if(this.isFull())throw new Error("CircularQueue is full");this.data[this.tail]=t,this.tail=(this.tail+1)%this.capacity,this.length++;}dequeue(){if(this.isEmpty())return;let t=this.data[this.head];return this.data[this.head]=void 0,this.head=(this.head+1)%this.capacity,this.length--,t}peek(){return this.isEmpty()?void 0:this.data[this.head]}clear(){this.data=new Array(this.capacity),this.head=0,this.tail=0,this.length=0;}toArray(){let t=[];for(let e=0;e<this.length;e++)t.push(this.data[(this.head+e)%this.capacity]);return t}toString(){return `CircularQueue [${this.toArray().join(", ")}]`}};var mt=class{items=[];size(){return this.items.length}isEmpty(){return this.items.length===0}pushFront(t){this.items.unshift(t);}pushBack(t){this.items.push(t);}popFront(){return this.items.shift()}popBack(){return this.items.pop()}peekFront(){return this.items[0]}peekBack(){return this.items[this.items.length-1]}clear(){this.items.length=0;}toArray(){return [...this.items]}toString(){return `Deque [${this.items.join(", ")}]`}};var gt=class{heap=[];size(){return this.heap.length}isEmpty(){return this.heap.length===0}enqueue(t,e){this.heap.push({value:t,priority:e}),this.bubbleUp();}dequeue(){if(this.isEmpty())return;let t=this.heap[0],e=this.heap.pop();return this.isEmpty()||(this.heap[0]=e,this.bubbleDown()),t.value}peek(){return this.heap[0]?.value}bubbleUp(){let t=this.heap.length-1;for(;t>0;){let e=Math.floor((t-1)/2);if(this.heap[e].priority<=this.heap[t].priority)break;[this.heap[e],this.heap[t]]=[this.heap[t],this.heap[e]],t=e;}}bubbleDown(){let t=0;for(;;){let e=t*2+1,r=t*2+2,i=t;if(e<this.heap.length&&this.heap[e].priority<this.heap[i].priority&&(i=e),r<this.heap.length&&this.heap[r].priority<this.heap[i].priority&&(i=r),i===t)break;[this.heap[t],this.heap[i]]=[this.heap[i],this.heap[t]],t=i;}}toString(){return `PriorityQueue [${this.heap.map(t=>`${t.value}:${t.priority}`).join(", ")}]`}};var Tt=class{items=[];head=0;size(){return this.items.length-this.head}isEmpty(){return this.size()===0}enqueue(t){this.items.push(t);}dequeue(){if(this.isEmpty())return;let t=this.items[this.head];return this.head++,this.head>50&&this.head*2>=this.items.length&&(this.items=this.items.slice(this.head),this.head=0),t}peek(){return this.isEmpty()?void 0:this.items[this.head]}clear(){this.items=[],this.head=0;}toArray(){return this.items.slice(this.head)}toString(){return `Queue [${this.toArray().join(", ")}]`}};var vt=class{parent=new Map;rank=new Map;makeSet(t){this.parent.has(t)||(this.parent.set(t,t),this.rank.set(t,0));}find(t){if(!this.parent.has(t))throw new Error("Element not found in DisjointSetUnion");let e=this.parent.get(t);if(e!==t){let r=this.find(e);return this.parent.set(t,r),r}return t}union(t,e){this.makeSet(t),this.makeSet(e);let r=this.find(t),i=this.find(e);if(r===i)return;let s=this.rank.get(r),o=this.rank.get(i);s<o?this.parent.set(r,i):s>o?this.parent.set(i,r):(this.parent.set(i,r),this.rank.set(r,s+1));}connected(t,e){return !this.parent.has(t)||!this.parent.has(e)?false:this.find(t)===this.find(e)}countSets(){let t=new Set;for(let e of this.parent.keys())t.add(this.find(e));return t.size}elements(){return Array.from(this.parent.keys())}clear(){this.parent.clear(),this.rank.clear();}size(){return this.parent.size}};var bt=class n{store;constructor(t){if(this.store=new Map,t)for(let e of t)this.add(e);}add(t,e=1){e<=0||this.store.set(t,(this.store.get(t)??0)+e);}remove(t,e=1){let r=this.store.get(t);return r===void 0?false:(e>=r?this.store.delete(t):this.store.set(t,r-e),true)}clear(){this.store.clear();}has(t){return this.store.has(t)}count(t){return this.store.get(t)??0}size(){let t=0;for(let e of this.store.values())t+=e;return t}distinctSize(){return this.store.size}isEmpty(){return this.store.size===0}values(){let t=[];for(let[e,r]of this.store)for(let i=0;i<r;i++)t.push(e);return t}entries(){return Array.from(this.store.entries())}union(t){let e=new n;for(let[r,i]of this.store)e.add(r,i);for(let[r,i]of t.store){let s=e.count(r);i>s&&e.store.set(r,i);}return e}intersection(t){let e=new n;for(let[r,i]of this.store){let s=Math.min(i,t.count(r));s>0&&e.add(r,s);}return e}difference(t){let e=new n;for(let[r,i]of this.store){let s=i-t.count(r);s>0&&e.add(r,s);}return e}[Symbol.iterator](){return this.store[Symbol.iterator]()}};var yt=class n{store;constructor(t){if(this.store=new Map,t)for(let e of t)this.add(e);}add(t){this.store.set(t,true);}delete(t){return this.store.delete(t)}has(t){return this.store.has(t)}clear(){this.store.clear();}size(){return this.store.size}isEmpty(){return this.store.size===0}values(){return Array.from(this.store.keys())}first(){return this.store.keys().next().value}last(){let t;for(let e of this.store.keys())t=e;return t}union(t){let e=new n;for(let r of this)e.add(r);for(let r of t)e.add(r);return e}intersection(t){let e=new n;for(let r of this)t.has(r)&&e.add(r);return e}difference(t){let e=new n;for(let r of this)t.has(r)||e.add(r);return e}isSubsetOf(t){for(let e of this)if(!t.has(e))return false;return true}isSupersetOf(t){return t.isSubsetOf(this)}[Symbol.iterator](){return this.store.keys()}};var xt=class n{store;constructor(t){this.store=new globalThis.Set(t);}add(t){this.store.add(t);}delete(t){return this.store.delete(t)}has(t){return this.store.has(t)}clear(){this.store.clear();}size(){return this.store.size}isEmpty(){return this.store.size===0}values(){return Array.from(this.store)}union(t){let e=new n(this.store);for(let r of t.store)e.add(r);return e}intersection(t){let e=new n;for(let r of this.store)t.has(r)&&e.add(r);return e}difference(t){let e=new n;for(let r of this.store)t.has(r)||e.add(r);return e}isSubsetOf(t){for(let e of this.store)if(!t.has(e))return false;return true}isSupersetOf(t){return t.isSubsetOf(this)}[Symbol.iterator](){return this.store[Symbol.iterator]()}};var E=class{point;value;axis;left=null;right=null;constructor(t,e,r){this.point=t,this.axis=e,this.value=r;}},Nt=class{root=null;k;constructor(t,e){if(t&&t.length>0)this.k=t[0].point.length,this.root=this.build(t,0);else if(e!==void 0)this.k=e;else throw new Error("KDTree requires points or dimension count")}insert(t,e){if(t.length!==this.k)throw new Error("Point dimensionality mismatch");this.root=this.insertNode(this.root,t,e,0);}contains(t){return !!this.findNode(this.root,t,0)}nearest(t){if(!this.root)return null;if(t.length!==this.k)throw new Error("Point dimensionality mismatch");let e=null,r,i=1/0,s=o=>{if(!o)return;let a=this.distanceSquared(t,o.point);a<i&&(i=a,e=o.point,r=o.value);let h=o.axis,u=t[h]-o.point[h],c=u<0?o.left:o.right,T=u<0?o.right:o.left;s(c),u*u<i&&s(T);};return s(this.root),e?{point:e,value:r}:null}rangeSearch(t,e){if(t.length!==this.k||e.length!==this.k)throw new Error("Point dimensionality mismatch");let r=[],i=s=>{if(!s)return;this.inRange(s.point,t,e)&&r.push({point:s.point,value:s.value});let o=s.axis;t[o]<=s.point[o]&&i(s.left),e[o]>=s.point[o]&&i(s.right);};return i(this.root),r}isEmpty(){return this.root===null}build(t,e){if(t.length===0)return null;let r=e%t[0].point.length;t.sort((o,a)=>o.point[r]-a.point[r]);let i=Math.floor(t.length/2),s=new E(t[i].point,r,t[i].value);return s.left=this.build(t.slice(0,i),e+1),s.right=this.build(t.slice(i+1),e+1),s}insertNode(t,e,r,i){if(!t)return new E(e,i%this.k,r);let s=t.axis;return e[s]<t.point[s]?t.left=this.insertNode(t.left,e,r,i+1):t.right=this.insertNode(t.right,e,r,i+1),t}findNode(t,e,r){if(!t)return null;if(this.pointsEqual(t.point,e))return t;let i=t.axis;return e[i]<t.point[i]?this.findNode(t.left,e,r+1):this.findNode(t.right,e,r+1)}distanceSquared(t,e){let r=0;for(let i=0;i<this.k;i++){let s=t[i]-e[i];r+=s*s;}return r}inRange(t,e,r){for(let i=0;i<this.k;i++)if(t[i]<e[i]||t[i]>r[i])return false;return true}pointsEqual(t,e){for(let r=0;r<this.k;r++)if(t[r]!==e[r])return false;return true}};var S=class n{boundary;capacity;points=[];divided=false;northeast=null;northwest=null;southeast=null;southwest=null;constructor(t,e){this.boundary=t,this.capacity=e;}insert(t,e){return K(this.boundary,t)?this.points.length<this.capacity&&!this.divided?(this.points.push({point:t,value:e}),true):(this.divided||this.subdivide(),this.northeast.insert(t,e)||this.northwest.insert(t,e)||this.southeast.insert(t,e)||this.southwest.insert(t,e)):false}contains(t){if(!K(this.boundary,t))return false;for(let e of this.points)if(e.point.x===t.x&&e.point.y===t.y)return true;return this.divided?this.northeast.contains(t)||this.northwest.contains(t)||this.southeast.contains(t)||this.southwest.contains(t):false}query(t,e){if(Xt(this.boundary,t)){for(let r of this.points)K(t,r.point)&&e.push(r);this.divided&&(this.northeast.query(t,e),this.northwest.query(t,e),this.southeast.query(t,e),this.southwest.query(t,e));}}subdivide(){let{x:t,y:e,w:r,h:i}=this.boundary,s=r/2,o=i/2;this.northeast=new n({x:t+s,y:e-o,w:s,h:o},this.capacity),this.northwest=new n({x:t-s,y:e-o,w:s,h:o},this.capacity),this.southeast=new n({x:t+s,y:e+o,w:s,h:o},this.capacity),this.southwest=new n({x:t-s,y:e+o,w:s,h:o},this.capacity),this.divided=true;}},wt=class{root;constructor(t,e=4){if(e<=0)throw new Error("QuadTree capacity must be greater than 0");this.root=new S(t,e);}insert(t,e){return this.root.insert(t,e)}contains(t){return this.root.contains(t)}query(t){let e=[];return this.root.query(t,e),e}clear(){this.root=new S(this.root.boundary,this.root.capacity);}};function K(n,t){return t.x>=n.x-n.w&&t.x<=n.x+n.w&&t.y>=n.y-n.h&&t.y<=n.y+n.h}function Xt(n,t){return !(t.x-t.w>n.x+n.w||t.x+t.w<n.x-n.w||t.y-t.h>n.y+n.h||t.y+t.h<n.y-n.h)}var kt=class{stack=[];maxStack=[];size(){return this.stack.length}isEmpty(){return this.stack.length===0}push(t){this.stack.push(t),(this.maxStack.length===0||t>=this.maxStack[this.maxStack.length-1])&&this.maxStack.push(t);}pop(){if(this.isEmpty())return;let t=this.stack.pop();return t===this.maxStack[this.maxStack.length-1]&&this.maxStack.pop(),t}peek(){return this.stack[this.stack.length-1]}getMax(){return this.maxStack[this.maxStack.length-1]}clear(){this.stack.length=0,this.maxStack.length=0;}toArray(){return [...this.stack]}toString(){return `MaxStack [${this.stack.join(", ")}]`}};var Et=class{stack=[];minStack=[];size(){return this.stack.length}isEmpty(){return this.stack.length===0}push(t){this.stack.push(t),(this.minStack.length===0||t<=this.minStack[this.minStack.length-1])&&this.minStack.push(t);}pop(){if(this.isEmpty())return;let t=this.stack.pop();return t===this.minStack[this.minStack.length-1]&&this.minStack.pop(),t}peek(){return this.stack[this.stack.length-1]}getMin(){return this.minStack[this.minStack.length-1]}clear(){this.stack.length=0,this.minStack.length=0;}toArray(){return [...this.stack]}toString(){return `MinStack [${this.stack.join(", ")}]`}};var St=class{items=[];size(){return this.items.length}isEmpty(){return this.items.length===0}push(t){this.items.push(t);}pop(){return this.items.pop()}peek(){return this.items[this.items.length-1]}clear(){this.items.length=0;}toArray(){return [...this.items]}*[Symbol.iterator](){for(let t=this.items.length-1;t>=0;t--)yield this.items[t];}toString(){return `Stack [${this.items.join(", ")}]`}};var At=class{text;suffixArray;constructor(t){this.text=t,this.suffixArray=this.buildSuffixArray(t);}getArray(){return [...this.suffixArray]}getText(){return this.text}getSuffix(t){if(t<0||t>=this.suffixArray.length)throw new RangeError("Index out of bounds");return this.text.slice(this.suffixArray[t])}size(){return this.suffixArray.length}buildSuffixArray(t){let e=t.length;if(e===0)return [];let r=new Array(e),i=new Array(e),s=new Array(e);for(let o=0;o<e;o++)r[o]=o,i[o]=t.charCodeAt(o);for(let o=1;o<e;o<<=1){r.sort((a,h)=>{if(i[a]!==i[h])return i[a]-i[h];let u=a+o<e?i[a+o]:-1,c=h+o<e?i[h+o]:-1;return u-c}),s[r[0]]=0;for(let a=1;a<e;a++){let h=r[a-1],u=r[a],c=i[h]===i[u]&&(h+o<e?i[h+o]:-1)===(u+o<e?i[u+o]:-1);s[u]=c?s[h]:s[h]+1;}for(let a=0;a<e;a++)i[a]=s[a];if(i[r[e-1]]===e-1)break}return r}};var x=class{value;constructor(t){this.value=t;}},v=class{children=new Map;start;end;suffixLink=null;constructor(t,e){this.start=t,this.end=e;}edgeLength(t){return Math.min(this.end.value,t+1)-this.start}},Ct=class{text;root;activeNode;activeEdge=-1;activeLength=0;remainingSuffixCount=0;leafEnd=new x(-1);constructor(t){this.text=t,this.root=new v(-1,new x(-1)),this.activeNode=this.root,this.build();}contains(t){if(t.length===0)return true;let e=this.root,r=0;for(;r<t.length;){let i=e.children.get(t[r]);if(!i)return false;let s=i.start,o=Math.min(i.end.value,this.text.length-1);for(;s<=o&&r<t.length;){if(this.text[s]!==t[r])return false;s++,r++;}if(r===t.length)return true;e=i;}return true}getText(){return this.text}build(){for(let t=0;t<this.text.length;t++)this.extend(t);}extend(t){this.leafEnd.value=t,this.remainingSuffixCount++;let e=null;for(;this.remainingSuffixCount>0;){this.activeLength===0&&(this.activeEdge=t);let r=this.text[this.activeEdge],i=this.activeNode.children.get(r);if(i){if(this.walkDown(i,t))continue;if(this.text[i.start+this.activeLength]===this.text[t]){e&&this.activeNode!==this.root&&(e.suffixLink=this.activeNode,e=null),this.activeLength++;break}let s=new x(i.start+this.activeLength),o=new v(i.start,s);this.activeNode.children.set(r,o);let a=new v(t,this.leafEnd);o.children.set(this.text[t],a),i.start+=this.activeLength,o.children.set(this.text[i.start],i),e&&(e.suffixLink=o),e=o;}else {let s=new v(t,this.leafEnd);this.activeNode.children.set(r,s),e&&(e.suffixLink=this.activeNode,e=null);}this.remainingSuffixCount--,this.activeNode===this.root&&this.activeLength>0?(this.activeLength--,this.activeEdge=t-this.remainingSuffixCount+1):this.activeNode!==this.root&&(this.activeNode=this.activeNode.suffixLink??this.root);}}walkDown(t,e){let r=t.edgeLength(e);return this.activeLength>=r?(this.activeEdge+=r,this.activeLength-=r,this.activeNode=t,true):false}};var Rt=class{n;log;table;combine;constructor(t,e){if(t.length===0)throw new Error("SparseTable requires a non-empty array");this.n=t.length,this.combine=e,this.log=new Array(this.n+1).fill(0);for(let i=2;i<=this.n;i++)this.log[i]=this.log[Math.floor(i/2)]+1;let r=this.log[this.n];this.table=Array.from({length:r+1},()=>new Array(this.n));for(let i=0;i<this.n;i++)this.table[0][i]=t[i];for(let i=1;i<=r;i++){let s=1<<i;for(let o=0;o+s<=this.n;o++)this.table[i][o]=this.combine(this.table[i-1][o],this.table[i-1][o+(s>>1)]);}}query(t,e){if(t<0||e>=this.n||t>e)throw new Error("Invalid query range");let r=e-t+1,i=this.log[r];return this.combine(this.table[i][t],this.table[i][e-(1<<i)+1])}size(){return this.n}};var V=class{value;left=null;right=null;height=0;constructor(t){this.value=t;}},Lt=class{root=null;compare;constructor(t){this.compare=t??((e,r)=>e<r?-1:e>r?1:0);}insert(t){this.root=this.insertNode(this.root,t);}remove(t){this.root=this.removeNode(this.root,t);}contains(t){return this.search(this.root,t)}inorder(){let t=[];return this.inorderTraverse(this.root,t),t}preorder(){let t=[];return this.preorderTraverse(this.root,t),t}postorder(){let t=[];return this.postorderTraverse(this.root,t),t}height(){return this.nodeHeight(this.root)}isEmpty(){return this.root===null}clear(){this.root=null;}insertNode(t,e){if(!t)return new V(e);let r=this.compare(e,t.value);if(r<0)t.left=this.insertNode(t.left,e);else if(r>0)t.right=this.insertNode(t.right,e);else return t;return this.updateHeight(t),this.rebalance(t)}removeNode(t,e){if(!t)return null;let r=this.compare(e,t.value);if(r<0)t.left=this.removeNode(t.left,e);else if(r>0)t.right=this.removeNode(t.right,e);else {if(!t.left||!t.right)return t.left??t.right;let i=this.findMin(t.right);t.value=i.value,t.right=this.removeNode(t.right,i.value);}return this.updateHeight(t),this.rebalance(t)}search(t,e){if(!t)return false;let r=this.compare(e,t.value);return r===0?true:r<0?this.search(t.left,e):this.search(t.right,e)}rotateRight(t){let e=t.left,r=e.right;return e.right=t,t.left=r,this.updateHeight(t),this.updateHeight(e),e}rotateLeft(t){let e=t.right,r=e.left;return e.left=t,t.right=r,this.updateHeight(t),this.updateHeight(e),e}rebalance(t){let e=this.getBalance(t);return e>1?(this.getBalance(t.left)<0&&(t.left=this.rotateLeft(t.left)),this.rotateRight(t)):e<-1?(this.getBalance(t.right)>0&&(t.right=this.rotateRight(t.right)),this.rotateLeft(t)):t}nodeHeight(t){return t?t.height:-1}updateHeight(t){t.height=1+Math.max(this.nodeHeight(t.left),this.nodeHeight(t.right));}getBalance(t){return this.nodeHeight(t.left)-this.nodeHeight(t.right)}findMin(t){for(;t.left;)t=t.left;return t}inorderTraverse(t,e){t&&(this.inorderTraverse(t.left,e),e.push(t.value),this.inorderTraverse(t.right,e));}preorderTraverse(t,e){t&&(e.push(t.value),this.preorderTraverse(t.left,e),this.preorderTraverse(t.right,e));}postorderTraverse(t,e){t&&(this.postorderTraverse(t.left,e),this.postorderTraverse(t.right,e),e.push(t.value));}};var D=class{value;color=0;left=null;right=null;parent=null;constructor(t){this.value=t;}},Bt=class{root=null;compare;constructor(t){this.compare=t??((e,r)=>e<r?-1:e>r?1:0);}insert(t){let e=new D(t);this.root=this.bstInsert(this.root,e),this.fixInsert(e);}remove(t){let e=this.findNode(this.root,t);e&&this.deleteNode(e);}contains(t){return !!this.findNode(this.root,t)}inorder(){let t=[];return this.inorderTraverse(this.root,t),t}height(){return this.calculateHeight(this.root)}isEmpty(){return this.root===null}clear(){this.root=null;}bstInsert(t,e){if(!t)return e;let r=this.compare(e.value,t.value);return r<0?(t.left=this.bstInsert(t.left,e),t.left.parent=t):r>0&&(t.right=this.bstInsert(t.right,e),t.right.parent=t),t}fixInsert(t){for(;t.parent&&t.parent.color===0;){let e=t.parent,r=e.parent;if(e===r.left){let i=r.right;i&&i.color===0?(e.color=1,i.color=1,r.color=0,t=r):(t===e.right&&(t=e,this.rotateLeft(t)),e.color=1,r.color=0,this.rotateRight(r));}else {let i=r.left;i&&i.color===0?(e.color=1,i.color=1,r.color=0,t=r):(t===e.left&&(t=e,this.rotateRight(t)),e.color=1,r.color=0,this.rotateLeft(r));}}this.root.color=1;}deleteNode(t){let e=t,r=e.color,i;t.left?t.right?(e=this.minimum(t.right),r=e.color,i=e.right,e.parent===t?i&&(i.parent=e):(this.transplant(e,e.right),e.right=t.right,e.right.parent=e),this.transplant(t,e),e.left=t.left,e.left.parent=e,e.color=t.color):(i=t.left,this.transplant(t,t.left)):(i=t.right,this.transplant(t,t.right)),r===1&&this.fixDelete(i,t.parent);}fixDelete(t,e){for(;t!==this.root&&(!t||t.color===1);)if(t===e?.left){let r=e.right;r?.color===0&&(r.color=1,e.color=0,this.rotateLeft(e),r=e.right),(!r?.left||r.left.color===1)&&(!r?.right||r.right.color===1)?(r.color=0,t=e,e=t.parent):((!r?.right||r.right.color===1)&&(r?.left&&(r.left.color=1),r.color=0,this.rotateRight(r),r=e.right),r.color=e.color,e.color=1,r?.right&&(r.right.color=1),this.rotateLeft(e),t=this.root);}else {let r=e?.left;r?.color===0&&(r.color=1,e.color=0,this.rotateRight(e),r=e.left),(!r?.left||r.left.color===1)&&(!r?.right||r.right.color===1)?(r.color=0,t=e,e=t.parent):((!r?.left||r.left.color===1)&&(r?.right&&(r.right.color=1),r.color=0,this.rotateLeft(r),r=e.left),r.color=e.color,e.color=1,r?.left&&(r.left.color=1),this.rotateRight(e),t=this.root);}t&&(t.color=1);}rotateLeft(t){let e=t.right;t.right=e.left,e.left&&(e.left.parent=t),e.parent=t.parent,t.parent?t===t.parent.left?t.parent.left=e:t.parent.right=e:this.root=e,e.left=t,t.parent=e;}rotateRight(t){let e=t.left;t.left=e.right,e.right&&(e.right.parent=t),e.parent=t.parent,t.parent?t===t.parent.left?t.parent.left=e:t.parent.right=e:this.root=e,e.right=t,t.parent=e;}transplant(t,e){t.parent?t===t.parent.left?t.parent.left=e:t.parent.right=e:this.root=e,e&&(e.parent=t.parent);}minimum(t){for(;t.left;)t=t.left;return t}findNode(t,e){if(!t)return null;let r=this.compare(e,t.value);return r===0?t:r<0?this.findNode(t.left,e):this.findNode(t.right,e)}inorderTraverse(t,e){t&&(this.inorderTraverse(t.left,e),e.push(t.value),this.inorderTraverse(t.right,e));}calculateHeight(t){return t?1+Math.max(this.calculateHeight(t.left),this.calculateHeight(t.right)):-1}};var A=class{value;left=null;right=null;parent=null;constructor(t){this.value=t;}},Mt=class{root=null;compare;constructor(t){this.compare=t??((e,r)=>e<r?-1:e>r?1:0);}insert(t){if(!this.root){this.root=new A(t);return}let e=this.root,r=null;for(;e;){r=e;let s=this.compare(t,e.value);if(s<0)e=e.left;else if(s>0)e=e.right;else {this.splay(e);return}}let i=new A(t);i.parent=r,this.compare(t,r.value)<0?r.left=i:r.right=i,this.splay(i);}contains(t){let e=this.findNode(t);return e?(this.splay(e),true):false}remove(t){let e=this.findNode(t);if(e)if(this.splay(e),!e.left)this.replaceRoot(e.right);else if(!e.right)this.replaceRoot(e.left);else {let r=this.subtreeMax(e.left);this.splay(r),r.right=e.right,e.right&&(e.right.parent=r),this.root=r,r.parent=null;}}inorder(){let t=[];return this.inorderTraverse(this.root,t),t}height(){return this.calculateHeight(this.root)}isEmpty(){return this.root===null}clear(){this.root=null;}splay(t){for(;t.parent;){let e=t.parent,r=e.parent;r?t===e.left&&e===r.left?(this.rotateRight(r),this.rotateRight(e)):t===e.right&&e===r.right?(this.rotateLeft(r),this.rotateLeft(e)):t===e.right&&e===r.left?(this.rotateLeft(e),this.rotateRight(r)):(this.rotateRight(e),this.rotateLeft(r)):t===e.left?this.rotateRight(e):this.rotateLeft(e);}this.root=t;}rotateLeft(t){let e=t.right;t.right=e.left,e.left&&(e.left.parent=t),e.parent=t.parent,t.parent?t===t.parent.left?t.parent.left=e:t.parent.right=e:this.root=e,e.left=t,t.parent=e;}rotateRight(t){let e=t.left;t.left=e.right,e.right&&(e.right.parent=t),e.parent=t.parent,t.parent?t===t.parent.left?t.parent.left=e:t.parent.right=e:this.root=e,e.right=t,t.parent=e;}findNode(t){let e=this.root;for(;e;){let r=this.compare(t,e.value);if(r===0)return e;e=r<0?e.left:e.right;}return null}replaceRoot(t){this.root=t,t&&(t.parent=null);}subtreeMax(t){for(;t.right;)t=t.right;return t}inorderTraverse(t,e){t&&(this.inorderTraverse(t.left,e),e.push(t.value),this.inorderTraverse(t.right,e));}calculateHeight(t){return t?1+Math.max(this.calculateHeight(t.left),this.calculateHeight(t.right)):-1}};var j=class{value;left=null;right=null;constructor(t){this.value=t;}},It=class{root=null;compare;constructor(t){this.compare=t??((e,r)=>e<r?-1:e>r?1:0);}insert(t){this.root=this.insertNode(this.root,t);}contains(t){return this.search(this.root,t)}remove(t){this.root=this.removeNode(this.root,t);}inorder(){let t=[];return this.inorderTraverse(this.root,t),t}preorder(){let t=[];return this.preorderTraverse(this.root,t),t}postorder(){let t=[];return this.postorderTraverse(this.root,t),t}min(){if(this.root)return this.findMin(this.root).value}max(){if(this.root)return this.findMax(this.root).value}height(){return this.calculateHeight(this.root)}isEmpty(){return this.root===null}clear(){this.root=null;}insertNode(t,e){if(!t)return new j(e);let r=this.compare(e,t.value);return r<0?t.left=this.insertNode(t.left,e):r>0&&(t.right=this.insertNode(t.right,e)),t}search(t,e){if(!t)return false;let r=this.compare(e,t.value);return r===0?true:r<0?this.search(t.left,e):this.search(t.right,e)}removeNode(t,e){if(!t)return null;let r=this.compare(e,t.value);if(r<0)t.left=this.removeNode(t.left,e);else if(r>0)t.right=this.removeNode(t.right,e);else {if(!t.left&&!t.right)return null;if(!t.left)return t.right;if(!t.right)return t.left;let i=this.findMin(t.right);t.value=i.value,t.right=this.removeNode(t.right,i.value);}return t}inorderTraverse(t,e){t&&(this.inorderTraverse(t.left,e),e.push(t.value),this.inorderTraverse(t.right,e));}preorderTraverse(t,e){t&&(e.push(t.value),this.preorderTraverse(t.left,e),this.preorderTraverse(t.right,e));}postorderTraverse(t,e){t&&(this.postorderTraverse(t.left,e),this.postorderTraverse(t.right,e),e.push(t.value));}findMin(t){for(;t.left;)t=t.left;return t}findMax(t){for(;t.right;)t=t.right;return t}calculateHeight(t){return t?1+Math.max(this.calculateHeight(t.left),this.calculateHeight(t.right)):-1}};var C=class{value;left=null;right=null;constructor(t){this.value=t;}},Pt=class{root=null;constructor(t){t!==void 0&&(this.root=new C(t));}insert(t){let e=new C(t);if(!this.root){this.root=e;return}let r=[this.root];for(;r.length>0;){let i=r.shift();if(i.left)r.push(i.left);else {i.left=e;return}if(i.right)r.push(i.right);else {i.right=e;return}}}inorder(){let t=[];return this.inorderTraverse(this.root,t),t}preorder(){let t=[];return this.preorderTraverse(this.root,t),t}postorder(){let t=[];return this.postorderTraverse(this.root,t),t}levelOrder(){let t=[];if(!this.root)return t;let e=[this.root];for(;e.length>0;){let r=e.shift();t.push(r.value),r.left&&e.push(r.left),r.right&&e.push(r.right);}return t}height(){return this.calculateHeight(this.root)}isEmpty(){return this.root===null}clear(){this.root=null;}inorderTraverse(t,e){t&&(this.inorderTraverse(t.left,e),e.push(t.value),this.inorderTraverse(t.right,e));}preorderTraverse(t,e){t&&(e.push(t.value),this.preorderTraverse(t.left,e),this.preorderTraverse(t.right,e));}postorderTraverse(t,e){t&&(this.postorderTraverse(t.left,e),this.postorderTraverse(t.right,e),e.push(t.value));}calculateHeight(t){return t?1+Math.max(this.calculateHeight(t.left),this.calculateHeight(t.right)):-1}};var b=class{keys=[];children=[];leaf;next=null;constructor(t){this.leaf=t;}},Ot=class{root;t;compare;constructor(t,e){if(t<2)throw new Error("BPlusTree minimum degree must be >= 2");this.t=t,this.root=new b(true),this.compare=e??((r,i)=>r<i?-1:r>i?1:0);}search(t){return this.findLeaf(this.root,t).keys.some(r=>this.compare(r,t)===0)}insert(t){let e=this.root;if(e.keys.length===2*this.t-1){let r=new b(false);r.children[0]=e,this.splitChild(r,0),this.root=r;}this.insertNonFull(this.root,t);}delete(t){this.deleteFromNode(this.root,t),!this.root.leaf&&this.root.keys.length===0&&(this.root=this.root.children[0]);}traverse(){let t=[],e=this.root;for(;e&&!e.leaf;)e=e.children[0];for(;e;)t.push(...e.keys),e=e.next;return t}range(t,e){let r=[],i=this.findLeaf(this.root,t);for(;i;){for(let s of i.keys){if(this.compare(s,e)>0)return r;this.compare(s,t)>=0&&r.push(s);}i=i.next;}return r}clear(){this.root=new b(true);}isEmpty(){return this.root.keys.length===0}findLeaf(t,e){for(;!t.leaf;){let r=0;for(;r<t.keys.length&&this.compare(e,t.keys[r])>=0;)r++;t=t.children[r];}return t}insertNonFull(t,e){if(t.leaf){t.keys.push(e),t.keys.sort(this.compare);return}let r=0;for(;r<t.keys.length&&this.compare(e,t.keys[r])>=0;)r++;t.children[r].keys.length===2*this.t-1&&(this.splitChild(t,r),this.compare(e,t.keys[r])>=0&&r++),this.insertNonFull(t.children[r],e);}splitChild(t,e){let r=t.children[e],i=new b(r.leaf),s=this.t;if(r.leaf)i.keys=r.keys.splice(s),t.keys.splice(e,0,i.keys[0]),i.next=r.next,r.next=i;else {let o=r.keys[s];i.keys=r.keys.splice(s+1),r.keys.splice(s),i.children=r.children.splice(s+1),t.keys.splice(e,0,o);}t.children.splice(e+1,0,i);}deleteFromNode(t,e){if(t.leaf){t.keys=t.keys.filter(i=>this.compare(i,e)!==0);return}let r=0;for(;r<t.keys.length&&this.compare(e,t.keys[r])>=0;)r++;this.deleteFromNode(t.children[r],e),t.children[r].keys.length<this.t-1&&this.rebalance(t,r);}rebalance(t,e){let r=t.children[e],i=e>0?t.children[e-1]:null,s=e<t.children.length-1?t.children[e+1]:null;if(i&&i.keys.length>=this.t){r.keys.unshift(i.keys.pop()),t.keys[e-1]=r.keys[0];return}if(s&&s.keys.length>=this.t){r.keys.push(s.keys.shift()),t.keys[e]=s.keys[0];return}i?(i.keys.push(...r.keys),i.next=r.next,t.keys.splice(e-1,1),t.children.splice(e,1)):s&&(r.keys.push(...s.keys),r.next=s.next,t.keys.splice(e,1),t.children.splice(e+1,1));}};var y=class{keys=[];children=[];leaf;constructor(t){this.leaf=t;}},zt=class{root;t;compare;constructor(t,e){if(t<2)throw new Error("BTree minimum degree must be >= 2");this.t=t,this.root=new y(true),this.compare=e??((r,i)=>r<i?-1:r>i?1:0);}search(t){return this.searchNode(this.root,t)}insert(t){let e=this.root;if(e.keys.length===2*this.t-1){let r=new y(false);r.children[0]=e,this.splitChild(r,0),this.root=r,this.insertNonFull(r,t);}else this.insertNonFull(e,t);}delete(t){this.deleteFromNode(this.root,t),this.root.keys.length===0&&!this.root.leaf&&(this.root=this.root.children[0]);}traverse(){let t=[];return this.traverseNode(this.root,t),t}clear(){this.root=new y(true);}isEmpty(){return this.root.keys.length===0}searchNode(t,e){let r=0;for(;r<t.keys.length&&this.compare(e,t.keys[r])>0;)r++;return r<t.keys.length&&this.compare(e,t.keys[r])===0?true:t.leaf?false:this.searchNode(t.children[r],e)}insertNonFull(t,e){let r=t.keys.length-1;if(t.leaf){for(t.keys.push(e);r>=0&&this.compare(e,t.keys[r])<0;)t.keys[r+1]=t.keys[r],r--;t.keys[r+1]=e;}else {for(;r>=0&&this.compare(e,t.keys[r])<0;)r--;r++,t.children[r].keys.length===2*this.t-1&&(this.splitChild(t,r),this.compare(e,t.keys[r])>0&&r++),this.insertNonFull(t.children[r],e);}}splitChild(t,e){let r=this.t,i=t.children[e],s=new y(i.leaf);s.keys=i.keys.splice(r);let o=i.keys.pop();i.leaf||(s.children=i.children.splice(r)),t.children.splice(e+1,0,s),t.keys.splice(e,0,o);}deleteFromNode(t,e){let r=this.findKey(t,e);if(r<t.keys.length&&this.compare(t.keys[r],e)===0)t.leaf?t.keys.splice(r,1):this.deleteInternalNode(t,e,r);else {if(t.leaf)return;t.children[r].keys.length<this.t&&this.fill(t,r);let s=r<t.keys.length&&this.compare(t.keys[r],e)<0?r+1:r;this.deleteFromNode(t.children[s],e);}}deleteInternalNode(t,e,r){let i=t.children[r],s=t.children[r+1];if(i.keys.length>=this.t){let o=this.getPredecessor(i);t.keys[r]=o,this.deleteFromNode(i,o);}else if(s.keys.length>=this.t){let o=this.getSuccessor(s);t.keys[r]=o,this.deleteFromNode(s,o);}else this.merge(t,r),this.deleteFromNode(i,e);}fill(t,e){e>0&&t.children[e-1].keys.length>=this.t?this.borrowFromPrev(t,e):e<t.children.length-1&&t.children[e+1].keys.length>=this.t?this.borrowFromNext(t,e):e<t.children.length-1?this.merge(t,e):this.merge(t,e-1);}borrowFromPrev(t,e){let r=t.children[e],i=t.children[e-1];r.keys.unshift(t.keys[e-1]),t.keys[e-1]=i.keys.pop(),i.leaf||r.children.unshift(i.children.pop());}borrowFromNext(t,e){let r=t.children[e],i=t.children[e+1];r.keys.push(t.keys[e]),t.keys[e]=i.keys.shift(),i.leaf||r.children.push(i.children.shift());}merge(t,e){let r=t.children[e],i=t.children[e+1];r.keys.push(t.keys[e],...i.keys),r.leaf||r.children.push(...i.children),t.keys.splice(e,1),t.children.splice(e+1,1);}findKey(t,e){let r=0;for(;r<t.keys.length&&this.compare(t.keys[r],e)<0;)r++;return r}getPredecessor(t){for(;!t.leaf;)t=t.children[t.children.length-1];return t.keys[t.keys.length-1]}getSuccessor(t){for(;!t.leaf;)t=t.children[0];return t.keys[0]}traverseNode(t,e){let r=0;for(;r<t.keys.length;r++)t.leaf||this.traverseNode(t.children[r],e),e.push(t.keys[r]);t.leaf||this.traverseNode(t.children[r],e);}};var g=class{children=new Map;isEndOfWord=false},qt=class{root=new g;insert(t){let e=this.root,r=t;for(;r.length>0;){let i=false;for(let[s,o]of e.children){let a=this.commonPrefix(s,r);if(a.length===0)continue;if(a.length===s.length){e=o,r=r.slice(a.length),i=true;break}let h=s.slice(a.length),u=r.slice(a.length),c=new g;if(c.isEndOfWord=false,e.children.delete(s),e.children.set(a,c),c.children.set(h,o),u.length>0){let T=new g;T.isEndOfWord=true,c.children.set(u,T);}else c.isEndOfWord=true;return}if(!i){let s=new g;s.isEndOfWord=true,e.children.set(r,s);return}}e.isEndOfWord=true;}search(t){let e=this.findNode(t,true);return !!e&&e.isEndOfWord}startsWith(t){return !!this.findNode(t,false)}delete(t){this.deleteHelper(this.root,t);}clear(){this.root=new g;}isEmpty(){return this.root.children.size===0}findNode(t,e){let r=this.root,i=t;for(;i.length>0;){let s=false;for(let[o,a]of r.children){if(i.startsWith(o)){i=i.slice(o.length),r=a,s=true;break}if(!e&&o.startsWith(i))return a}if(!s)return null}return r}deleteHelper(t,e){if(e.length===0)return t.isEndOfWord?(t.isEndOfWord=false,t.children.size===0):false;for(let[r,i]of t.children){if(!e.startsWith(r))continue;if(this.deleteHelper(i,e.slice(r.length))){if(t.children.delete(r),t.children.size===1&&!t.isEndOfWord){let o=t.children.entries().next().value;if(o){let[a,h]=o;t.children.clear(),t.children.set(r+a,h);}}return t.children.size===0&&!t.isEndOfWord}return false}return false}commonPrefix(t,e){let r=0;for(;r<t.length&&r<e.length&&t[r]===e[r];)r++;return t.slice(0,r)}};var $=class{char;isEndOfWord=false;left=null;equal=null;right=null;constructor(t){this.char=t;}},Ft=class{root=null;insert(t){t.length!==0&&(this.root=this.insertNode(this.root,t,0));}search(t){if(t.length===0)return false;let e=this.searchNode(this.root,t,0);return !!e&&e.isEndOfWord}startsWith(t){return t.length===0?true:!!this.searchNode(this.root,t,0)}delete(t){t.length!==0&&(this.root=this.deleteNode(this.root,t,0));}clear(){this.root=null;}isEmpty(){return this.root===null}insertNode(t,e,r){let i=e[r];return t||(t=new $(i)),i<t.char?t.left=this.insertNode(t.left,e,r):i>t.char?t.right=this.insertNode(t.right,e,r):r+1===e.length?t.isEndOfWord=true:t.equal=this.insertNode(t.equal,e,r+1),t}searchNode(t,e,r){if(!t)return null;let i=e[r];return i<t.char?this.searchNode(t.left,e,r):i>t.char?this.searchNode(t.right,e,r):r+1===e.length?t:this.searchNode(t.equal,e,r+1)}deleteNode(t,e,r){if(!t)return null;let i=e[r];if(i<t.char)t.left=this.deleteNode(t.left,e,r);else if(i>t.char)t.right=this.deleteNode(t.right,e,r);else if(r+1===e.length?t.isEndOfWord=false:t.equal=this.deleteNode(t.equal,e,r+1),!t.isEndOfWord&&!t.left&&!t.equal&&!t.right)return null;return t}};var N=class{children=new Map;isEndOfWord=false},Kt=class{root=new N;insert(t){let e=this.root;for(let r of t)e.children.has(r)||e.children.set(r,new N),e=e.children.get(r);e.isEndOfWord=true;}search(t){let e=this.findNode(t);return !!e&&e.isEndOfWord}startsWith(t){return !!this.findNode(t)}delete(t){this.deleteHelper(this.root,t,0);}clear(){this.root=new N;}isEmpty(){return this.root.children.size===0}findNode(t){let e=this.root;for(let r of t){let i=e.children.get(r);if(!i)return null;e=i;}return e}deleteHelper(t,e,r){if(r===e.length)return t.isEndOfWord?(t.isEndOfWord=false,t.children.size===0):false;let i=e[r],s=t.children.get(i);return s&&this.deleteHelper(s,e,r+1)?(t.children.delete(i),t.children.size===0&&!t.isEndOfWord):false}};var Vt=class{n;tree;constructor(t){if(typeof t=="number"){if(t<=0)throw new Error("FenwickTree size must be > 0");this.n=t,this.tree=new Array(this.n+1).fill(0);}else {if(t.length===0)throw new Error("FenwickTree array must not be empty");this.n=t.length,this.tree=new Array(this.n+1).fill(0);for(let e=0;e<this.n;e++)this.add(e,t[e]);}}add(t,e){if(t<0||t>=this.n)throw new Error("Index out of bounds");let r=t+1;for(;r<=this.n;)this.tree[r]+=e,r+=r&-r;}sum(t){if(t<0||t>=this.n)throw new Error("Index out of bounds");let e=0,r=t+1;for(;r>0;)e+=this.tree[r],r-=r&-r;return e}rangeSum(t,e){if(t<0||e>=this.n||t>e)throw new Error("Invalid range");return this.sum(e)-(t>0?this.sum(t-1):0)}size(){return this.n}clear(){this.tree.fill(0);}};var H=class{interval;max;left=null;right=null;constructor(t){if(t.low>t.high)throw new Error("Invalid interval: low > high");this.interval=t,this.max=t.high;}},Dt=class{root=null;insert(t){this.root=this.insertNode(this.root,t);}delete(t){this.root=this.deleteNode(this.root,t);}search(t){return this.searchAny(this.root,t)!==null}searchAll(t){let e=[];return this.searchAllFrom(this.root,t,e),e}traverse(){let t=[];return this.inOrder(this.root,t),t}clear(){this.root=null;}isEmpty(){return this.root===null}insertNode(t,e){return t?(e.low<t.interval.low?t.left=this.insertNode(t.left,e):t.right=this.insertNode(t.right,e),t.max=Math.max(t.max,e.high,t.left?.max??-1/0,t.right?.max??-1/0),t):new H(e)}deleteNode(t,e){if(!t)return null;if(e.low===t.interval.low&&e.high===t.interval.high){if(!t.left)return t.right;if(!t.right)return t.left;let r=this.minNode(t.right);t.interval=r.interval,t.right=this.deleteNode(t.right,r.interval);}else e.low<t.interval.low?t.left=this.deleteNode(t.left,e):t.right=this.deleteNode(t.right,e);return t.max=Math.max(t.interval.high,t.left?.max??-1/0,t.right?.max??-1/0),t}searchAny(t,e){return t?this.overlaps(t.interval,e)?t:t.left&&t.left.max>=e.low?this.searchAny(t.left,e):this.searchAny(t.right,e):null}searchAllFrom(t,e,r){t&&(this.overlaps(t.interval,e)&&r.push(t.interval),t.left&&t.left.max>=e.low&&this.searchAllFrom(t.left,e,r),t.right&&t.interval.low<=e.high&&this.searchAllFrom(t.right,e,r));}overlaps(t,e){return t.low<=e.high&&e.low<=t.high}minNode(t){for(;t.left;)t=t.left;return t}inOrder(t,e){t&&(this.inOrder(t.left,e),e.push(t.interval),this.inOrder(t.right,e));}};var jt=class{tree;data;n;merge;identity;constructor(t,e,r){if(t.length===0)throw new Error("SegmentTree requires a non-empty array");this.data=[...t],this.n=t.length,this.merge=e,this.identity=r,this.tree=new Array(4*this.n),this.build(0,0,this.n-1);}query(t,e){if(t<0||e>=this.n||t>e)throw new Error("Invalid query range");return this.queryRange(0,0,this.n-1,t,e)}update(t,e){if(t<0||t>=this.n)throw new Error("Index out of bounds");this.data[t]=e,this.updatePoint(0,0,this.n-1,t,e);}toArray(){return [...this.data]}size(){return this.n}build(t,e,r){if(e===r){this.tree[t]=this.data[e];return}let i=Math.floor((e+r)/2),s=t*2+1,o=t*2+2;this.build(s,e,i),this.build(o,i+1,r),this.tree[t]=this.merge(this.tree[s],this.tree[o]);}queryRange(t,e,r,i,s){if(s<e||r<i)return this.identity;if(i<=e&&r<=s)return this.tree[t];let o=Math.floor((e+r)/2),a=t*2+1,h=t*2+2,u=this.queryRange(a,e,o,i,s),c=this.queryRange(h,o+1,r,i,s);return this.merge(u,c)}updatePoint(t,e,r,i,s){if(e===r){this.tree[t]=s;return}let o=Math.floor((e+r)/2),a=t*2+1,h=t*2+2;i<=o?this.updatePoint(a,e,o,i,s):this.updatePoint(h,o+1,r,i,s),this.tree[t]=this.merge(this.tree[a],this.tree[h]);}};var Fs=(n,t,e)=>{e();};var Yt=n=>new l(`Invalid ${n.path}: ${n.value}`,400,{code:"INVALID_ID"}),Zt=n=>{let t=n.keyValue?JSON.stringify(n.keyValue):"duplicate value";return new l(`Duplicate field value: ${t}`,400,{code:"DUPLICATE_FIELD"})},Gt=n=>{let t=Object.values(n.errors).map(e=>e.message);return new l("Invalid input data",400,{code:"VALIDATION_ERROR",details:t})},te=()=>new l("Invalid token. Please log in again.",401),ee=()=>new l("Your token has expired. Please log in again.",401),$s=(n=false)=>(t,e,r,i)=>{let s;return t instanceof l?s=t:t instanceof Error?(s=new l(t.message,500),s.isOperational=false):(s=new l("Internal Server Error",500),s.isOperational=false),t&&t.name==="CastError"&&(s=Yt(t)),t&&typeof t=="object"&&t.code===11e3&&(s=Zt(t)),t&&t.name==="ValidationError"&&(s=Gt(t)),t?.name==="JsonWebTokenError"&&(s=te()),t?.name==="TokenExpiredError"&&(s=ee()),s.isOperational?f.danger("Operational error",{message:s.message}):f.danger("Programming error",t),n?d.send(r,{success:false,statusCode:s.statusCode,message:s.isOperational?s.message:"Something went wrong"}):d.send(r,{success:false,statusCode:s.statusCode,message:s.message,data:{stack:t?.stack,details:s.details}})};var Ws=n=>(t,e,r)=>{let{error:i}=n.validate(t.body);if(i)return r(i);r();};var $t=class{model;resourceName;constructor(t,e){this.model=t,this.resourceName=e;}async create(t){return await this.model.create(t)}async findAll(){return this.model.find()}async findById(t){let e=await this.model.findById(t);if(!e)throw new l(`${this.resourceName} not found`,404,{code:`${this.resourceName.toUpperCase()}_NOT_FOUND`});return e}async updateById(t,e){let r=await this.model.findByIdAndUpdate(t,e,{new:true,runValidators:true});if(!r)throw new l(`${this.resourceName} not found`,404,{code:`${this.resourceName.toUpperCase()}_NOT_FOUND`});return r}async deleteById(t){let e=await this.model.findByIdAndDelete(t);if(!e)throw new l(`${this.resourceName} not found`,404,{code:`${this.resourceName.toUpperCase()}_NOT_FOUND`});return e}};function rn(n){return n}function sn(n){return n*1e3}function nn(n){return n*6e4}function on(n){return n*36e5}function an(n){return n*864e5}function hn(n){return n/1e3}function ln(n){return n/6e4}function un(n){return n/36e5}function cn(n){return new Promise(t=>setTimeout(t,n))}
|
|
4
|
+
exports.APIFactory=B;exports.APIFeatures=L;exports.APIResponse=d;exports.AVLTree=Lt;exports.AdjacencyList=X;exports.AdjacencyMatrix=Y;exports.AppError=l;exports.AzureBlobService=W;exports.BPlusTree=Ot;exports.BTree=zt;exports.BaseService=$t;exports.BinaryHeap=z;exports.BinarySearchTree=It;exports.BinaryTree=Pt;exports.BloomFilter=ct;exports.CircularArray=_;exports.CircularLinkedList=lt;exports.CircularQueue=pt;exports.ConsistentHash=tt;exports.CountMinSketch=dt;exports.Deque=mt;exports.DirectedGraph=Z;exports.DisjointSetUnion=vt;exports.DoublyLinkedList=w;exports.DynamicArray=Q;exports.FenwickTree=Vt;exports.FibNode=q;exports.FibonacciHeap=nt;exports.GlobalErrorHandler=$s;exports.Graph=G;exports.HashMap=O;exports.HashSet=rt;exports.HyperLogLog=ft;exports.IntervalTree=Dt;exports.KDTree=Nt;exports.LFUCache=it;exports.LRUCache=st;exports.MaxHeap=ot;exports.MaxStack=kt;exports.MinHeap=at;exports.MinStack=Et;exports.MultiSet=bt;exports.Node=p;exports.OrderedSet=yt;exports.PairingHeap=ht;exports.PairingNode=F;exports.PriorityQueue=gt;exports.QuadTree=wt;exports.Queue=Tt;exports.RadixTree=qt;exports.RedBlackTree=Bt;exports.SegmentTree=jt;exports.Set=xt;exports.SinglyLinkedList=ut;exports.SparseTable=Rt;exports.SplayTree=Mt;exports.Stack=St;exports.StaticArray=J;exports.SuffixArray=At;exports.SuffixTree=Ct;exports.TernarySearchTree=Ft;exports.TreeNode=C;exports.Trie=Kt;exports.asyncHandler=m;exports.authMiddleware=Fs;exports.connectMongoDB=Re;exports.createAllowedOrigins=Qt;exports.createCorsOptions=Jt;exports.days=an;exports.errorToString=U;exports.hours=on;exports.loadEnv=Ie;exports.logger=f;exports.milliseconds=rn;exports.minutes=nn;exports.seconds=sn;exports.sleep=cn;exports.toHours=un;exports.toMinutes=ln;exports.toSeconds=hn;exports.validate=Ws;//# sourceMappingURL=index.cjs.map
|
|
5
5
|
//# sourceMappingURL=index.cjs.map
|