-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeparateChainingHash.js
More file actions
42 lines (30 loc) · 888 Bytes
/
SeparateChainingHash.js
File metadata and controls
42 lines (30 loc) · 888 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const Search = require("../Search")
const SequentialSearch = require("../symbol-table/SequentialSearch")
class SeparateChainingHash extends Search {
#keyValuePairsCount
#hashTableSize
#sequentialSearchTables
constructor() {
super()
this.#keyValuePairsCount = 0
this.#hashTableSize = 0
this.#sequentialSearchTables = []
}
get (key) {
const hash = this.generateHash(key)
const sequentialSearchTable = this.#sequentialSearchTables[hash]
if (!sequentialSearchTable) {
return null
}
const value = sequentialSearchTable.get(key)
return value
}
put (key, value) {
const hash = this.generateHash(key)
if (!this.#sequentialSearchTables[hash]) {
this.#sequentialSearchTables[hash] = new SequentialSearch()
}
this.#sequentialSearchTables[hash].put(key, value)
}
}
module.exports = SeparateChainingHash