mirror of
https://github.com/JasonYANG170/IOTConnect-Web.git
synced 2024-11-27 14:16:34 +00:00
1 line
8.8 KiB
Plaintext
1 line
8.8 KiB
Plaintext
{"version":3,"sources":["container/ContainerBase/index.js","../../src/container/ContainerBase/index.ts"],"names":["Object","defineProperty","exports","value","ContainerIterator","Container","Base","constructor","iteratorType","this","equals","iter","_node","_length","length","size","empty"],"mappings":"AAAA;;AAEAA,OAAOC,eAAeC,SAAS,KAAc;IAC3CC,OAAO;;;AAETD,QAAQE,oBAAoBF,QAAQG,YAAYH,QAAQI,YAAY;;ACG9D,MAAgBF;IAkBpBG,YAAsBC,IAAY;QAChCC,KAAKD,eAAeA;ADrBpB;IC6BFE,OAAOC;QACL,OAAOF,KAAKG,MAAUD,EAAKC;ADrB3B;;;ACsEHV,QAAAE,oBAAAA;;AAEK,MAAgBE;IAAtBC;QAKYE,KAAAI,IAAU;AAmCtB;IA5BMC;QACF,OAAOL,KAAKI;ADnEZ;IC2EFE;QACE,OAAON,KAAKI;ADnEZ;IC2EFG;QACE,OAAOP,KAAKI,MAAY;ADnExB;;;AC4EHX,QAAAI,OAAAA;;AAEK,MAAgBD,kBAAqBC;;AAgG1CJ,QAAAG,YAAAA","file":"index.js","sourcesContent":["export class ContainerIterator {\n /**\n * @internal\n */\n constructor(iteratorType = 0 /* IteratorType.NORMAL */) {\n this.iteratorType = iteratorType;\n }\n /**\n * @param iter - The other iterator you want to compare.\n * @returns Whether this equals to obj.\n * @example\n * container.find(1).equals(container.end());\n */\n equals(iter) {\n return this._node === iter._node;\n }\n}\nexport class Base {\n constructor() {\n /**\n * @description Container's size.\n * @internal\n */\n this._length = 0;\n }\n /**\n * @returns The size of the container.\n * @example\n * const container = new Vector([1, 2]);\n * console.log(container.length); // 2\n */\n get length() {\n return this._length;\n }\n /**\n * @returns The size of the container.\n * @example\n * const container = new Vector([1, 2]);\n * console.log(container.size()); // 2\n */\n size() {\n return this._length;\n }\n /**\n * @returns Whether the container is empty.\n * @example\n * container.clear();\n * console.log(container.empty()); // true\n */\n empty() {\n return this._length === 0;\n }\n}\nexport class Container extends Base {\n}\n","/**\n * @description The iterator type including `NORMAL` and `REVERSE`.\n */\nexport const enum IteratorType {\n NORMAL = 0,\n REVERSE = 1\n}\n\nexport abstract class ContainerIterator<T> {\n /**\n * @description The container pointed to by the iterator.\n */\n abstract readonly container: Container<T>;\n /**\n * @internal\n */\n abstract _node: unknown;\n /**\n * @description Iterator's type.\n * @example\n * console.log(container.end().iteratorType === IteratorType.NORMAL); // true\n */\n readonly iteratorType: IteratorType;\n /**\n * @internal\n */\n protected constructor(iteratorType = IteratorType.NORMAL) {\n this.iteratorType = iteratorType;\n }\n /**\n * @param iter - The other iterator you want to compare.\n * @returns Whether this equals to obj.\n * @example\n * container.find(1).equals(container.end());\n */\n equals(iter: ContainerIterator<T>) {\n return this._node === iter._node;\n }\n /**\n * @description Pointers to element.\n * @returns The value of the pointer's element.\n * @example\n * const val = container.begin().pointer;\n */\n abstract get pointer(): T;\n /**\n * @description Set pointer's value (some containers are unavailable).\n * @param newValue - The new value you want to set.\n * @example\n * (<LinkList<number>>container).begin().pointer = 1;\n */\n abstract set pointer(newValue: T);\n /**\n * @description Move `this` iterator to pre.\n * @returns The iterator's self.\n * @example\n * const iter = container.find(1); // container = [0, 1]\n * const pre = iter.pre();\n * console.log(pre === iter); // true\n * console.log(pre.equals(iter)); // true\n * console.log(pre.pointer, iter.pointer); // 0, 0\n */\n abstract pre(): this;\n /**\n * @description Move `this` iterator to next.\n * @returns The iterator's self.\n * @example\n * const iter = container.find(1); // container = [1, 2]\n * const next = iter.next();\n * console.log(next === iter); // true\n * console.log(next.equals(iter)); // true\n * console.log(next.pointer, iter.pointer); // 2, 2\n */\n abstract next(): this;\n /**\n * @description Get a copy of itself.\n * @returns The copy of self.\n * @example\n * const iter = container.find(1); // container = [1, 2]\n * const next = iter.copy().next();\n * console.log(next === iter); // false\n * console.log(next.equals(iter)); // false\n * console.log(next.pointer, iter.pointer); // 2, 1\n */\n abstract copy(): ContainerIterator<T>;\n}\n\nexport abstract class Base {\n /**\n * @description Container's size.\n * @internal\n */\n protected _length = 0;\n /**\n * @returns The size of the container.\n * @example\n * const container = new Vector([1, 2]);\n * console.log(container.length); // 2\n */\n get length() {\n return this._length;\n }\n /**\n * @returns The size of the container.\n * @example\n * const container = new Vector([1, 2]);\n * console.log(container.size()); // 2\n */\n size() {\n return this._length;\n }\n /**\n * @returns Whether the container is empty.\n * @example\n * container.clear();\n * console.log(container.empty()); // true\n */\n empty() {\n return this._length === 0;\n }\n /**\n * @description Clear the container.\n * @example\n * container.clear();\n * console.log(container.empty()); // true\n */\n abstract clear(): void;\n}\n\nexport abstract class Container<T> extends Base {\n /**\n * @returns Iterator pointing to the beginning element.\n * @example\n * const begin = container.begin();\n * const end = container.end();\n * for (const it = begin; !it.equals(end); it.next()) {\n * doSomething(it.pointer);\n * }\n */\n abstract begin(): ContainerIterator<T>;\n /**\n * @returns Iterator pointing to the super end like c++.\n * @example\n * const begin = container.begin();\n * const end = container.end();\n * for (const it = begin; !it.equals(end); it.next()) {\n * doSomething(it.pointer);\n * }\n */\n abstract end(): ContainerIterator<T>;\n /**\n * @returns Iterator pointing to the end element.\n * @example\n * const rBegin = container.rBegin();\n * const rEnd = container.rEnd();\n * for (const it = rBegin; !it.equals(rEnd); it.next()) {\n * doSomething(it.pointer);\n * }\n */\n abstract rBegin(): ContainerIterator<T>;\n /**\n * @returns Iterator pointing to the super begin like c++.\n * @example\n * const rBegin = container.rBegin();\n * const rEnd = container.rEnd();\n * for (const it = rBegin; !it.equals(rEnd); it.next()) {\n * doSomething(it.pointer);\n * }\n */\n abstract rEnd(): ContainerIterator<T>;\n /**\n * @returns The first element of the container.\n */\n abstract front(): T | undefined;\n /**\n * @returns The last element of the container.\n */\n abstract back(): T | undefined;\n /**\n * @param element - The element you want to find.\n * @returns An iterator pointing to the element if found, or super end if not found.\n * @example\n * container.find(1).equals(container.end());\n */\n abstract find(element: T): ContainerIterator<T>;\n /**\n * @description Iterate over all elements in the container.\n * @param callback - Callback function like Array.forEach.\n * @example\n * container.forEach((element, index) => console.log(element, index));\n */\n abstract forEach(callback: (element: T, index: number, container: Container<T>) => void): void;\n /**\n * @description Gets the value of the element at the specified position.\n * @example\n * const val = container.getElementByPos(-1); // throw a RangeError\n */\n abstract getElementByPos(pos: number): T;\n /**\n * @description Removes the element at the specified position.\n * @param pos - The element's position you want to remove.\n * @returns The container length after erasing.\n * @example\n * container.eraseElementByPos(-1); // throw a RangeError\n */\n abstract eraseElementByPos(pos: number): number;\n /**\n * @description Removes element by iterator and move `iter` to next.\n * @param iter - The iterator you want to erase.\n * @returns The next iterator.\n * @example\n * container.eraseElementByIterator(container.begin());\n * container.eraseElementByIterator(container.end()); // throw a RangeError\n */\n abstract eraseElementByIterator(\n iter: ContainerIterator<T>\n ): ContainerIterator<T>;\n /**\n * @description Using for `for...of` syntax like Array.\n * @example\n * for (const element of container) {\n * console.log(element);\n * }\n */\n abstract [Symbol.iterator](): Generator<T, void>;\n}\n\n/**\n * @description The initial data type passed in when initializing the container.\n */\nexport type initContainer<T> = {\n size?: number | (() => number);\n length?: number;\n forEach: (callback: (el: T) => void) => void;\n}\n"]} |