@gabrielrufino/cube 1.0.26 → 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.
@@ -8,13 +8,12 @@ var HashTableSeparateChainingElement = /** @class */ (function () {
8
8
  this.value = value;
9
9
  }
10
10
  HashTableSeparateChainingElement.prototype[Symbol.toPrimitive] = function (type) {
11
- if (type === 'string') {
12
- return "{ ".concat(this.key, " => ").concat(this.value, "}");
13
- }
14
- if (type === 'number') {
15
- return 2;
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._maxSize = maxSize;
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, key) { return ({ key: key, value: 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.key] = current.value, _a)));
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._maxSize;
97
+ return code % this.maxSize;
92
98
  };
93
99
  HashTableSeparateChaining.prototype[Symbol.toPrimitive] = function (type) {
94
- if (type === 'string') {
95
- return "[ ".concat(Object.values(this.data).map(String).join(', '), " ]");
96
- }
97
- if (type === 'number') {
98
- return this.size;
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.26",
3
+ "version": "1.0.27",
4
4
  "description": "Data Structures and Algorithms made in Typescript",
5
5
  "main": "build/index.js",
6
6
  "scripts": {