data-structure-typed 1.46.2 → 1.46.4

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 (97) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +16 -16
  3. package/benchmark/report.html +1 -46
  4. package/benchmark/report.json +8 -389
  5. package/dist/cjs/data-structures/hash/hash-map.d.ts +31 -116
  6. package/dist/cjs/data-structures/hash/hash-map.js +127 -254
  7. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  8. package/dist/cjs/data-structures/hash/index.d.ts +0 -4
  9. package/dist/cjs/data-structures/hash/index.js +0 -4
  10. package/dist/cjs/data-structures/hash/index.js.map +1 -1
  11. package/dist/cjs/data-structures/queue/deque.d.ts +6 -74
  12. package/dist/cjs/data-structures/queue/deque.js +20 -142
  13. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  14. package/dist/cjs/types/data-structures/hash/hash-map.d.ts +5 -0
  15. package/dist/cjs/types/data-structures/hash/index.d.ts +0 -4
  16. package/dist/cjs/types/data-structures/hash/index.js +0 -4
  17. package/dist/cjs/types/data-structures/hash/index.js.map +1 -1
  18. package/dist/cjs/utils/utils.d.ts +1 -1
  19. package/dist/cjs/utils/utils.js +3 -3
  20. package/dist/cjs/utils/utils.js.map +1 -1
  21. package/dist/mjs/data-structures/hash/hash-map.d.ts +31 -116
  22. package/dist/mjs/data-structures/hash/hash-map.js +129 -257
  23. package/dist/mjs/data-structures/hash/index.d.ts +0 -4
  24. package/dist/mjs/data-structures/hash/index.js +0 -4
  25. package/dist/mjs/data-structures/queue/deque.d.ts +6 -74
  26. package/dist/mjs/data-structures/queue/deque.js +16 -140
  27. package/dist/mjs/types/data-structures/hash/hash-map.d.ts +5 -0
  28. package/dist/mjs/types/data-structures/hash/index.d.ts +0 -4
  29. package/dist/mjs/types/data-structures/hash/index.js +0 -4
  30. package/dist/mjs/utils/utils.d.ts +1 -1
  31. package/dist/mjs/utils/utils.js +1 -1
  32. package/dist/umd/data-structure-typed.js +169 -531
  33. package/dist/umd/data-structure-typed.min.js +1 -1
  34. package/dist/umd/data-structure-typed.min.js.map +1 -1
  35. package/package.json +4 -3
  36. package/src/data-structures/hash/hash-map.ts +154 -275
  37. package/src/data-structures/hash/index.ts +0 -4
  38. package/src/data-structures/queue/deque.ts +22 -161
  39. package/src/types/data-structures/hash/hash-map.ts +6 -0
  40. package/src/types/data-structures/hash/index.ts +0 -4
  41. package/src/utils/utils.ts +1 -1
  42. package/test/performance/data-structures/hash/hash-map.test.ts +86 -11
  43. package/test/performance/reportor.ts +6 -3
  44. package/test/unit/data-structures/hash/hash-map.test.ts +36 -5
  45. package/test/unit/data-structures/queue/deque.test.ts +28 -0
  46. package/dist/cjs/data-structures/hash/coordinate-map.d.ts +0 -44
  47. package/dist/cjs/data-structures/hash/coordinate-map.js +0 -63
  48. package/dist/cjs/data-structures/hash/coordinate-map.js.map +0 -1
  49. package/dist/cjs/data-structures/hash/coordinate-set.d.ts +0 -36
  50. package/dist/cjs/data-structures/hash/coordinate-set.js +0 -53
  51. package/dist/cjs/data-structures/hash/coordinate-set.js.map +0 -1
  52. package/dist/cjs/data-structures/hash/tree-map.d.ts +0 -2
  53. package/dist/cjs/data-structures/hash/tree-map.js +0 -7
  54. package/dist/cjs/data-structures/hash/tree-map.js.map +0 -1
  55. package/dist/cjs/data-structures/hash/tree-set.d.ts +0 -2
  56. package/dist/cjs/data-structures/hash/tree-set.js +0 -7
  57. package/dist/cjs/data-structures/hash/tree-set.js.map +0 -1
  58. package/dist/cjs/types/data-structures/hash/coordinate-map.d.ts +0 -1
  59. package/dist/cjs/types/data-structures/hash/coordinate-map.js +0 -3
  60. package/dist/cjs/types/data-structures/hash/coordinate-map.js.map +0 -1
  61. package/dist/cjs/types/data-structures/hash/coordinate-set.d.ts +0 -1
  62. package/dist/cjs/types/data-structures/hash/coordinate-set.js +0 -3
  63. package/dist/cjs/types/data-structures/hash/coordinate-set.js.map +0 -1
  64. package/dist/cjs/types/data-structures/hash/tree-map.d.ts +0 -1
  65. package/dist/cjs/types/data-structures/hash/tree-map.js +0 -3
  66. package/dist/cjs/types/data-structures/hash/tree-map.js.map +0 -1
  67. package/dist/cjs/types/data-structures/hash/tree-set.d.ts +0 -1
  68. package/dist/cjs/types/data-structures/hash/tree-set.js +0 -3
  69. package/dist/cjs/types/data-structures/hash/tree-set.js.map +0 -1
  70. package/dist/mjs/data-structures/hash/coordinate-map.d.ts +0 -44
  71. package/dist/mjs/data-structures/hash/coordinate-map.js +0 -58
  72. package/dist/mjs/data-structures/hash/coordinate-set.d.ts +0 -36
  73. package/dist/mjs/data-structures/hash/coordinate-set.js +0 -48
  74. package/dist/mjs/data-structures/hash/tree-map.d.ts +0 -2
  75. package/dist/mjs/data-structures/hash/tree-map.js +0 -2
  76. package/dist/mjs/data-structures/hash/tree-set.d.ts +0 -2
  77. package/dist/mjs/data-structures/hash/tree-set.js +0 -2
  78. package/dist/mjs/types/data-structures/hash/coordinate-map.d.ts +0 -1
  79. package/dist/mjs/types/data-structures/hash/coordinate-map.js +0 -1
  80. package/dist/mjs/types/data-structures/hash/coordinate-set.d.ts +0 -1
  81. package/dist/mjs/types/data-structures/hash/coordinate-set.js +0 -1
  82. package/dist/mjs/types/data-structures/hash/tree-map.d.ts +0 -1
  83. package/dist/mjs/types/data-structures/hash/tree-map.js +0 -1
  84. package/dist/mjs/types/data-structures/hash/tree-set.d.ts +0 -1
  85. package/dist/mjs/types/data-structures/hash/tree-set.js +0 -1
  86. package/src/data-structures/hash/coordinate-map.ts +0 -63
  87. package/src/data-structures/hash/coordinate-set.ts +0 -52
  88. package/src/data-structures/hash/tree-map.ts +0 -2
  89. package/src/data-structures/hash/tree-set.ts +0 -2
  90. package/src/types/data-structures/hash/coordinate-map.ts +0 -1
  91. package/src/types/data-structures/hash/coordinate-set.ts +0 -1
  92. package/src/types/data-structures/hash/tree-map.ts +0 -1
  93. package/src/types/data-structures/hash/tree-set.ts +0 -1
  94. package/test/performance/data-structures/hash/coordinate-map.test.ts +0 -0
  95. package/test/performance/data-structures/hash/coordinate-set.test.ts +0 -0
  96. package/test/unit/data-structures/hash/coordinate-map.test.ts +0 -74
  97. package/test/unit/data-structures/hash/coordinate-set.test.ts +0 -66
