@gabrielrufino/cube 2.0.9 → 2.0.11

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 (45) hide show
  1. package/dist/Array/IArray.d.ts +6 -6
  2. package/dist/Array/index.d.ts +1 -1
  3. package/dist/BinarySearchTree/IBinarySearchTree.d.ts +7 -7
  4. package/dist/BinarySearchTree/IBinarySearchTreeData.d.ts +1 -1
  5. package/dist/BinarySearchTree/index.d.ts +3 -3
  6. package/dist/BinarySearchTree/index.js +6 -4
  7. package/dist/Deck/IDeck.d.ts +6 -6
  8. package/dist/Deck/index.d.ts +1 -1
  9. package/dist/Dictionary/IDictionary.d.ts +7 -7
  10. package/dist/Dictionary/index.d.ts +2 -2
  11. package/dist/DoublyLinkedList/IDoublyLinkedList.d.ts +6 -6
  12. package/dist/DoublyLinkedList/index.d.ts +2 -1
  13. package/dist/DoublyLinkedList/index.js +10 -10
  14. package/dist/Graph/GraphSearchNodeStates.js +0 -1
  15. package/dist/Graph/IGraph.d.ts +4 -4
  16. package/dist/Graph/index.d.ts +3 -3
  17. package/dist/Graph/index.js +2 -2
  18. package/dist/HashTable/IHashTable.d.ts +4 -4
  19. package/dist/HashTable/index.d.ts +5 -5
  20. package/dist/HashTable/index.js +2 -8
  21. package/dist/HashTableLinearProbing/HashTableLinearProbingElement.js +0 -2
  22. package/dist/HashTableLinearProbing/IHashTableLinearProbing.d.ts +4 -4
  23. package/dist/HashTableLinearProbing/IHashTableLinearProbingData.d.ts +1 -1
  24. package/dist/HashTableLinearProbing/index.d.ts +4 -4
  25. package/dist/HashTableSeparateChaining/HashTableSeparateChainingElement.js +0 -2
  26. package/dist/HashTableSeparateChaining/IHashTableSeparateChaining.d.ts +5 -5
  27. package/dist/HashTableSeparateChaining/IHashTableSeparateChainingData.d.ts +1 -1
  28. package/dist/HashTableSeparateChaining/index.d.ts +4 -4
  29. package/dist/HashTableSeparateChaining/index.js +3 -9
  30. package/dist/LinkedList/ILinkedList.d.ts +7 -7
  31. package/dist/LinkedList/index.d.ts +2 -2
  32. package/dist/LinkedList/index.js +5 -5
  33. package/dist/MaxHeap/IMaxHeap.d.ts +2 -2
  34. package/dist/MaxHeap/index.d.ts +6 -6
  35. package/dist/MinHeap/IMinHeap.d.ts +2 -2
  36. package/dist/MinHeap/index.d.ts +6 -6
  37. package/dist/Queue/IQueue.d.ts +4 -4
  38. package/dist/Queue/index.d.ts +1 -1
  39. package/dist/Set/ISet.d.ts +10 -10
  40. package/dist/Set/index.d.ts +2 -2
  41. package/dist/Stack/IStack.d.ts +4 -4
  42. package/dist/Stack/index.d.ts +1 -1
  43. package/eslint.config.mjs +3 -0
  44. package/package.json +24 -25
  45. package/stryker.config.json +1 -1
@@ -1,9 +1,9 @@
1
1
  interface IArray<T> {
2
- insertInLastPosition(_element: T): T;
3
- insertInFirstPosition(_element: T): T;
4
- insertInPosition(_position: number, _element: T): T;
5
- removeFromLastPosition(): T | undefined;
6
- removeFromFirstPosition(): T | undefined;
7
- removeFromPosition(_position: number): T | undefined;
2
+ insertInLastPosition: (_element: T) => T;
3
+ insertInFirstPosition: (_element: T) => T;
4
+ insertInPosition: (_position: number, _element: T) => T;
5
+ removeFromLastPosition: () => T | undefined;
6
+ removeFromFirstPosition: () => T | undefined;
7
+ removeFromPosition: (_position: number) => T | undefined;
8
8
  }
9
9
  export default IArray;
@@ -1,5 +1,5 @@
1
+ import type IArray from './IArray';
1
2
  import DataStructure from '../DataStructure';
