FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java/DataStructures/HashMap/Hashing/HashMap.java at master · roysh/Java · GitHub
roysh
/
Java
Public
forked from
TheAlgorithms/Java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java
/
DataStructures
/
HashMap
/
Hashing
/
HashMap.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (32 loc) · 737 Bytes
Breadcrumbs
Java
/
DataStructures
/
HashMap
/
Hashing
/
HashMap.java
Copy path
File metadata and controls
39 lines (32 loc) · 737 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
class
HashMap
{
private
int
hsize
;
private
LinkedList
[]
buckets
;
public
HashMap
(
int
hsize
) {
buckets
=
new
LinkedList
[
hsize
];
for
(
int
i
=
0
;
i
<
hsize
;
i
++ ) {
buckets
[
i
] =
new
LinkedList
();
// Java requires explicit initialisaton of each object
}
this
.
hsize
=
hsize
;
}
public
int
hashing
(
int
key
) {
int
hash
=
key
%
hsize
;
if
(
hash
<
0
)
hash
+=
hsize
;
return
hash
;
}
public
void
insertHash
(
int
key
) {
int
hash
=
hashing
(
key
);
buckets
[
hash
].
insert
(
key
);
}
public
void
deleteHash
(
int
key
) {
int
hash
=
hashing
(
key
);
buckets
[
hash
].
delete
(
key
);
}
public
void
displayHashtable
() {
for
(
int
i
=
0
;
i
<
hsize
;
i
++) {
System
.
out
.
printf
(
"Bucket %d :"
,
i
);
buckets
[
i
].
display
();
}
}
}
Back
|
FazBrowse Home
|
New Git URL