@gabrielrufino/cube 1.0.24 → 1.0.27
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/Graph/index.js +16 -20
- package/build/HashTableLinearProbing/index.js +7 -10
- package/build/HashTableSeparateChaining/HashTableSeparateChainingElement.js +6 -7
- package/build/HashTableSeparateChaining/IHashTableSeparateChaining.d.ts +1 -0
- package/build/HashTableSeparateChaining/index.d.ts +1 -1
- package/build/HashTableSeparateChaining/index.js +17 -12
- package/package.json +9 -9
package/build/Graph/index.js
CHANGED
|
@@ -30,7 +30,7 @@ var Queue_1 = __importDefault(require("../Queue"));
|
|
|
30
30
|
var Set_1 = __importDefault(require("../Set"));
|
|
31
31
|
var Graph = /** @class */ (function () {
|
|
32
32
|
function Graph(_a) {
|
|
33
|
-
var _b = _a === void 0 ? {
|
|
33
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.inputs, inputs = _c === void 0 ? {} : _c, _d = _b.isDirected, isDirected = _d === void 0 ? false : _d;
|
|
34
34
|
this._isDirected = isDirected;
|
|
35
35
|
this._data = new Dictionary_1.default();
|
|
36
36
|
var nodes = Object.keys(inputs);
|
|
@@ -135,15 +135,13 @@ var Graph = /** @class */ (function () {
|
|
|
135
135
|
queue.enqueue(startNode);
|
|
136
136
|
while (!queue.isEmpty) {
|
|
137
137
|
var current = queue.dequeue() || '';
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
queue.enqueue(neighbor);
|
|
146
|
-
}
|
|
138
|
+
states[current] = GraphSearchNodeStates_1.default.DISCOVERED;
|
|
139
|
+
var neighbors = ((_a = this._data.get(current)) === null || _a === void 0 ? void 0 : _a.data) || [];
|
|
140
|
+
var unexploredNeighbors = neighbors.filter(function (neighbor) { return states[neighbor] === GraphSearchNodeStates_1.default.UNEXPLORED; });
|
|
141
|
+
for (var _i = 0, unexploredNeighbors_1 = unexploredNeighbors; _i < unexploredNeighbors_1.length; _i++) {
|
|
142
|
+
var neighbor = unexploredNeighbors_1[_i];
|
|
143
|
+
states[neighbor] = GraphSearchNodeStates_1.default.DISCOVERED;
|
|
144
|
+
queue.enqueue(neighbor);
|
|
147
145
|
}
|
|
148
146
|
states[current] = GraphSearchNodeStates_1.default.EXPLORED;
|
|
149
147
|
callback(current);
|
|
@@ -167,16 +165,14 @@ var Graph = /** @class */ (function () {
|
|
|
167
165
|
queue.enqueue(node);
|
|
168
166
|
while (!queue.isEmpty) {
|
|
169
167
|
var current = queue.dequeue() || '';
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
queue.enqueue(neighbor);
|
|
179
|
-
}
|
|
168
|
+
states[current] = GraphSearchNodeStates_1.default.DISCOVERED;
|
|
169
|
+
var neighbors = ((_a = this._data.get(current)) === null || _a === void 0 ? void 0 : _a.data) || [];
|
|
170
|
+
var unexploredNeighbors = neighbors.filter(function (neighbor) { return states[neighbor] === GraphSearchNodeStates_1.default.UNEXPLORED; });
|
|
171
|
+
for (var _i = 0, unexploredNeighbors_2 = unexploredNeighbors; _i < unexploredNeighbors_2.length; _i++) {
|
|
172
|
+
var neighbor = unexploredNeighbors_2[_i];
|
|
173
|
+
states[neighbor] = GraphSearchNodeStates_1.default.DISCOVERED;
|
|
174
|
+
distances[neighbor] = distances[current] + 1;
|
|
175
|
+
queue.enqueue(neighbor);
|
|
180
176
|
}
|
|
181
177
|
states[current] = GraphSearchNodeStates_1.default.EXPLORED;
|
|
182
178
|
}
|
|
@@ -86,9 +86,7 @@ var HashTableLinearProbing = /** @class */ (function () {
|
|
|
86
86
|
&& this._nextPositionOf(i) !== position; i = this._nextPositionOf(i)) {
|
|
87
87
|
this._data[i] = this._data[this._nextPositionOf(i)];
|
|
88
88
|
}
|
|
89
|
-
|
|
90
|
-
Reflect.deleteProperty(this._data, i);
|
|
91
|
-
}
|
|
89
|
+
Reflect.deleteProperty(this._data, i);
|
|
92
90
|
return value;
|
|
93
91
|
}
|
|
94
92
|
return null;
|
|
@@ -107,13 +105,12 @@ var HashTableLinearProbing = /** @class */ (function () {
|
|
|
107
105
|
return (position + this.size - 1) % this._maxSize;
|
|
108
106
|
};
|
|
109
107
|
HashTableLinearProbing.prototype[Symbol.toPrimitive] = function (type) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return null;
|
|
108
|
+
var primitives = {
|
|
109
|
+
default: true,
|
|
110
|
+
number: this.size,
|
|
111
|
+
string: "[ ".concat(Object.values(this.data).join(', '), " ]"),
|
|
112
|
+
};
|
|
113
|
+
return primitives[type];
|
|
117
114
|
};
|
|
118
115
|
return HashTableLinearProbing;
|
|
119
116
|
}());
|
|
@@ -8,13 +8,12 @@ var HashTableSeparateChainingElement = /** @class */ (function () {
|
|
|
8
8
|
this.value = value;
|
|
9
9
|
}
|
|
10
10
|
HashTableSeparateChainingElement.prototype[Symbol.toPrimitive] = function (type) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return null;
|
|
11
|
+
var primitives = {
|
|
12
|
+
default: true,
|
|
13
|
+
number: 2,
|
|
14
|
+
string: "{ ".concat(this.key, " => ").concat(this.value, "}"),
|
|
15
|
+
};
|
|
16
|
+
return primitives[type];
|
|
18
17
|
};
|
|
19
18
|
return HashTableSeparateChainingElement;
|
|
20
19
|
}());
|
|
@@ -3,6 +3,7 @@ import IHashTableSeparateChainingData from './IHashTableSeparateChainingData';
|
|
|
3
3
|
interface IHashTableSeparateChaining<T> {
|
|
4
4
|
get data(): IHashTableSeparateChainingData<T>;
|
|
5
5
|
get size(): number;
|
|
6
|
+
get maxSize(): number;
|
|
6
7
|
put(_key: string, _value: T): T;
|
|
7
8
|
get(_key: string): HashTableSeparateChainingElement<T> | null;
|
|
8
9
|
remove(_key: string): HashTableSeparateChainingElement<T> | null;
|
|
@@ -3,13 +3,13 @@ import IHashTableSeparateChaining from './IHashTableSeparateChaining';
|
|
|
3
3
|
import IHashTableSeparateChainingData from './IHashTableSeparateChainingData';
|
|
4
4
|
import IHashTableSeparateChainingInputs from './IHashTableSeparateChainingInputs';
|
|
5
5
|
export default class HashTableSeparateChaining<T = number> implements IHashTableSeparateChaining<T> {
|
|
6
|
-
private _maxSize;
|
|
7
6
|
private _data;
|
|
8
7
|
constructor(inputs?: IHashTableSeparateChainingInputs<T>, { maxSize }?: {
|
|
9
8
|
maxSize: number;
|
|
10
9
|
});
|
|
11
10
|
get data(): IHashTableSeparateChainingData<T>;
|
|
12
11
|
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;
|
|
@@ -20,8 +20,7 @@ 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.
|
|
24
|
-
this._data = new Array(this._maxSize);
|
|
23
|
+
this._data = new Array(maxSize);
|
|
25
24
|
for (var _i = 0, _c = Object.entries(inputs); _i < _c.length; _i++) {
|
|
26
25
|
var _d = _c[_i], key = _d[0], value = _d[1];
|
|
27
26
|
this.put(key, value);
|
|
@@ -30,10 +29,10 @@ var HashTableSeparateChaining = /** @class */ (function () {
|
|
|
30
29
|
Object.defineProperty(HashTableSeparateChaining.prototype, "data", {
|
|
31
30
|
get: function () {
|
|
32
31
|
return this._data
|
|
33
|
-
.map(function (value,
|
|
32
|
+
.map(function (value, index) { return ({ index: index, value: value }); })
|
|
34
33
|
.reduce(function (accumulator, current) {
|
|
35
34
|
var _a;
|
|
36
|
-
return (__assign(__assign({}, accumulator), (_a = {}, _a[current.
|
|
35
|
+
return (__assign(__assign({}, accumulator), (_a = {}, _a[current.index] = current.value, _a)));
|
|
37
36
|
}, {});
|
|
38
37
|
},
|
|
39
38
|
enumerable: false,
|
|
@@ -46,6 +45,13 @@ var HashTableSeparateChaining = /** @class */ (function () {
|
|
|
46
45
|
enumerable: false,
|
|
47
46
|
configurable: true
|
|
48
47
|
});
|
|
48
|
+
Object.defineProperty(HashTableSeparateChaining.prototype, "maxSize", {
|
|
49
|
+
get: function () {
|
|
50
|
+
return this._data.length;
|
|
51
|
+
},
|
|
52
|
+
enumerable: false,
|
|
53
|
+
configurable: true
|
|
54
|
+
});
|
|
49
55
|
HashTableSeparateChaining.prototype.put = function (key, value) {
|
|
50
56
|
var linkedList = this._getLinkedListByKey(key);
|
|
51
57
|
var element = new HashTableSeparateChainingElement_1.default(key, value);
|
|
@@ -88,16 +94,15 @@ var HashTableSeparateChaining = /** @class */ (function () {
|
|
|
88
94
|
.split('')
|
|
89
95
|
.map(function (character) { return character.charCodeAt(0); })
|
|
90
96
|
.reduce(function (previous, current) { return previous + current; }, 0);
|
|
91
|
-
return code % this.
|
|
97
|
+
return code % this.maxSize;
|
|
92
98
|
};
|
|
93
99
|
HashTableSeparateChaining.prototype[Symbol.toPrimitive] = function (type) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return null;
|
|
100
|
+
var primitives = {
|
|
101
|
+
default: true,
|
|
102
|
+
number: this.size,
|
|
103
|
+
string: "[ ".concat(Object.values(this.data).map(String).join(', '), " ]"),
|
|
104
|
+
};
|
|
105
|
+
return primitives[type];
|
|
101
106
|
};
|
|
102
107
|
return HashTableSeparateChaining;
|
|
103
108
|
}());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gabrielrufino/cube",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.27",
|
|
4
4
|
"description": "Data Structures and Algorithms made in Typescript",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,20 +28,20 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/gabrielrufino/cube#readme",
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@faker-js/faker": "^6.1
|
|
31
|
+
"@faker-js/faker": "^6.3.1",
|
|
32
32
|
"@stryker-mutator/core": "^6.0.2",
|
|
33
33
|
"@stryker-mutator/jest-runner": "^6.0.2",
|
|
34
34
|
"@stryker-mutator/typescript-checker": "^6.0.2",
|
|
35
|
-
"@types/jest": "^27.
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
37
|
-
"@typescript-eslint/parser": "^5.
|
|
38
|
-
"eslint": "^8.
|
|
35
|
+
"@types/jest": "^27.5.1",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "^5.26.0",
|
|
37
|
+
"@typescript-eslint/parser": "^5.26.0",
|
|
38
|
+
"eslint": "^8.16.0",
|
|
39
39
|
"eslint-config-xo": "^0.39.0",
|
|
40
40
|
"jest": "^27.5.1",
|
|
41
41
|
"rimraf": "^3.0.2",
|
|
42
42
|
"stryker-cli": "^1.0.2",
|
|
43
|
-
"ts-jest": "^27.1.
|
|
44
|
-
"ts-node": "^10.
|
|
45
|
-
"typescript": "^4.
|
|
43
|
+
"ts-jest": "^27.1.5",
|
|
44
|
+
"ts-node": "^10.8.0",
|
|
45
|
+
"typescript": "^4.7.2"
|
|
46
46
|
}
|
|
47
47
|
}
|