@gabrielrufino/cube 1.0.18 → 1.0.21
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.
- package/build/BinarySearchTree/BinarySearchTreeNode.d.ts +1 -1
- package/build/BinarySearchTree/BinarySearchTreeNode.js +6 -7
- package/build/BinarySearchTree/index.js +7 -8
- package/build/Dictionary/index.js +7 -8
- package/build/HashTable/IHashTable.d.ts +1 -0
- package/build/HashTable/index.d.ts +1 -1
- package/build/HashTable/index.js +20 -18
- package/build/LinkedList/index.js +12 -15
- package/build/MaxHeap/index.js +7 -8
- package/build/MinHeap/index.js +7 -8
- package/package.json +1 -1
|
@@ -9,13 +9,12 @@ var BinarySearchTreeNode = /** @class */ (function () {
|
|
|
9
9
|
this.right = null;
|
|
10
10
|
}
|
|
11
11
|
BinarySearchTreeNode.prototype[Symbol.toPrimitive] = function (type) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return null;
|
|
12
|
+
var primitives = {
|
|
13
|
+
default: true,
|
|
14
|
+
number: 1 + (this.left ? 1 : 0) + (this.right ? 1 : 0),
|
|
15
|
+
string: "[".concat(this.left, "] <= (").concat(this.value, ") => [").concat(this.right, "]"),
|
|
16
|
+
};
|
|
17
|
+
return primitives[type];
|
|
19
18
|
};
|
|
20
19
|
return BinarySearchTreeNode;
|
|
21
20
|
}());
|
|
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
var BinarySearchTreeNode_1 = __importDefault(require("./BinarySearchTreeNode"));
|
|
18
18
|
var BinarySearchTree = /** @class */ (function () {
|
|
19
19
|
function BinarySearchTree(_a) {
|
|
20
|
-
var _b = _a === void 0 ? {
|
|
20
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.inputs, inputs = _c === void 0 ? [] : _c, lessThanOrEqualTo = _b.lessThanOrEqualTo;
|
|
21
21
|
this._root = null;
|
|
22
22
|
this._size = 0;
|
|
23
23
|
if (lessThanOrEqualTo) {
|
|
@@ -183,13 +183,12 @@ var BinarySearchTree = /** @class */ (function () {
|
|
|
183
183
|
}
|
|
184
184
|
};
|
|
185
185
|
BinarySearchTree.prototype[Symbol.toPrimitive] = function (type) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return null;
|
|
186
|
+
var primitives = {
|
|
187
|
+
default: true,
|
|
188
|
+
number: this.size,
|
|
189
|
+
string: "".concat(this._root),
|
|
190
|
+
};
|
|
191
|
+
return primitives[type];
|
|
193
192
|
};
|
|
194
193
|
return BinarySearchTree;
|
|
195
194
|
}());
|
|
@@ -94,16 +94,15 @@ var Dictionary = /** @class */ (function () {
|
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
96
|
Dictionary.prototype[Symbol.toPrimitive] = function (type) {
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
var primitives = {
|
|
98
|
+
default: true,
|
|
99
|
+
number: this.size,
|
|
100
|
+
string: "{ ".concat(this.pairs.map(function (_a) {
|
|
99
101
|
var key = _a[0], value = _a[1];
|
|
100
102
|
return "".concat(key, " => ").concat(value);
|
|
101
|
-
}).join(', '), " }")
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return this.size;
|
|
105
|
-
}
|
|
106
|
-
return null;
|
|
103
|
+
}).join(', '), " }"),
|
|
104
|
+
};
|
|
105
|
+
return primitives[type];
|
|
107
106
|
};
|
|
108
107
|
return Dictionary;
|
|
109
108
|
}());
|
|
@@ -3,11 +3,11 @@ import IHashTableData from './IHashTableData';
|
|
|
3
3
|
import IHashTableInputs from './IHashTableInputs';
|
|
4
4
|
import IHashTableOptions from './IHashTableOptions';
|
|
5
5
|
export default class HashTable<T = number> implements IHashTable<T> {
|
|
6
|
-
private _maxSize;
|
|
7
6
|
private _data;
|
|
8
7
|
constructor(inputs?: IHashTableInputs<T>, { maxSize }?: IHashTableOptions);
|
|
9
8
|
get data(): IHashTableData<T>;
|
|
10
9
|
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;
|
package/build/HashTable/index.js
CHANGED
|
@@ -14,9 +14,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
var HashTable = /** @class */ (function () {
|
|
15
15
|
function HashTable(inputs, _a) {
|
|
16
16
|
if (inputs === void 0) { inputs = {}; }
|
|
17
|
-
var _b = _a === void 0 ? {
|
|
18
|
-
this.
|
|
19
|
-
this._data = new Array(this._maxSize);
|
|
17
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.maxSize, maxSize = _c === void 0 ? 100 : _c;
|
|
18
|
+
this._data = new Array(maxSize);
|
|
20
19
|
for (var _i = 0, _d = Object.entries(inputs); _i < _d.length; _i++) {
|
|
21
20
|
var _e = _d[_i], key = _e[0], value = _e[1];
|
|
22
21
|
this.put(key, value);
|
|
@@ -41,6 +40,13 @@ var HashTable = /** @class */ (function () {
|
|
|
41
40
|
enumerable: false,
|
|
42
41
|
configurable: true
|
|
43
42
|
});
|
|
43
|
+
Object.defineProperty(HashTable.prototype, "maxSize", {
|
|
44
|
+
get: function () {
|
|
45
|
+
return this._data.length;
|
|
46
|
+
},
|
|
47
|
+
enumerable: false,
|
|
48
|
+
configurable: true
|
|
49
|
+
});
|
|
44
50
|
HashTable.prototype.put = function (key, value) {
|
|
45
51
|
var position = this._hashCode(key);
|
|
46
52
|
this._data[position] = value;
|
|
@@ -52,31 +58,27 @@ var HashTable = /** @class */ (function () {
|
|
|
52
58
|
};
|
|
53
59
|
HashTable.prototype.remove = function (key) {
|
|
54
60
|
var value = this.get(key);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return value;
|
|
59
|
-
}
|
|
60
|
-
return null;
|
|
61
|
+
var position = this._hashCode(key);
|
|
62
|
+
Reflect.deleteProperty(this._data, position);
|
|
63
|
+
return value;
|
|
61
64
|
};
|
|
62
65
|
HashTable.prototype._hashCode = function (key) {
|
|
63
66
|
var code = key
|
|
64
67
|
.split('')
|
|
65
68
|
.map(function (character) { return character.charCodeAt(0); })
|
|
66
69
|
.reduce(function (previous, current) { return previous + current; }, 0);
|
|
67
|
-
return code % this.
|
|
70
|
+
return code % this.maxSize;
|
|
68
71
|
};
|
|
69
72
|
HashTable.prototype[Symbol.toPrimitive] = function (type) {
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
var primitives = {
|
|
74
|
+
default: true,
|
|
75
|
+
number: this.size,
|
|
76
|
+
string: "[ ".concat(Object.entries(this.data).map(function (_a) {
|
|
72
77
|
var key = _a[0], value = _a[1];
|
|
73
78
|
return "".concat(key, " => ").concat(value);
|
|
74
|
-
}).join(', '), " ]")
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return this.size;
|
|
78
|
-
}
|
|
79
|
-
return null;
|
|
79
|
+
}).join(', '), " ]"),
|
|
80
|
+
};
|
|
81
|
+
return primitives[type];
|
|
80
82
|
};
|
|
81
83
|
return HashTable;
|
|
82
84
|
}());
|
|
@@ -13,14 +13,12 @@ var LinkedList = /** @class */ (function () {
|
|
|
13
13
|
this._FIRST_POSITION = 0;
|
|
14
14
|
this._head = null;
|
|
15
15
|
this._size = 0;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
nodes[i].next = nodes[i + 1];
|
|
20
|
-
}
|
|
21
|
-
this._head = nodes[0];
|
|
22
|
-
this._size = nodes.length;
|
|
16
|
+
var nodes = inputs.map(function (input) { return new Node_1.default(input); });
|
|
17
|
+
for (var i = 0; i < inputs.length - 1; i++) {
|
|
18
|
+
nodes[i].next = nodes[i + 1];
|
|
23
19
|
}
|
|
20
|
+
this._head = nodes[0];
|
|
21
|
+
this._size = nodes.length;
|
|
24
22
|
}
|
|
25
23
|
Object.defineProperty(LinkedList.prototype, "data", {
|
|
26
24
|
get: function () {
|
|
@@ -153,16 +151,15 @@ var LinkedList = /** @class */ (function () {
|
|
|
153
151
|
return node || undefined;
|
|
154
152
|
};
|
|
155
153
|
LinkedList.prototype[Symbol.toPrimitive] = function (type) {
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
var primitives = {
|
|
155
|
+
default: true,
|
|
156
|
+
number: this.size,
|
|
157
|
+
string: "[Head] ".concat(this.data.map(function (_a) {
|
|
158
158
|
var value = _a.value;
|
|
159
159
|
return value;
|
|
160
|
-
}).join(' => '))
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
return this.size;
|
|
164
|
-
}
|
|
165
|
-
return null;
|
|
160
|
+
}).join(' => ')),
|
|
161
|
+
};
|
|
162
|
+
return primitives[type];
|
|
166
163
|
};
|
|
167
164
|
return LinkedList;
|
|
168
165
|
}());
|
package/build/MaxHeap/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
var MaxHeap = /** @class */ (function () {
|
|
13
13
|
function MaxHeap(_a) {
|
|
14
|
-
var _b = _a === void 0 ? {
|
|
14
|
+
var _b = _a === void 0 ? {} : _a, greaterThanOrEqualTo = _b.greaterThanOrEqualTo, _c = _b.inputs, inputs = _c === void 0 ? [] : _c;
|
|
15
15
|
this._data = [];
|
|
16
16
|
this._greaterThanOrEqualTo = function (value1, value2) { return value1 >= value2; };
|
|
17
17
|
this._getLeftIndex = function (index) { return (2 * index) + 1; };
|
|
@@ -89,13 +89,12 @@ var MaxHeap = /** @class */ (function () {
|
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
91
|
MaxHeap.prototype[Symbol.toPrimitive] = function (type) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return null;
|
|
92
|
+
var primitives = {
|
|
93
|
+
default: true,
|
|
94
|
+
number: this.size,
|
|
95
|
+
string: this.data.join(', '),
|
|
96
|
+
};
|
|
97
|
+
return primitives[type];
|
|
99
98
|
};
|
|
100
99
|
return MaxHeap;
|
|
101
100
|
}());
|
package/build/MinHeap/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
var MinHeap = /** @class */ (function () {
|
|
13
13
|
function MinHeap(_a) {
|
|
14
|
-
var _b = _a === void 0 ? {
|
|
14
|
+
var _b = _a === void 0 ? {} : _a, lessThanOrEqualTo = _b.lessThanOrEqualTo, _c = _b.inputs, inputs = _c === void 0 ? [] : _c;
|
|
15
15
|
this._data = [];
|
|
16
16
|
this._lessThanOrEqualTo = function (value1, value2) { return value1 <= value2; };
|
|
17
17
|
this._getLeftIndex = function (index) { return (2 * index) + 1; };
|
|
@@ -89,13 +89,12 @@ var MinHeap = /** @class */ (function () {
|
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
91
|
MinHeap.prototype[Symbol.toPrimitive] = function (type) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return null;
|
|
92
|
+
var primitives = {
|
|
93
|
+
default: true,
|
|
94
|
+
number: this.size,
|
|
95
|
+
string: this.data.join(', '),
|
|
96
|
+
};
|
|
97
|
+
return primitives[type];
|
|
99
98
|
};
|
|
100
99
|
return MinHeap;
|
|
101
100
|
}());
|