2
- import IArray from './IArray';
3
3
  export default class Array<T = number> extends DataStructure<T> implements IArray<T> {
4
4
  constructor(...inputs: Readonly<T[]>);
5
5
  insertInLastPosition(element: T): T;
@@ -1,14 +1,14 @@
1
- import IBinarySearchTreeData from './IBinarySearchTreeData';
1
+ import type IBinarySearchTreeData from './IBinarySearchTreeData';
2
2
  interface IBinarySearchTree<T> {
3
3
  get data(): IBinarySearchTreeData<T>;
4
4
  get size(): number;
5
5
  get min(): T | null;
6
6
  get max(): T | null;
7
- insert(_value: T): T;
8
- walkInOrder(_callback: (_value: T) => any): void;
9
- walkPreOrder(_callback: (_value: T) => any): void;
10
- walkPostOrder(_callback: (_value: T) => any): void;
11
- search(_value: T): boolean;
12
- remove(_value: T): T | null;
7
+ insert: (_value: T) => T;
8
+ walkInOrder: (_callback: (_value: T) => any) => void;
9
+ walkPreOrder: (_callback: (_value: T) => any) => void;
10
+ walkPostOrder: (_callback: (_value: T) => any) => void;
11
+ search: (_value: T) => boolean;
12
+ remove: (_value: T) => T | null;
13
13
  }
14
14
  export default IBinarySearchTree;
@@ -1,4 +1,4 @@
1
- import BinarySearchTreeNode from './BinarySearchTreeNode';
1
+ import type BinarySearchTreeNode from './BinarySearchTreeNode';
2
2
  interface IBinarySearchTreeData<T> {
3
3
  left: BinarySearchTreeNode<T> | null;
4
4
  value: T | null;
@@ -1,6 +1,6 @@
1
- import IBinarySearchNodeOptions from './IBinarySearchNodeOptions';
2
- import IBinarySearchTree from './IBinarySearchTree';
3
- import IBinarySearchTreeData from './IBinarySearchTreeData';
1
+ import type IBinarySearchNodeOptions from './IBinarySearchNodeOptions';
2
+ import type IBinarySearchTree from './IBinarySearchTree';
3
+ import type IBinarySearchTreeData from './IBinarySearchTreeData';
4
4
  export default class BinarySearchTree<T = number> implements IBinarySearchTree<T> {
5
5
  private _root;
6
6
  private _size;
@@ -46,11 +46,12 @@ var BinarySearchTree = /** @class */ (function () {
46
46
  });
47
47
  Object.defineProperty(BinarySearchTree.prototype, "min", {
48
48
  get: function () {
49
+ var _a;
49
50
  var current = this._root;
50
51
  while (current && current.left) {
51
52
  current = current.left;
52
53
  }
53
- return (current === null || current === void 0 ? void 0 : current.value) || null;
54
+ return (_a = current === null || current === void 0 ? void 0 : current.value) !== null && _a !== void 0 ? _a : null;
54
55
  },
55
56
  enumerable: false,
56
57
  configurable: true
@@ -58,7 +59,7 @@ var BinarySearchTree = /** @class */ (function () {
58
59
  Object.defineProperty(BinarySearchTree.prototype, "max", {
59
60
  get: function () {
60
61
  var current = this._root;
61
- while (current && current.right) {
62
+ while (current === null || current === void 0 ? void 0 : current.right) {
62
63
  current = current.right;
63
64
  }
64
65
  return (current === null || current === void 0 ? void 0 : current.value) || null;
@@ -99,6 +100,7 @@ var BinarySearchTree = /** @class */ (function () {
99
100
  return Boolean(current);
100
101
  };
101
102
  BinarySearchTree.prototype.remove = function (value) {
103
+ var _a;
102
104
  var current = this._root;
103
105
  var path = [];
104
106
  while (current && current.value !== value) {
@@ -114,7 +116,7 @@ var BinarySearchTree = /** @class */ (function () {
114
116
  var found = __assign({}, current);
115
117
  var parent = path
116
118
  .slice(0, path.length - 1)
117
- .reduce(function (accumulator, current) { return accumulator && accumulator[current]; }, this._root);
119
+ .reduce(function (accumulator, current) { return accumulator[current]; }, this._root);
118
120
  var child = path[path.length - 1];
119
121
  if ((current === null || current === void 0 ? void 0 : current.left) && current.right && parent) {
120
122
  var head = current.right;
@@ -136,7 +138,7 @@ var BinarySearchTree = /** @class */ (function () {
136
138
  parent[child] = null;
137
139
  this._size -= 1;
138
140
  }
139
- return found.value || null;
141
+ return (_a = found.value) !== null && _a !== void 0 ? _a : null;
140
142
  };
141
143
  BinarySearchTree.prototype._lessThanOrEqualTo = function (value1, value2) {
142
144
  if (value1 <= value2) {
@@ -1,9 +1,9 @@
1
1
  interface IDeck<T> {
2
- addFront(_element: T): T;
3
- addBack(_element: T): T;
4
- removeFront(): T | undefined;
5
- removeBack(): T | undefined;
6
- peekFront(): T | undefined;
7
- peekBack(): T | undefined;
2
+ addFront: (_element: T) => T;
3
+ addBack: (_element: T) => T;
4
+ removeFront: () => T | undefined;
5
+ removeBack: () => T | undefined;
6
+ peekFront: () => T | undefined;
7
+ peekBack: () => T | undefined;
8
8
  }
9
9
  export default IDeck;
@@ -1,5 +1,5 @@
1
+ import type IDeck from './IDeck';
1
2
  import DataStructure from '../DataStructure';
2
- import IDeck from './IDeck';
3
3
  export default class Deck<T = number> extends DataStructure<T> implements IDeck<T> {
4
4
  constructor(...inputs: Readonly<T[]>);
5
5
  addFront(element: T): T;
@@ -1,4 +1,4 @@
1
- import IDictionaryData from './IDictionaryData';
1
+ import type IDictionaryData from './IDictionaryData';
2
2
  interface IDictionary<T> {
3
3
  get data(): IDictionaryData<T>;
4
4
  get size(): number;
@@ -6,11 +6,11 @@ interface IDictionary<T> {
6
6
  get keys(): string[];
7
7
  get values(): T[];
8
8
  get pairs(): [string, T][];
9
- set(_key: string, _value: T): [string, T];
10
- remove(_key: string): [string, T] | null;
11
- hasKey(_key: string): boolean;
12
- get(_key: string): T | null;
13
- clear(): IDictionaryData<T>;
14
- forEach(_func: (_key: string, _value: T) => any): void;
9
+ set: (_key: string, _value: T) => [string, T];
10
+ remove: (_key: string) => [string, T] | null;
11
+ hasKey: (_key: string) => boolean;
12
+ get: (_key: string) => T | null;
13
+ clear: () => IDictionaryData<T>;
14
+ forEach: (_func: (_key: string, _value: T) => any) => void;
15
15
  }
16
16
  export default IDictionary;
@@ -1,5 +1,5 @@
1
- import IDictionary from './IDictionary';
2
- import IDictionaryData from './IDictionaryData';
1
+ import type IDictionary from './IDictionary';
2
+ import type IDictionaryData from './IDictionaryData';
3
3
  export default class Dictionary<T = number> implements IDictionary<T> {
4
4
  private _data;
5
5
  constructor(inputs?: Readonly<{
@@ -6,11 +6,11 @@ export interface IDoublyLinkedListItem<T> {
6
6
  interface IDoublyLinkedList<T> {
7
7
  get data(): IDoublyLinkedListItem<T>[];
8
8
  get size(): number;
9
- push(_element: T): T;
10
- getFromPosition(_position: number): IDoublyLinkedListItem<T> | undefined;
11
- positionOf(_element: T): number | undefined;
12
- insertInPosition(_element: T, _position: number): T | undefined;
13
- remove(_element: T): T | undefined;
14
- removeFromPosition(_position: number): T | undefined;
9
+ push: (_element: T) => T;
10
+ getFromPosition: (_position: number) => IDoublyLinkedListItem<T> | undefined;
11
+ positionOf: (_element: T) => number | undefined;
12
+ insertInPosition: (_element: T, _position: number) => T | undefined;
13
+ remove: (_element: T) => T | undefined;
14
+ removeFromPosition: (_position: number) => T | undefined;
15
15
  }
16
16
  export default IDoublyLinkedList;
@@ -1,4 +1,5 @@
1
- import IDoublyLinkedList, { IDoublyLinkedListItem } from './IDoublyLinkedList';
1
+ import type { IDoublyLinkedListItem } from './IDoublyLinkedList';
2
+ import type IDoublyLinkedList from './IDoublyLinkedList';
2
3
  export default class DoublyLinkedList<T = number> implements IDoublyLinkedList<T> {
3
4
  private _head;
4
5
  private _tail;
@@ -24,14 +24,14 @@ var DoublyLinkedList = /** @class */ (function () {
24
24
  }
25
25
  Object.defineProperty(DoublyLinkedList.prototype, "data", {
26
26
  get: function () {
27
- var _a, _b;
27
+ var _a, _b, _c, _d;
28
28
  var current = this._head;
29
29
  var data = [];
30
30
  while (current) {
31
31
  data.push({
32
- previous: ((_a = current.previous) === null || _a === void 0 ? void 0 : _a.value) || null,
32
+ previous: (_b = (_a = current.previous) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null,
33
33
  value: current.value,
34
- next: ((_b = current.next) === null || _b === void 0 ? void 0 : _b.value) || null,
34
+ next: (_d = (_c = current.next) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : null,
35
35
  });
36
36
  current = current.next;
37
37
  }
@@ -67,7 +67,7 @@ var DoublyLinkedList = /** @class */ (function () {
67
67
  * Complexity: O(n/2)
68
68
  */
69
69
  DoublyLinkedList.prototype.getFromPosition = function (position) {
70
- var _a, _b;
70
+ var _a, _b, _c, _d;
71
71
  if (position < 0 || position >= this.size) {
72
72
  return undefined;
73
73
  }
@@ -88,9 +88,9 @@ var DoublyLinkedList = /** @class */ (function () {
88
88
  }
89
89
  if (current === null || current === void 0 ? void 0 : current.value) {
90
90
  return {
91
- previous: ((_a = current.previous) === null || _a === void 0 ? void 0 : _a.value) || null,
91
+ previous: (_b = (_a = current.previous) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null,
92
92
  value: current.value,
93
- next: ((_b = current.next) === null || _b === void 0 ? void 0 : _b.value) || null,
93
+ next: (_d = (_c = current.next) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : null,
94
94
  };
95
95
  }
96
96
  };
@@ -107,7 +107,7 @@ var DoublyLinkedList = /** @class */ (function () {
107
107
  * Complexity: O(n)
108
108
  */
109
109
  DoublyLinkedList.prototype.insertInPosition = function (element, position) {
110
- var _a;
110
+ var _a, _b;
111
111
  if (position < 0 || position > this.size) {
112
112
  return undefined;
113
113
  }
@@ -119,9 +119,9 @@ var DoublyLinkedList = /** @class */ (function () {
119
119
  this._size += 1;
120
120
  return element;
121
121
  }
122
- if (position === this.size - 1 && this._tail && this._tail.previous) {
122
+ if (position === this.size - 1 && ((_a = this._tail) === null || _a === void 0 ? void 0 : _a.previous)) {
123
123
  this._tail.previous.next = node;
124
- node.previous = ((_a = this._tail) === null || _a === void 0 ? void 0 : _a.previous) || null;
124
+ node.previous = ((_b = this._tail) === null || _b === void 0 ? void 0 : _b.previous) || null;
125
125
  node.next = this._tail;
126
126
  this._tail.previous = node;
127
127
  this._size += 1;
@@ -148,7 +148,7 @@ var DoublyLinkedList = /** @class */ (function () {
148
148
  current = (current === null || current === void 0 ? void 0 : current.previous) || null;
149
149
  }
150
150
  }
151
- if (current && current.previous) {
151
+ if (current === null || current === void 0 ? void 0 : current.previous) {
152
152
  current.previous.next = node;
153
153
  node.previous = current.previous;
154
154
  node.next = current;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- /* eslint-disable no-unused-vars */
4
3
  var GraphSearchNodeStates;
5
4
  (function (GraphSearchNodeStates) {
6
5
  GraphSearchNodeStates[GraphSearchNodeStates["UNEXPLORED"] = 0] = "UNEXPLORED";
@@ -6,10 +6,10 @@ interface IGraph {
6
6
  get size(): number;
7
7
  get nodes(): string[];
8
8
  get edges(): [string, string][];
9
- insert(_node: string): string | null;
10
- connect(_node1: string, _node2: string): [string, string];
11
- breadthFirstSearch(_startNode: string, _callback: (_node: string) => void): void;
12
- getDistancesFrom(_node: string): {
9
+ insert: (_node: string) => string | null;
10
+ connect: (_node1: string, _node2: string) => [string, string];
11
+ breadthFirstSearch: (_startNode: string, _callback: (_node: string) => void) => void;
12
+ getDistancesFrom: (_node: string) => {
13
13
  [key: string]: number;
14
14
  };
15
15
  }
@@ -1,6 +1,6 @@
1
- import IGraph from './IGraph';
2
- import IGraphOptions from './IGraphOptions';
3
- import { Edge } from './Edge';
1
+ import type { Edge } from './Edge';
2
+ import type IGraph from './IGraph';
3
+ import type IGraphOptions from './IGraphOptions';
4
4
  export default class Graph implements IGraph {
5
5
  private readonly _isDirected;
6
6
  private readonly _data;
@@ -23,11 +23,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- var GraphNodeNotFoundError_1 = __importDefault(require("./GraphNodeNotFoundError"));
27
- var GraphSearchNodeStates_1 = __importDefault(require("./GraphSearchNodeStates"));
28
26
  var Dictionary_1 = __importDefault(require("../Dictionary"));
29
27
  var Queue_1 = __importDefault(require("../Queue"));
30
28
  var Set_1 = __importDefault(require("../Set"));
29
+ var GraphNodeNotFoundError_1 = __importDefault(require("./GraphNodeNotFoundError"));
30
+ var GraphSearchNodeStates_1 = __importDefault(require("./GraphSearchNodeStates"));
31
31
  var Graph = /** @class */ (function () {
32
32
  function Graph(_a) {
33
33
  var _b = _a === void 0 ? {} : _a, _c = _b.inputs, inputs = _c === void 0 ? {} : _c, _d = _b.isDirected, isDirected = _d === void 0 ? false : _d;
@@ -1,10 +1,10 @@
1
- import IHashTableData from './IHashTableData';
1
+ import type IHashTableData from './IHashTableData';
2
2
  interface IHashTable<T> {
3
3
  get data(): IHashTableData<T>;
4
4
  get size(): number;
5
5
  get maxSize(): number;
6
- put(_key: string, _value: T): T;
7
- get(_key: string): T | null;
8
- remove(_key: string): T | null;
6
+ put: (_key: string, _value: T) => T;
7
+ get: (_key: string) => T | null;
8
+ remove: (_key: string) => T | null;
9
9
  }
10
10
  export default IHashTable;
@@ -1,13 +1,13 @@
1
- import IHashTable from './IHashTable';
2
- import IHashTableData from './IHashTableData';
3
- import IHashTableInputs from './IHashTableInputs';
4
- import IHashTableOptions from './IHashTableOptions';
1
+ import type IHashTable from './IHashTable';
2
+ import type IHashTableData from './IHashTableData';
3
+ import type IHashTableInputs from './IHashTableInputs';
4
+ import type IHashTableOptions from './IHashTableOptions';
5
5
  export default class HashTable<T = number> implements IHashTable<T> {
6
+ readonly maxSize: number;
6
7
  private _data;
7
8
  constructor(inputs?: Readonly<IHashTableInputs<T>>, { maxSize }?: IHashTableOptions);
8
9
  get data(): IHashTableData<T>;
9
10
  get size(): number;
10
- get maxSize(): number;
11
11
  put(key: string, value: T): T;
12
12
  get(key: string): T | null;
13
13
  remove(key: string): T | null;
@@ -15,7 +15,8 @@ var HashTable = /** @class */ (function () {
15
15
  function HashTable(inputs, _a) {
16
16
  if (inputs === void 0) { inputs = {}; }
17
17
  var _b = _a === void 0 ? {} : _a, _c = _b.maxSize, maxSize = _c === void 0 ? 100 : _c;
18
- this._data = new Array(maxSize);
18
+ this._data = [];
19
+ this.maxSize = maxSize;
19
20
  for (var _i = 0, _d = Object.entries(inputs); _i < _d.length; _i++) {
20
21
  var _e = _d[_i], key = _e[0], value = _e[1];
21
22
  this.put(key, value);
@@ -40,13 +41,6 @@ var HashTable = /** @class */ (function () {
40
41
  enumerable: false,
41
42
  configurable: true
42
43
  });
43
- Object.defineProperty(HashTable.prototype, "maxSize", {
44
- get: function () {
45
- return this._data.length;
46
- },
47
- enumerable: false,
48
- configurable: true
49
- });
50
44
  HashTable.prototype.put = function (key, value) {
51
45
  var position = this._hashCode(key);
52
46
  this._data[position] = value;
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable no-unused-vars */
3
- /* eslint-disable no-useless-constructor */
4
2
  Object.defineProperty(exports, "__esModule", { value: true });
5
3
  var HashTableLinearProbingElement = /** @class */ (function () {
6
4
  function HashTableLinearProbingElement(key, value) {
@@ -1,9 +1,9 @@
1
- import IHashTableLinearProbingData from './IHashTableLinearProbingData';
1
+ import type IHashTableLinearProbingData from './IHashTableLinearProbingData';
2
2
  interface IHashTableLinearProbing<T> {
3
3
  get data(): IHashTableLinearProbingData<T>;
4
4
  get size(): number;
5
- put(_key: string, _value: T): T | null;
6
- get(_key: string): T | null;
7
- remove(_key: string): T | null;
5
+ put: (_key: string, _value: T) => T | null;
6
+ get: (_key: string) => T | null;
7
+ remove: (_key: string) => T | null;
8
8
  }
9
9
  export default IHashTableLinearProbing;
@@ -1,4 +1,4 @@
1
- import HashTableLinearProbingElement from './HashTableLinearProbingElement';
1
+ import type HashTableLinearProbingElement from './HashTableLinearProbingElement';
2
2
  interface IHashTableLinearProbingData<T> {
3
3
  [index: number]: HashTableLinearProbingElement<T>;
4
4
  }
@@ -1,9 +1,9 @@
1
+ import type IHashTableLinearProbing from './IHashTableLinearProbing';
2
+ import type IHashTableLinearProbingInputs from './IHashTableLinearProbingInputs';
3
+ import type IHashTableLinearProbingOptions from './IHashTableLinearProbingOptions';
1
4
  import HashTableLinearProbingElement from './HashTableLinearProbingElement';
2
- import IHashTableLinearProbing from './IHashTableLinearProbing';
3
- import IHashTableLinearProbingInputs from './IHashTableLinearProbingInputs';
4
- import IHashTableLinearProbingOptions from './IHashTableLinearProbingOptions';
5
5
  export default class HashTableLinearProbing<T = number> implements IHashTableLinearProbing<T> {
6
- private _maxSize;
6
+ private readonly _maxSize;
7
7
  private _data;
8
8
  constructor(inputs?: Readonly<IHashTableLinearProbingInputs<T>>, { maxSize }?: IHashTableLinearProbingOptions);
9
9
  get data(): {
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable no-useless-constructor */
3
- /* eslint-disable no-unused-vars */
4
2
  Object.defineProperty(exports, "__esModule", { value: true });
5
3
  var HashTableSeparateChainingElement = /** @class */ (function () {
6
4
  function HashTableSeparateChainingElement(key, value) {
@@ -1,11 +1,11 @@
1
- import HashTableSeparateChainingElement from './HashTableSeparateChainingElement';
2
- import IHashTableSeparateChainingData from './IHashTableSeparateChainingData';
1
+ import type HashTableSeparateChainingElement from './HashTableSeparateChainingElement';
2
+ import type IHashTableSeparateChainingData from './IHashTableSeparateChainingData';
3
3
  interface IHashTableSeparateChaining<T> {
4
4
  get data(): IHashTableSeparateChainingData<T>;
5
5
  get size(): number;
6
6
  get maxSize(): number;
7
- put(_key: string, _value: T): T;
8
- get(_key: string): HashTableSeparateChainingElement<T> | null;
9
- remove(_key: string): HashTableSeparateChainingElement<T> | null;
7
+ put: (_key: string, _value: T) => T;
8
+ get: (_key: string) => HashTableSeparateChainingElement<T> | null;
9
+ remove: (_key: string) => HashTableSeparateChainingElement<T> | null;
10
10
  }
11
11
  export default IHashTableSeparateChaining;
@@ -1,4 +1,4 @@
1
- import LinkedList from '../LinkedList';
1
+ import type LinkedList from '../LinkedList';
2
2
  interface IHashTableSeparateChainingData<T> {
3
3
  [key: number]: LinkedList<T>;
4
4
  }
@@ -1,15 +1,15 @@
1
+ import type IHashTableSeparateChaining from './IHashTableSeparateChaining';
2
+ import type IHashTableSeparateChainingData from './IHashTableSeparateChainingData';
3
+ import type IHashTableSeparateChainingInputs from './IHashTableSeparateChainingInputs';
1
4
  import HashTableSeparateChainingElement from './HashTableSeparateChainingElement';
2
- import IHashTableSeparateChaining from './IHashTableSeparateChaining';
3
- import IHashTableSeparateChainingData from './IHashTableSeparateChainingData';
4
- import IHashTableSeparateChainingInputs from './IHashTableSeparateChainingInputs';
5
5
  export default class HashTableSeparateChaining<T = number> implements IHashTableSeparateChaining<T> {
6
6
  private _data;
7
+ readonly maxSize: number;
7
8
  constructor(inputs?: Readonly<IHashTableSeparateChainingInputs<T>>, { maxSize }?: {
8
9
  maxSize: number;
9
10
  });
10
11
  get data(): IHashTableSeparateChainingData<T>;
11
12
  get size(): number;
12
- get maxSize(): number;
13
13
  put(key: string, value: T): T;
14
14
  get(key: string): HashTableSeparateChainingElement<T> | null;
15
15
  remove(key: string): HashTableSeparateChainingElement<T> | null;
@@ -14,13 +14,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- var HashTableSeparateChainingElement_1 = __importDefault(require("./HashTableSeparateChainingElement"));
18
17
  var LinkedList_1 = __importDefault(require("../LinkedList"));
18
+ var HashTableSeparateChainingElement_1 = __importDefault(require("./HashTableSeparateChainingElement"));
19
19
  var HashTableSeparateChaining = /** @class */ (function () {
20
20
  function HashTableSeparateChaining(inputs, _a) {
21
21
  if (inputs === void 0) { inputs = {}; }
22
22
  var _b = _a === void 0 ? { maxSize: 100 } : _a, maxSize = _b.maxSize;
23
- this._data = new Array(maxSize);
23
+ this._data = [];
24
+ this.maxSize = maxSize;
24
25
  for (var _i = 0, _c = Object.entries(inputs); _i < _c.length; _i++) {
25
26
  var _d = _c[_i], key = _d[0], value = _d[1];
26
27
  this.put(key, value);
@@ -45,13 +46,6 @@ var HashTableSeparateChaining = /** @class */ (function () {
45
46
  enumerable: false,
46
47
  configurable: true
47
48
  });
48
- Object.defineProperty(HashTableSeparateChaining.prototype, "maxSize", {
49
- get: function () {
50
- return this._data.length;
51
- },
52
- enumerable: false,
53
- configurable: true
54
- });
55
49
  HashTableSeparateChaining.prototype.put = function (key, value) {
56
50
  var linkedList = this._getLinkedListByKey(key);
57
51
  var element = new HashTableSeparateChainingElement_1.default(key, value);
@@ -1,13 +1,13 @@
1
- import ILinkedListItem from './ILinkedListItem';
1
+ import type ILinkedListItem from './ILinkedListItem';
2
2
  interface ILinkedList<T> {
3
3
  get data(): ILinkedListItem<T>[];
4
4
  get size(): number;
5
5
  get isEmpty(): boolean;
6
- push(_element: T): T;
7
- getFromPosition(_position: number): ILinkedListItem<T> | null;
8
- positionOf(_element: T): number | undefined;
9
- insertInPosition(_element: T, _position: number): T | undefined;
10
- remove(_element: T): T | null;
11
- removeFromPosition(_position: number): T | null;
6
+ push: (_element: T) => T;
7
+ getFromPosition: (_position: number) => ILinkedListItem<T> | null;
8
+ positionOf: (_element: T) => number | undefined;
9
+ insertInPosition: (_element: T, _position: number) => T | undefined;
10
+ remove: (_element: T) => T | null;
11
+ removeFromPosition: (_position: number) => T | null;
12
12
  }
13
13
  export default ILinkedList;
@@ -1,5 +1,5 @@
1
- import ILinkedList from './ILinkedList';
2
- import ILinkedListItem from './ILinkedListItem';
1
+ import type ILinkedList from './ILinkedList';
2
+ import type ILinkedListItem from './ILinkedListItem';
3
3
  export default class LinkedList<T = number> implements ILinkedList<T> {
4
4
  private readonly _FIRST_POSITION;
5
5
  private _head;
@@ -22,13 +22,13 @@ var LinkedList = /** @class */ (function () {
22
22
  }
23
23
  Object.defineProperty(LinkedList.prototype, "data", {
24
24
  get: function () {
25
- var _a;
25
+ var _a, _b;
26
26
  var data = [];
27
27
  var current = this._head;
28
28
  while (current) {
29
29
  data.push({
30
30
  value: current.value,
31
- next: ((_a = current.next) === null || _a === void 0 ? void 0 : _a.value) || null,
31
+ next: (_b = (_a = current.next) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null,
32
32
  });
33
33
  current = current.next;
34
34
  }
@@ -94,7 +94,7 @@ var LinkedList = /** @class */ (function () {
94
94
  }
95
95
  else {
96
96
  var before = this._getNodeFromPosition(position - 1);
97
- var after = (before && before.next) || null;
97
+ var after = (before === null || before === void 0 ? void 0 : before.next) || null;
98
98
  if (before) {
99
99
  before.next = node;
100
100
  }
@@ -104,14 +104,14 @@ var LinkedList = /** @class */ (function () {
104
104
  return element;
105
105
  };
106
106
  LinkedList.prototype.getFromPosition = function (position) {
107
- var _a;
107
+ var _a, _b;
108
108
  var node = this._getNodeFromPosition(position);
109
109
  if (!node) {
110
110
  return null;
111
111
  }
112
112
  return {
113
113
  value: node.value,
114
- next: ((_a = node.next) === null || _a === void 0 ? void 0 : _a.value) || null,
114
+ next: (_b = (_a = node.next) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : null,
115
115
  };
116
116
  };
117
117
  LinkedList.prototype.removeFromPosition = function (position) {
@@ -3,7 +3,7 @@ interface IMaxHeap<T> {
3
3
  get size(): number;
4
4
  get isEmpty(): boolean;
5
5
  get max(): T | null;
6
- insert(_value: T): T;
7
- extract(): T | null;
6
+ insert: (_value: T) => T;
7
+ extract: () => T | null;
8
8
  }
9
9
  export default IMaxHeap;
@@ -1,5 +1,5 @@
1
- import IMaxHeap from './IMaxHeap';
2
- import IMaxHeapOptions from './IMaxHeapOptions';
1
+ import type IMaxHeap from './IMaxHeap';
2
+ import type IMaxHeapOptions from './IMaxHeapOptions';
3
3
  export default class MaxHeap<T = number> implements IMaxHeap<T> {
4
4
  private _data;
5
5
  constructor({ greaterThanOrEqualTo, inputs }?: IMaxHeapOptions<T>);
@@ -9,10 +9,10 @@ export default class MaxHeap<T = number> implements IMaxHeap<T> {
9
9
  get max(): T | null;
10
10
  insert(value: T): T;
11
11
  extract(): T | null;
12
- private _greaterThanOrEqualTo;
13
- private _getLeftIndex;
14
- private _getRightIndex;
15
- private _getParentIndex;
12
+ private readonly _greaterThanOrEqualTo;
13
+ private readonly _getLeftIndex;
14
+ private readonly _getRightIndex;
15
+ private readonly _getParentIndex;
16
16
  private _siftUp;
17
17
  private _siftDown;
18
18
  private [Symbol.toPrimitive];
@@ -3,7 +3,7 @@ interface IMinHeap<T> {
3
3
  get size(): number;
4
4
  get isEmpty(): boolean;
5
5
  get min(): T | null;
6
- insert(_value: T): T;
7
- extract(): T | null;
6
+ insert: (_value: T) => T;
7
+ extract: () => T | null;
8
8
  }
9
9
  export default IMinHeap;
@@ -1,5 +1,5 @@
1
- import IMinHeap from './IMinHeap';
2
- import IMinHeapOptions from './IMinHeapOptions';
1
+ import type IMinHeap from './IMinHeap';
2
+ import type IMinHeapOptions from './IMinHeapOptions';
3
3
  export default class MinHeap<T = number> implements IMinHeap<T> {
4
4
  private _data;
5
5
  constructor({ lessThanOrEqualTo, inputs }?: IMinHeapOptions<T>);
@@ -9,10 +9,10 @@ export default class MinHeap<T = number> implements IMinHeap<T> {
9
9
  get min(): T | null;
10
10
  insert(value: T): T;
11
11
  extract(): T | null;
12
- private _lessThanOrEqualTo;
13
- private _getLeftIndex;
14
- private _getRightIndex;
15
- private _getParentIndex;
12
+ private readonly _lessThanOrEqualTo;
13
+ private readonly _getLeftIndex;
14
+ private readonly _getRightIndex;
15
+ private readonly _getParentIndex;
16
16
  private _siftUp;
17
17
  private _siftDown;
18
18
  private [Symbol.toPrimitive];
@@ -1,8 +1,8 @@
1
1
  interface IQueue<T> {
2
- enqueue(_element: T): T;
3
- dequeue(): T | undefined;
4
- peek(): T | undefined;
5
- clear(): void;
2
+ enqueue: (_element: T) => T;
3
+ dequeue: () => T | undefined;
4
+ peek: () => T | undefined;
5
+ clear: () => void;
6
6
  get isEmpty(): boolean;
7
7
  }
8
8
  export default IQueue;
@@ -1,5 +1,5 @@
1
+ import type IQueue from './IQueue';
1
2
  import DataStructure from '../DataStructure';
2
- import IQueue from './IQueue';
3
3
  export default class Queue<T = number> extends DataStructure<T> implements IQueue<T> {
4
4
  constructor(...inputs: Readonly<T[]>);
5
5
  get isEmpty(): boolean;
@@ -1,15 +1,15 @@
1
- import Set from './';
1
+ import type Set from './';
2
2
  interface ISet<T> {
3
3
  get data(): T[];
4
4
  get size(): number;
5
- has(_elemet: T): boolean;
6
- add(_element: T): T | null;
7
- delete(_element: T): T | null;
8
- clear(_element: T): T[];
9
- union(_set: Set<T>): Set<T>;
10
- intersection(_set: Set<T>): Set<T>;
11
- difference(_set: Set<T>): Set<T>;
12
- isSubsetOf(_set: Set<T>): boolean;
13
- contains(_set: Set<T>): boolean;
5
+ has: (_elemet: T) => boolean;
6
+ add: (_element: T) => T | null;
7
+ delete: (_element: T) => T | null;
8
+ clear: (_element: T) => T[];
9
+ union: (_set: Set<T>) => Set<T>;
10
+ intersection: (_set: Set<T>) => Set<T>;
11
+ difference: (_set: Set<T>) => Set<T>;
12
+ isSubsetOf: (_set: Set<T>) => boolean;
13
+ contains: (_set: Set<T>) => boolean;
14
14
  }
15
15
  export default ISet;
@@ -1,6 +1,6 @@
1
- import ISet from './ISet';
1
+ import type ISet from './ISet';
2
2
  export default class Set<T = number> implements ISet<T> {
3
- private _data;
3
+ private readonly _data;
4
4
  constructor(...inputs: Readonly<T[]>);
5
5
  get data(): T[];
6
6
  get size(): number;
@@ -1,8 +1,8 @@
1
1
  interface IStack<T> {
2
- push(_element: T): T;
3
- pop(): T | undefined;
4
- peek(): T | undefined;
5
- clear(): void;
2
+ push: (_element: T) => T;
3
+ pop: () => T | undefined;
4
+ peek: () => T | undefined;
5
+ clear: () => void;
6
6
  get isEmpty(): boolean;
7
7
  }
8
8
  export default IStack;
@@ -1,5 +1,5 @@
1
+ import type IStack from './IStack';
1
2
  import DataStructure from '../DataStructure';
2
- import IStack from './IStack';
3
3
  export default class Stack<T = number> extends DataStructure<T> implements IStack<T> {
4
4
  constructor(...inputs: Readonly<T[]>);
5
5
  push(element: T): T;
@@ -0,0 +1,3 @@
1
+ import antfu from '@antfu/eslint-config'
2
+
3
+ export default antfu()
package/package.json CHANGED
@@ -1,42 +1,41 @@
1
1
  {
2
2
  "name": "@gabrielrufino/cube",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
4
4
  "description": "Data structures made in Typescript",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "build": "tsc",
8
- "build:watch": "npm run build -- --watch",
9
- "lint": "eslint src/**/*.ts",
10
- "test": "vitest run",
11
- "test:cov": "npm t -- --coverage",
12
- "test:mutation": "npx stryker run",
13
- "test:watch": "vitest"
14
- },
5
+ "author": "Gabriel Rufino <contato@gabrielrufino.com>",
6
+ "license": "UNLICENSED",
7
+ "funding": "https://github.com/sponsors/gabrielrufino",
8
+ "homepage": "https://github.com/gabrielrufino/cube#readme",
15
9
  "repository": {
16
10
  "type": "git",
17
11
  "url": "git+https://github.com/gabrielrufino/cube.git"
18
12
  },
13
+ "bugs": {
14
+ "url": "https://github.com/gabrielrufino/cube/issues"
15
+ },
19
16
  "keywords": [
20
17
  "Data",
21
18
  "Structures"
22
19
  ],
23
- "author": "Gabriel Rufino <contato@gabrielrufino.com>",
24
- "funding": "https://github.com/sponsors/gabrielrufino",
25
- "license": "UNLICENSED",
26
- "bugs": {
27
- "url": "https://github.com/gabrielrufino/cube/issues"
20
+ "main": "dist/index.js",
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "build:watch": "npm run build -- --watch",
24
+ "lint": "eslint",
25
+ "lint:fix": "npm run lint -- --fix",
26
+ "test": "vitest run",
27
+ "test:cov": "npm t -- --coverage",
28
+ "test:mutation": "npx stryker run",
29
+ "test:watch": "vitest"
28
30
  },
29
- "homepage": "https://github.com/gabrielrufino/cube#readme",
30
31
  "devDependencies": {
31
- "@commitlint/cli": "^19.8.0",
32
- "@commitlint/config-conventional": "^19.8.0",
33
- "@faker-js/faker": "^8.4.1",
32
+ "@antfu/eslint-config": "^4.13.0",
33
+ "@commitlint/cli": "^19.8.1",
34
+ "@commitlint/config-conventional": "^19.8.1",
35
+ "@faker-js/faker": "^9.7.0",
34
36
  "@stryker-mutator/vitest-runner": "^8.7.1",
35
- "@typescript-eslint/eslint-plugin": "^5.62.0",
36
- "@typescript-eslint/parser": "^5.62.0",
37
- "@vitest/coverage-v8": "^3.1.1",
38
- "eslint": "^8.57.1",
39
- "eslint-config-xo": "^0.43.1",
37
+ "@vitest/coverage-v8": "^3.1.3",
38
+ "eslint": "^9.26.0",
40
39
  "husky": "^9.1.7",
41
40
  "typescript": "^5.8.3",
42
41
  "vitest": "^3.0.4"
@@ -14,4 +14,4 @@
14
14
  "htmlReporter": {
15
15
  "baseDir": ".stryker-reports"
16
16
  }
17
- }
17
+ }