-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.min.js
1 lines (1 loc) · 6.05 KB
/
index.min.js
1
var f=class{#t=null;#e=null;size=0;constructor(t){t&&this.addAll(t)}add(t=null){if(t===null)throw Error("'item' parameter not defined");if(this.size===0)this.#e=new l(t,null),this.#t=this.#e;else{let e=this.#e;this.#e=new l(t,null),e.next=this.#e}this.size++}addAll(t=null){if(t===null)throw Error("'items' parameter not defined");t.forEach(e=>this.add(e))}remove(t=null){if(t===null)throw Error("'item' parameter not defined");if(this.size===0)throw Error("can't remove an item from an empty list");let e=this.#t,s=this.#t;for(;s!=null;){if(s.data===t)return this.size===1?(this.#t=null,this.tail=null):s===this.#t?this.#t=this.#t.next:s===this.#e?(this.#e=e,this.#e.next=null):e.next=s.next,this.size--,!0;e=s,s=e.next}return!1}clear(){this.#t=null,this.#e=null,this.size=0}[Symbol.iterator](){let t=this.#t;return{next:()=>{if(t){let e=t.data;return t=t.next,{value:e,done:!1}}return{value:null,done:!0}}}}},l=class{data;next;constructor(t,e=null){this.data=t,this.next=e}};var d=class{capacity=0;items=new Map;dequeue=[];constructor(t=null){if(t===null)throw Error("'capacity' parameter not defined");this.capacity=t}get(t){let e=this.dequeue.indexOf(t);return e===-1?e:(this.dequeue.splice(e,1),this.dequeue.unshift(t),this.items.get(t))}put(t,e){if(this.get(t)!==-1){this.items.set(t,e);return}if(this.dequeue.length>this.capacity){let s=this.dequeue.pop();this.items.delete(s)}this.dequeue.unshift(t),this.items.set(t,e)}clear(){this.items=new Map,this.dequeue=[]}*keys(){for(let t of this.dequeue)yield t}*values(){for(let t of this.dequeue)yield this.items.get(t)}*entries(){for(let t of this.dequeue)yield[t,this.items.get(t)]}};var p=class{first=null;last=null;size=0;constructor(t){t&&this.enqueueAll(t)}enqueue(t=null){if(t===null)throw Error("'item' parameter not defined");if(this.size!==0){let e=this.last;this.last=new u(t,null),e.link=this.last}else this.first=new u(t,null),this.last=this.first;this.size++}enqueueAll(t=null){if(t===null)throw Error("'items' parameter not defined");t.forEach(e=>this.enqueue(e))}dequeue(){if(this.size===0)throw Error("can't dequeue an item from an empty queue");let t=this.first;return this.size===1?(this.first=null,this.last=null):this.first=t.link,this.size--,t.data}peek(){if(this.size===0)throw Error("can't peek an item from an empty stack");return this.first.data}clear(){this.first=null,this.last=null,this.size=0}[Symbol.iterator](){let t=this.first;return{next:()=>{if(t){let e=t.data;return t=t.link,{value:e,done:!1}}return{value:null,done:!0}}}}},u=class{data;link;constructor(t,e=null){this.data=t,this.link=e}};var a=class{values=[];size=0;constructor(t){t&&this.addAll(t)}add(t=null){if(t===null)throw Error("'item' parameter not defined");this.values.includes(t)||(this.values.push(t),this.size++)}addAll(t=null){if(t===null)throw Error("'items' parameter not defined");t.forEach(e=>this.add(e))}remove(t=null){if(t===null)throw Error("'item' parameter not defined");let e=this.values.indexOf(t);return e!==-1?(this.values=[...this.values.slice(0,e),...this.values.slice(e+1)],this.size--,!0):!1}clear(){this.values=[],this.size=0}[Symbol.iterator](){return this.values[Symbol.iterator]()}};function w(i,t=(s,n)=>s<n,e){let s=i.length;for(let n=0;n<s;n++){for(let r=0;r<s;r++)if(t(i[r+1],i[r])){let o=i[r];i[r]=i[r+1],i[r+1]=o}e&&e(i)}return i}function S(i,t=(s,n)=>s<n,e){let s=i.length;for(let n=1;n<s;n++){for(let r=n;r>0;r--)t(i[r],i[r-1])&&([i[r],i[r-1]]=[i[r-1],i[r]]);e&&e(i)}return i}function k(i,t,e){if(!(i.length<2))return typeof t!="function"&&(t=(s,n)=>s<n),h(i,0,i.length-1,t,e),i}var z=(i,t,e)=>{let s=i[t];i[t]=i[e],i[e]=s},E=(i,t,e,s,n)=>{let r=Math.floor((t+e)/2);for(;t<=e;){for(;s(i[t],i[r]);)t++;for(;s(i[r],i[e]);)e--;t<=e&&(z(i,t,e),t++,e--),n&&n(i)}return t},h=(i,t,e,s,n)=>{if(e-t<1)return;let r=E(i,t,e,s,n);t<r-1&&h(i,t,r-1,s,n),r<e&&h(i,r,e,s,n)};function q(i,t=(s,n)=>s<n,e){let s=i.length;for(let n=0;n<s;n++){let r=n;for(let o=n+1;o<s;o++)t(i[o],i[r])&&(r=o);n!==r&&([i[n],i[r]]=[i[r],i[n]]),e&&e(i)}return i}var m=class{top=null;size=0;constructor(t){t&&this.pushAll(t)}push(t=null){if(t===null)throw Error("'item' parameter not defined");if(this.size===0)this.top=new c(t,null);else{let e=this.top;this.top=new c(t,e)}this.size++}pushAll(t=null){if(t===null)throw Error("'items' parameter not defined");t.forEach(e=>this.push(e))}pop(){if(this.size===0)throw Error("can't pop an item from an empty stack");let t=this.top.data;return this.top=this.top.link,this.size--,t}peek(){if(this.size===0)throw Error("can't peek an item from an empty stack");return this.top.data}clear(){this.top=null,this.size=0}[Symbol.iterator](){let t=this.top;return{next:()=>{if(t){let e=t.data;return t=t.link,{value:e,done:!1}}return{value:null,done:!0}}}}},c=class{data;link;constructor(t,e=null){this.data=t,this.link=e}};var v=class{verticies=null;count=0;constructor(t=[]){this.verticies=new Map,t.forEach((e,s)=>{this.verticies.set(e,s)}),this.count=this.verticies.size}find(t){let e=this.verticies.get(t);if(e===void 0)throw Error(`Item: ${t} not found in the set`);return e}connected(t,e){return this.find(t)===this.find(e)}union(t,e){if(this.connected(t,e))return;let s=this.find(t),n=this.find(e);this.verticies.forEach((r,o)=>{r===s&&this.verticies.set(o,n)}),this.count--}sets(){let e=[...this.verticies.entries()].reduce((s,n)=>(s[n[1]]===void 0&&(s[n[1]]=[]),s[n[1]].push(n[0]),s),{});return Object.values(e)}};var x=class{verticies=null;count=0;constructor(t=[]){this.verticies=new Map,t.forEach(e=>{this.verticies.set(e,e)}),this.count=this.verticies.size}find(t){let e=t;for(;e!==this.verticies.get(e);)if(e=this.verticies.get(e),e===void 0)throw Error(`Item: ${t} not found in the set`);return e}connected(t,e){return this.find(t)===this.find(e)}union(t,e){if(this.connected(t,e))return;let s=this.find(t),n=this.find(e);this.verticies.set(s,n),this.count--}sets(){let e=[...this.verticies.entries()].reduce((s,n)=>{let r=this.verticies.get(n[1]);return s[r]===void 0&&(s[r]=[]),s[r].push(n[0]),s},{});return Object.values(e)}};export{w as BubbleSort,S as InsertionSort,d as LRUCache,f as LinkedList,p as Queue,v as QuickFind,k as QuickSort,x as QuickUnion,q as SelectionSort,a as Set,m as Stack};