Skip to content

Commit 9af10ba

Browse files
committed
need quokka; setup for node logging
1 parent ba2d8dc commit 9af10ba

File tree

7 files changed

+5291
-30
lines changed

7 files changed

+5291
-30
lines changed

.huskyrc.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +0,0 @@
1-
{
2-
"hooks": {
3-
"pre-commit": "npm run lint && npm run test"
4-
}
5-
}

src/data-structures/bloom-filter/BloomFilter.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default class BloomFilter {
1+
module.exports = class BloomFilter {
22
/**
33
* @param {number} size - the size of the storage.
44
*/
@@ -50,7 +50,11 @@ export default class BloomFilter {
5050
const storage = [];
5151

5252
// Initialize all indexes to false
53-
for (let storageCellIndex = 0; storageCellIndex < size; storageCellIndex += 1) {
53+
for (
54+
let storageCellIndex = 0;
55+
storageCellIndex < size;
56+
storageCellIndex += 1
57+
) {
5458
storage.push(false);
5559
}
5660

@@ -122,10 +126,6 @@ export default class BloomFilter {
122126
* @return {number[]}
123127
*/
124128
getHashValues(item) {
125-
return [
126-
this.hash1(item),
127-
this.hash2(item),
128-
this.hash3(item),
129-
];
129+
return [this.hash1(item), this.hash2(item), this.hash3(item)];
130130
}
131-
}
131+
};

src/data-structures/hash-table/HashTable.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
import LinkedList from '../linked-list/LinkedList';
1+
const LinkedList = require('../linked-list/LinkedList');
22

33
// Hash table size directly affects on the number of collisions.
44
// The bigger the hash table size the less collisions you'll get.
55
// For demonstrating purposes hash table size is small to show how collisions
66
// are being handled.
77
const defaultHashTableSize = 32;
88

9-
export default class HashTable {
9+
module.exports = class HashTable {
1010
/**
1111
* @param {number} hashTableSize
1212
*/
1313
constructor(hashTableSize = defaultHashTableSize) {
1414
// Create hash table of certain size and fill each bucket with empty linked list.
15-
this.buckets = Array(hashTableSize).fill(null).map(() => new LinkedList());
15+
this.buckets = Array(hashTableSize)
16+
.fill(null)
17+
.map(() => new LinkedList());
1618

1719
// Just to keep track of all actual keys in a fast way.
1820
this.keys = {};
@@ -36,7 +38,7 @@ export default class HashTable {
3638
// where charCodeAt(i) is the i-th character code of the key, n is the length of the key and
3739
// PRIME is just any prime number like 31.
3840
const hash = Array.from(key).reduce(
39-
(hashAccumulator, keySymbol) => (hashAccumulator + keySymbol.charCodeAt(0)),
41+
(hashAccumulator, keySymbol) => hashAccumulator + keySymbol.charCodeAt(0),
4042
0,
4143
);
4244

@@ -52,7 +54,9 @@ export default class HashTable {
5254
const keyHash = this.hash(key);
5355
this.keys[key] = keyHash;
5456
const bucketLinkedList = this.buckets[keyHash];
55-
const node = bucketLinkedList.find({ callback: nodeValue => nodeValue.key === key });
57+
const node = bucketLinkedList.find({
58+
callback: nodeValue => nodeValue.key === key,
59+
});
5660

5761
if (!node) {
5862
// Insert new node.
@@ -71,7 +75,9 @@ export default class HashTable {
7175
const keyHash = this.hash(key);
7276
delete this.keys[key];
7377
const bucketLinkedList = this.buckets[keyHash];
74-
const node = bucketLinkedList.find({ callback: nodeValue => nodeValue.key === key });
78+
const node = bucketLinkedList.find({
79+
callback: nodeValue => nodeValue.key === key,
80+
});
7581

7682
if (node) {
7783
return bucketLinkedList.delete(node.value);
@@ -86,7 +92,9 @@ export default class HashTable {
8692
*/
8793
get(key) {
8894
const bucketLinkedList = this.buckets[this.hash(key)];
89-
const node = bucketLinkedList.find({ callback: nodeValue => nodeValue.key === key });
95+
const node = bucketLinkedList.find({
96+
callback: nodeValue => nodeValue.key === key,
97+
});
9098

9199
return node ? node.value.value : undefined;
92100
}
@@ -105,4 +113,4 @@ export default class HashTable {
105113
getKeys() {
106114
return Object.keys(this.keys);
107115
}
108-
}
116+
};

src/data-structures/linked-list/LinkedList.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import LinkedListNode from './LinkedListNode';
2-
import Comparator from '../../utils/comparator/Comparator';
1+
const LinkedListNode = require('./LinkedListNode');
2+
const Comparator = require('../../utils/comparator/Comparator');
33

4-
export default class LinkedList {
4+
module.exports = class LinkedList {
55
/**
66
* @param {Function} [comparatorFunction]
77
*/
@@ -205,7 +205,9 @@ export default class LinkedList {
205205
* @return {string}
206206
*/
207207
toString(callback) {
208-
return this.toArray().map(node => node.toString(callback)).toString();
208+
return this.toArray()
209+
.map(node => node.toString(callback))
210+
.toString();
209211
}
210212

211213
/**
@@ -235,4 +237,4 @@ export default class LinkedList {
235237

236238
return this;
237239
}
238-
}
240+
};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default class LinkedListNode {
1+
module.exports = class LinkedListNode {
22
constructor(value, next = null) {
33
this.value = value;
44
this.next = next;
@@ -7,4 +7,4 @@ export default class LinkedListNode {
77
toString(callback) {
88
return callback ? callback(this.value) : `${this.value}`;
99
}
10-
}
10+
};

src/utils/comparator/Comparator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default class Comparator {
1+
module.exports = class Comparator {
22
/**
33
* @param {function(a: *, b: *)} [compareFunction] - It may be custom compare function that, let's
44
* say may compare custom objects together.
@@ -78,4 +78,4 @@ export default class Comparator {
7878
const compareOriginal = this.compare;
7979
this.compare = (a, b) => compareOriginal(b, a);
8080
}
81-
}
81+
};

0 commit comments

Comments
 (0)