mirror of
https://github.moeyy.xyz/https://github.com/trekhleb/javascript-algorithms.git
synced 2024-09-20 07:43:04 +08:00
addressed issue 1033, changed while to if in LinkedList and add new before Array in HashTable constructor
This commit is contained in:
parent
8c5e5f4f0d
commit
085bb2973e
@ -12,7 +12,7 @@ export default class HashTable {
|
|||||||
*/
|
*/
|
||||||
constructor(hashTableSize = defaultHashTableSize) {
|
constructor(hashTableSize = defaultHashTableSize) {
|
||||||
// Create hash table of certain size and fill each bucket with empty linked list.
|
// Create hash table of certain size and fill each bucket with empty linked list.
|
||||||
this.buckets = Array(hashTableSize).fill(null).map(() => new LinkedList());
|
this.buckets = new Array(hashTableSize).fill(null).map(() => new LinkedList());
|
||||||
|
|
||||||
// Just to keep track of all actual keys in a fast way.
|
// Just to keep track of all actual keys in a fast way.
|
||||||
this.keys = {};
|
this.keys = {};
|
||||||
|
@ -101,7 +101,7 @@ export default class LinkedList {
|
|||||||
|
|
||||||
// If the head must be deleted then make next node that is different
|
// If the head must be deleted then make next node that is different
|
||||||
// from the head to be a new head.
|
// from the head to be a new head.
|
||||||
while (this.head && this.compare.equal(this.head.value, value)) {
|
if (this.head && this.compare.equal(this.head.value, value)) {
|
||||||
deletedNode = this.head;
|
deletedNode = this.head;
|
||||||
this.head = this.head.next;
|
this.head = this.head.next;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user