@@ -1,36 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- export declare class CoordinateSet extends Set<any> {
9
- constructor(joint?: string);
10
- protected _joint: string;
11
- get joint(): string;
12
- /**
13
- * The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
14
- * joining its elements with a specified separator.
15
- * @param {number[]} value - The parameter "value" is an array of numbers.
16
- * @returns The overridden `has` method is returning the result of calling the `has` method of the superclass, passing
17
- * in the joined value as an argument.
18
- */
19
- has(value: number[]): boolean;
20
- /**
21
- * The "add" function overrides the parent class's "add" function by joining the elements of the input array with a
22
- * specified delimiter before calling the parent class's "add" function.
23
- * @param {number[]} value - An array of numbers
24
- * @returns The overridden `add` method is returning the result of calling the `add` method of the superclass
25
- * (`super.add`) with the joined string representation of the `value` array (`value.join(this._joint)`).
26
- */
27
- add(value: number[]): this;
28
- /**
29
- * The function overrides the delete method and deletes an element from a Set by joining the elements of the input
30
- * array with a specified joint and then calling the delete method of the parent class.
31
- * @param {number[]} value - An array of numbers
32
- * @returns The `delete` method is returning the result of calling the `delete` method of the superclass, with the
33
- * `value` array joined together using the `_joint` property.
34
- */
35
- delete(value: number[]): boolean;
36
- }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CoordinateSet = void 0;
4
- /**
5
- * data-structure-typed
6
- *
7
- * @author Tyler Zeng
8
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
9
- * @license MIT License
10
- */
11
- class CoordinateSet extends Set {
12
- constructor(joint) {
13
- super();
14
- this._joint = '_';
15
- if (joint !== undefined)
16
- this._joint = joint;
17
- }
18
- get joint() {
19
- return this._joint;
20
- }
21
- /**
22
- * The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
23
- * joining its elements with a specified separator.
24
- * @param {number[]} value - The parameter "value" is an array of numbers.
25
- * @returns The overridden `has` method is returning the result of calling the `has` method of the superclass, passing
26
- * in the joined value as an argument.
27
- */
28
- has(value) {
29
- return super.has(value.join(this._joint));
30
- }
31
- /**
32
- * The "add" function overrides the parent class's "add" function by joining the elements of the input array with a
33
- * specified delimiter before calling the parent class's "add" function.
34
- * @param {number[]} value - An array of numbers
35
- * @returns The overridden `add` method is returning the result of calling the `add` method of the superclass
36
- * (`super.add`) with the joined string representation of the `value` array (`value.join(this._joint)`).
37
- */
38
- add(value) {
39
- return super.add(value.join(this._joint));
40
- }
41
- /**
42
- * The function overrides the delete method and deletes an element from a Set by joining the elements of the input
43
- * array with a specified joint and then calling the delete method of the parent class.
44
- * @param {number[]} value - An array of numbers
45
- * @returns The `delete` method is returning the result of calling the `delete` method of the superclass, with the
46
- * `value` array joined together using the `_joint` property.
47
- */
48
- delete(value) {
49
- return super.delete(value.join(this._joint));
50
- }
51
- }
52
- exports.CoordinateSet = CoordinateSet;
53
- //# sourceMappingURL=coordinate-set.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"coordinate-set.js","sourceRoot":"","sources":["../../../../src/data-structures/hash/coordinate-set.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,MAAa,aAAc,SAAQ,GAAQ;IACzC,YAAY,KAAc;QACxB,KAAK,EAAE,CAAC;QAIA,WAAM,GAAG,GAAG,CAAC;QAHrB,IAAI,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IAC/C,CAAC;IAID,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;;;OAMG;IACM,GAAG,CAAC,KAAe;QAC1B,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACM,GAAG,CAAC,KAAe;QAC1B,OAAO,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;OAMG;IACM,MAAM,CAAC,KAAe;QAC7B,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/C,CAAC;CACF;AA5CD,sCA4CC"}
@@ -1,2 +0,0 @@
1
- export declare class TreeMap {
2
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TreeMap = void 0;
4
- class TreeMap {
5
- }
6
- exports.TreeMap = TreeMap;
7
- //# sourceMappingURL=tree-map.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tree-map.js","sourceRoot":"","sources":["../../../../src/data-structures/hash/tree-map.ts"],"names":[],"mappings":";;;AAAA,MAAa,OAAO;CACnB;AADD,0BACC"}
@@ -1,2 +0,0 @@
1
- export declare class TreeSet {
2
- }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TreeSet = void 0;
4
- class TreeSet {
5
- }
6
- exports.TreeSet = TreeSet;
7
- //# sourceMappingURL=tree-set.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tree-set.js","sourceRoot":"","sources":["../../../../src/data-structures/hash/tree-set.ts"],"names":[],"mappings":";;;AAAA,MAAa,OAAO;CACnB;AADD,0BACC"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=coordinate-map.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"coordinate-map.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/hash/coordinate-map.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=coordinate-set.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"coordinate-set.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/hash/coordinate-set.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=tree-map.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tree-map.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/hash/tree-map.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=tree-set.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tree-set.js","sourceRoot":"","sources":["../../../../../src/types/data-structures/hash/tree-set.ts"],"names":[],"mappings":""}
@@ -1,44 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- export declare class CoordinateMap<V> extends Map<any, V> {
9
- constructor(joint?: string);
10
- protected _joint: string;
11
- get joint(): string;
12
- /**
13
- * The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
14
- * key array with a specified delimiter.
15
- * @param {number[]} key - The parameter "key" is an array of numbers.
16
- * @returns The `has` method is being overridden to return the result of calling the `has` method of the superclass
17
- * (`super.has`) with the `key` array joined together using the `_joint` property.
18
- */
19
- has(key: number[]): boolean;
20
- /**
21
- * The function overrides the set method of a Map object to convert the key from an array to a string using a specified
22
- * delimiter before calling the original set method.
23
- * @param {number[]} key - The key parameter is an array of numbers.
24
- * @param {V} value - The value parameter is the value that you want to associate with the specified key.
25
- * @returns The `set` method is returning the result of calling the `set` method of the superclass
26
- * (`super.set(key.join(this._joint), value)`).
27
- */
28
- set(key: number[], value: V): this;
29
- /**
30
- * The function overrides the get method to join the key array with a specified joint and then calls the super get
31
- * method.
32
- * @param {number[]} key - An array of numbers
33
- * @returns The code is returning the value associated with the specified key in the map.
34
- */
35
- get(key: number[]): V | undefined;
36
- /**
37
- * The function overrides the delete method and joins the key array using a specified joint character before calling
38
- * the super delete method.
39
- * @param {number[]} key - An array of numbers that represents the key to be deleted.
40
- * @returns The `delete` method is returning the result of calling the `delete` method on the superclass, with the
41
- * `key` array joined together using the `_joint` property.
42
- */
43
- delete(key: number[]): boolean;
44
- }
@@ -1,58 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- export class CoordinateMap extends Map {
9
- constructor(joint) {
10
- super();
11
- if (joint !== undefined)
12
- this._joint = joint;
13
- }
14
- _joint = '_';
15
- get joint() {
16
- return this._joint;
17
- }
18
- /**
19
- * The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
20
- * key array with a specified delimiter.
21
- * @param {number[]} key - The parameter "key" is an array of numbers.
22
- * @returns The `has` method is being overridden to return the result of calling the `has` method of the superclass
23
- * (`super.has`) with the `key` array joined together using the `_joint` property.
24
- */
25
- has(key) {
26
- return super.has(key.join(this._joint));
27
- }
28
- /**
29
- * The function overrides the set method of a Map object to convert the key from an array to a string using a specified
30
- * delimiter before calling the original set method.
31
- * @param {number[]} key - The key parameter is an array of numbers.
32
- * @param {V} value - The value parameter is the value that you want to associate with the specified key.
33
- * @returns The `set` method is returning the result of calling the `set` method of the superclass
34
- * (`super.set(key.join(this._joint), value)`).
35
- */
36
- set(key, value) {
37
- return super.set(key.join(this._joint), value);
38
- }
39
- /**
40
- * The function overrides the get method to join the key array with a specified joint and then calls the super get
41
- * method.
42
- * @param {number[]} key - An array of numbers
43
- * @returns The code is returning the value associated with the specified key in the map.
44
- */
45
- get(key) {
46
- return super.get(key.join(this._joint));
47
- }
48
- /**
49
- * The function overrides the delete method and joins the key array using a specified joint character before calling
50
- * the super delete method.
51
- * @param {number[]} key - An array of numbers that represents the key to be deleted.
52
- * @returns The `delete` method is returning the result of calling the `delete` method on the superclass, with the
53
- * `key` array joined together using the `_joint` property.
54
- */
55
- delete(key) {
56
- return super.delete(key.join(this._joint));
57
- }
58
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- export declare class CoordinateSet extends Set<any> {
9
- constructor(joint?: string);
10
- protected _joint: string;
11
- get joint(): string;
12
- /**
13
- * The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
14
- * joining its elements with a specified separator.
15
- * @param {number[]} value - The parameter "value" is an array of numbers.
16
- * @returns The overridden `has` method is returning the result of calling the `has` method of the superclass, passing
17
- * in the joined value as an argument.
18
- */
19
- has(value: number[]): boolean;
20
- /**
21
- * The "add" function overrides the parent class's "add" function by joining the elements of the input array with a
22
- * specified delimiter before calling the parent class's "add" function.
23
- * @param {number[]} value - An array of numbers
24
- * @returns The overridden `add` method is returning the result of calling the `add` method of the superclass
25
- * (`super.add`) with the joined string representation of the `value` array (`value.join(this._joint)`).
26
- */
27
- add(value: number[]): this;
28
- /**
29
- * The function overrides the delete method and deletes an element from a Set by joining the elements of the input
30
- * array with a specified joint and then calling the delete method of the parent class.
31
- * @param {number[]} value - An array of numbers
32
- * @returns The `delete` method is returning the result of calling the `delete` method of the superclass, with the
33
- * `value` array joined together using the `_joint` property.
34
- */
35
- delete(value: number[]): boolean;
36
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- export class CoordinateSet extends Set {
9
- constructor(joint) {
10
- super();
11
- if (joint !== undefined)
12
- this._joint = joint;
13
- }
14
- _joint = '_';
15
- get joint() {
16
- return this._joint;
17
- }
18
- /**
19
- * The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
20
- * joining its elements with a specified separator.
21
- * @param {number[]} value - The parameter "value" is an array of numbers.
22
- * @returns The overridden `has` method is returning the result of calling the `has` method of the superclass, passing
23
- * in the joined value as an argument.
24
- */
25
- has(value) {
26
- return super.has(value.join(this._joint));
27
- }
28
- /**
29
- * The "add" function overrides the parent class's "add" function by joining the elements of the input array with a
30
- * specified delimiter before calling the parent class's "add" function.
31
- * @param {number[]} value - An array of numbers
32
- * @returns The overridden `add` method is returning the result of calling the `add` method of the superclass
33
- * (`super.add`) with the joined string representation of the `value` array (`value.join(this._joint)`).
34
- */
35
- add(value) {
36
- return super.add(value.join(this._joint));
37
- }
38
- /**
39
- * The function overrides the delete method and deletes an element from a Set by joining the elements of the input
40
- * array with a specified joint and then calling the delete method of the parent class.
41
- * @param {number[]} value - An array of numbers
42
- * @returns The `delete` method is returning the result of calling the `delete` method of the superclass, with the
43
- * `value` array joined together using the `_joint` property.
44
- */
45
- delete(value) {
46
- return super.delete(value.join(this._joint));
47
- }
48
- }
@@ -1,2 +0,0 @@
1
- export declare class TreeMap {
2
- }
@@ -1,2 +0,0 @@
1
- export class TreeMap {
2
- }
@@ -1,2 +0,0 @@
1
- export declare class TreeSet {
2
- }
@@ -1,2 +0,0 @@
1
- export class TreeSet {
2
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,63 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- export class CoordinateMap<V> extends Map<any, V> {
9
- constructor(joint?: string) {
10
- super();
11
- if (joint !== undefined) this._joint = joint;
12
- }
13
-
14
- protected _joint = '_';
15
-
16
- get joint(): string {
17
- return this._joint;
18
- }
19
-
20
- /**
21
- * The "has" function overrides the base class's "has" function and checks if a key exists in the map by joining the
22
- * key array with a specified delimiter.
23
- * @param {number[]} key - The parameter "key" is an array of numbers.
24
- * @returns The `has` method is being overridden to return the result of calling the `has` method of the superclass
25
- * (`super.has`) with the `key` array joined together using the `_joint` property.
26
- */
27
- override has(key: number[]) {
28
- return super.has(key.join(this._joint));
29
- }
30
-
31
- /**
32
- * The function overrides the set method of a Map object to convert the key from an array to a string using a specified
33
- * delimiter before calling the original set method.
34
- * @param {number[]} key - The key parameter is an array of numbers.
35
- * @param {V} value - The value parameter is the value that you want to associate with the specified key.
36
- * @returns The `set` method is returning the result of calling the `set` method of the superclass
37
- * (`super.set(key.join(this._joint), value)`).
38
- */
39
- override set(key: number[], value: V) {
40
- return super.set(key.join(this._joint), value);
41
- }
42
-
43
- /**
44
- * The function overrides the get method to join the key array with a specified joint and then calls the super get
45
- * method.
46
- * @param {number[]} key - An array of numbers
47
- * @returns The code is returning the value associated with the specified key in the map.
48
- */
49
- override get(key: number[]) {
50
- return super.get(key.join(this._joint));
51
- }
52
-
53
- /**
54
- * The function overrides the delete method and joins the key array using a specified joint character before calling
55
- * the super delete method.
56
- * @param {number[]} key - An array of numbers that represents the key to be deleted.
57
- * @returns The `delete` method is returning the result of calling the `delete` method on the superclass, with the
58
- * `key` array joined together using the `_joint` property.
59
- */
60
- override delete(key: number[]) {
61
- return super.delete(key.join(this._joint));
62
- }
63
- }
@@ -1,52 +0,0 @@
1
- /**
2
- * data-structure-typed
3
- *
4
- * @author Tyler Zeng
5
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
- * @license MIT License
7
- */
8
- export class CoordinateSet extends Set<any> {
9
- constructor(joint?: string) {
10
- super();
11
- if (joint !== undefined) this._joint = joint;
12
- }
13
-
14
- protected _joint = '_';
15
-
16
- get joint(): string {
17
- return this._joint;
18
- }
19
-
20
- /**
21
- * The "has" function overrides the "has" method of the superclass and checks if a value exists in an array after
22
- * joining its elements with a specified separator.
23
- * @param {number[]} value - The parameter "value" is an array of numbers.
24
- * @returns The overridden `has` method is returning the result of calling the `has` method of the superclass, passing
25
- * in the joined value as an argument.
26
- */
27
- override has(value: number[]) {
28
- return super.has(value.join(this._joint));
29
- }
30
-
31
- /**
32
- * The "add" function overrides the parent class's "add" function by joining the elements of the input array with a
33
- * specified delimiter before calling the parent class's "add" function.
34
- * @param {number[]} value - An array of numbers
35
- * @returns The overridden `add` method is returning the result of calling the `add` method of the superclass
36
- * (`super.add`) with the joined string representation of the `value` array (`value.join(this._joint)`).
37
- */
38
- override add(value: number[]) {
39
- return super.add(value.join(this._joint));
40
- }
41
-
42
- /**
43
- * The function overrides the delete method and deletes an element from a Set by joining the elements of the input
44
- * array with a specified joint and then calling the delete method of the parent class.
45
- * @param {number[]} value - An array of numbers
46
- * @returns The `delete` method is returning the result of calling the `delete` method of the superclass, with the
47
- * `value` array joined together using the `_joint` property.
48
- */
49
- override delete(value: number[]) {
50
- return super.delete(value.join(this._joint));
51
- }
52
- }
@@ -1,2 +0,0 @@
1
- export class TreeMap {
2
- }
@@ -1,2 +0,0 @@
1
- export class TreeSet {
2
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,74 +0,0 @@
1
- import { CoordinateMap } from '../../../../src';
2
-
3
- describe('CoordinateMap', () => {
4
- it('should set and get values correctly', () => {
5
- const coordinateMap = new CoordinateMap<string>();
6
- const key = [1, 2, 3];
7
- const value = 'TestValue';
8
-
9
- coordinateMap.set(key, value);
10
- const retrievedValue = coordinateMap.get(key);
11
-
12
- expect(retrievedValue).toBe(value);
13
- });
14
-
15
- it('should return true when key exists', () => {
16
- const coordinateMap = new CoordinateMap<string>();
17
- const key = [1, 2, 3];
18
- const value = 'TestValue';
19
-
20
- coordinateMap.set(key, value);
21
-
22
- expect(coordinateMap.has(key)).toBe(true);
23
- });
24
-
25
- it('should return false when key does not exist', () => {
26
- const coordinateMap = new CoordinateMap<string>();
27
- const key = [1, 2, 3];
28
-
29
- expect(coordinateMap.has(key)).toBe(false);
30
- });
31
-
32
- it('should delete key-value pair correctly', () => {
33
- const coordinateMap = new CoordinateMap<string>();
34
- const key = [1, 2, 3];
35
- const value = 'TestValue';
36
-
37
- coordinateMap.set(key, value);
38
- coordinateMap.delete(key);
39
-
40
- expect(coordinateMap.has(key)).toBe(false);
41
- });
42
-
43
- it('should allow changing the joint character', () => {
44
- const coordinateMap = new CoordinateMap<string>();
45
- const key = [1, 2, 3];
46
- const value = 'TestValue';
47
-
48
- coordinateMap.set(key, value);
49
- const newKey = [1, 2, 3];
50
- const retrievedValue = coordinateMap.get(newKey);
51
-
52
- expect(retrievedValue).toBe(value);
53
- });
54
- });
55
-
56
- describe('CoordinateMap', () => {
57
- class MyCoordinateMap<V = any> extends CoordinateMap<V> {
58
- constructor(joint?: string) {
59
- super(joint);
60
- this._joint = joint += '-';
61
- }
62
- }
63
-
64
- const cMap = new MyCoordinateMap<number>('*');
65
-
66
- beforeEach(() => {
67
- cMap.set([0, 0], 0);
68
- cMap.set([0, 1], 1);
69
- cMap.set([1, 1], 11);
70
- });
71
- it('should joint to be *-', () => {
72
- expect(cMap.joint).toBe('*-');
73
- });
74
- });