FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaSTUDY1/HashFunction.java at master · Slyrich/JavaSTUDY1 · GitHub
Slyrich
/
JavaSTUDY1
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaSTUDY1
/
HashFunction.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
117 lines (82 loc) · 2.78 KB
Breadcrumbs
JavaSTUDY1
/
HashFunction.java
Copy path
File metadata and controls
117 lines (82 loc) · 2.78 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package
test
;
import
java
.
util
.
Arrays
;
public
class
HashFunction
{
String
[]
theArray
;
int
arraySize
;
int
ItemsInArray
=
0
;
public
static
void
main
(
String
[]
args
){
HashFunction
Func1
=
new
HashFunction
(
60
);
String
[]
abc
= {
"5"
,
"4"
,
"22"
,
"6"
,
"24"
,
"56"
,
"44"
,
"15"
,
"0"
};
String
[]
abc2
= {
"236"
,
"6666"
,
"1098"
,
"2"
,
"4677"
,
"65432"
,
"1001"
,
"817"
,
"18"
,
"82"
,
"71"
,
"99"
,
"109"
,
"152"
,
"111"
,
"100"
,
"8282"
,
"104"
,
"45"
};
Func1
.
hashFunction1
(
abc
,
Func1
.
theArray
);
Func1
.
displayTheStack
();
Func1
.
hashFunction2
(
abc2
,
Func1
.
theArray
);
Func1
.
displayTheStack
();
Func1
.
findKey
(
"44"
);
Func1
.
findKey
(
"1"
);
Func1
.
findKey
(
"236"
);
}
public
void
hashFunction1
(
String
[]
stringForArray
,
String
[]
theArray
){
for
(
int
i
=
0
;
i
<
stringForArray
.
length
;
i
++){
String
newElement
=
stringForArray
[
i
];
theArray
[
Integer
.
parseInt
(
newElement
)]=
newElement
;
}
}
public
void
hashFunction2
(
String
[]
stringForArray
,
String
[]
theArray
){
for
(
int
i
=
0
;
i
<
stringForArray
.
length
;
i
++){
String
newElement
=
stringForArray
[
i
];
int
num
=
Integer
.
parseInt
(
newElement
) %
arraySize
;
System
.
out
.
println
(
"Modulus Index ="
+
num
);
while
(!(
theArray
[
num
]==
"-1"
)){
num
+=
1
;
System
.
out
.
println
(
num
-
1
+
" has a collsion, try "
+
num
);
}
theArray
[
num
] =
newElement
;
}
}
public
String
findKey
(
String
key
){
int
index
=
Integer
.
parseInt
(
key
)%
arraySize
;
while
((
theArray
[
index
]!=
"-1"
)){
if
(
theArray
[
index
]==
key
){
System
.
out
.
println
(
key
+
" was found in"
+
index
);
return
theArray
[
index
];
}
index
++;
System
.
out
.
println
(
"try another one: "
+
index
);
index
%=
arraySize
;
}
return
null
;
}
HashFunction
(
int
size
){
arraySize
=
size
;
theArray
=
new
String
[
size
];
Arrays
.
fill
(
theArray
,
"-1"
);
}
public
void
displayTheStack
() {
int
increment
=
0
;
for
(
int
m
=
0
;
m
<
6
;
m
++) {
increment
+=
10
;
for
(
int
n
=
0
;
n
<
71
;
n
++)
System
.
out
.
print
(
"-"
);
System
.
out
.
println
();
for
(
int
n
=
increment
-
10
;
n
<
increment
;
n
++) {
System
.
out
.
format
(
"| %3s "
+
" "
,
n
);
}
System
.
out
.
println
(
"|"
);
for
(
int
n
=
0
;
n
<
71
;
n
++)
System
.
out
.
print
(
"-"
);
System
.
out
.
println
();
for
(
int
n
=
increment
-
10
;
n
<
increment
;
n
++) {
if
(
theArray
[
n
].
equals
(
"-1"
))
System
.
out
.
print
(
"| "
);
else
System
.
out
.
print
(
String
.
format
(
"| %3s "
+
" "
,
theArray
[
n
]));
}
System
.
out
.
println
(
"|"
);
for
(
int
n
=
0
;
n
<
71
;
n
++)
System
.
out
.
print
(
"-"
);
System
.
out
.
println
();
}
}
}
Back
|
FazBrowse Home
|
New Git URL