@gabrielrufino/cube 1.0.17 → 1.0.20
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/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/MaxHeap/index.js +7 -8
- package/build/MinHeap/index.js +7 -8
- package/build/Queue/index.js +6 -7
- package/build/Stack/index.js +6 -7
- package/package.json +1 -1
|
@@ -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
|
}());
|
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
|
}());
|
package/build/Queue/index.js
CHANGED
|
@@ -61,13 +61,12 @@ var Queue = /** @class */ (function (_super) {
|
|
|
61
61
|
this._data = [];
|
|
62
62
|
};
|
|
63
63
|
Queue.prototype[Symbol.toPrimitive] = function (type) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return null;
|
|
64
|
+
var primitives = {
|
|
65
|
+
default: true,
|
|
66
|
+
number: this.size,
|
|
67
|
+
string: "[Front] ".concat(this.data.join(', ')),
|
|
68
|
+
};
|
|
69
|
+
return primitives[type];
|
|
71
70
|
};
|
|
72
71
|
return Queue;
|
|
73
72
|
}(DataStructure_1.default));
|
package/build/Stack/index.js
CHANGED
|
@@ -51,13 +51,12 @@ var Stack = /** @class */ (function (_super) {
|
|
|
51
51
|
configurable: true
|
|
52
52
|
});
|
|
53
53
|
Stack.prototype[Symbol.toPrimitive] = function (type) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return null;
|
|
54
|
+
var primitives = {
|
|
55
|
+
default: true,
|
|
56
|
+
number: this.size,
|
|
57
|
+
string: "".concat(this.data.join(', '), " [Top]"),
|
|
58
|
+
};
|
|
59
|
+
return primitives[type];
|
|
61
60
|
};
|
|
62
61
|
return Stack;
|
|
63
62
|
}(DataStructure_1.default));
|