@gabrielrufino/cube 2.0.10 → 2.0.12

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.
@@ -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;
@@ -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;
@@ -15,7 +15,7 @@ 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 = [];
18
+ this._data = Array.from({ length: maxSize });
19
19
  this.maxSize = maxSize;
20
20
  for (var _i = 0, _d = Object.entries(inputs); _i < _d.length; _i++) {
21
21
  var _e = _d[_i], key = _e[0], value = _e[1];
@@ -26,6 +26,10 @@ var HashTable = /** @class */ (function () {
26
26
  get: function () {
27
27
  return this._data
28
28
  .map(function (value, index) { return ({ index: index, value: value }); })
29
+ .filter(function (_a) {
30
+ var value = _a.value;
31
+ return value !== undefined;
32
+ })
29
33
  .reduce(function (accumulator, current) {
30
34
  var _a;
31
35
  return (__assign(__assign({}, accumulator), (_a = {}, _a[current.index] = current.value, _a)));
@@ -3,7 +3,7 @@ import type IHashTableLinearProbingInputs from './IHashTableLinearProbingInputs'
3
3
  import type IHashTableLinearProbingOptions from './IHashTableLinearProbingOptions';
4
4
  import HashTableLinearProbingElement from './HashTableLinearProbingElement';
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(): {
@@ -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
  }
@@ -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) {
@@ -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];
@@ -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,6 +1,6 @@
1
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gabrielrufino/cube",
3
- "version": "2.0.10",
3
+ "version": "2.0.12",
4
4
  "description": "Data structures made in Typescript",
5
5
  "author": "Gabriel Rufino <contato@gabrielrufino.com>",
6
6
  "license": "UNLICENSED",
@@ -29,13 +29,13 @@
29
29
  "test:watch": "vitest"
30
30
  },
31
31
  "devDependencies": {
32
- "@antfu/eslint-config": "^4.13.0",
32
+ "@antfu/eslint-config": "^4.13.1",
33
33
  "@commitlint/cli": "^19.8.1",
34
34
  "@commitlint/config-conventional": "^19.8.1",
35
- "@faker-js/faker": "^9.7.0",
35
+ "@faker-js/faker": "^9.8.0",
36
36
  "@stryker-mutator/vitest-runner": "^8.7.1",
37
37
  "@vitest/coverage-v8": "^3.1.3",
38
- "eslint": "^9.26.0",
38
+ "eslint": "^9.27.0",
39
39
  "husky": "^9.1.7",
40
40
  "typescript": "^5.8.3",
41
41
  "vitest": "^3.0.4"