Skip to content

Commit 8420d3b

Browse files
fix: fixed type conversion error in datastructures/bloomfilter/BloomFilter.java
1 parent 55f3be8 commit 8420d3b

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/main/java/com/thealgorithms/datastructures/bloomfilter/BloomFilter.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.thealgorithms.datastructures.bloomfilter;
22

3+
import java.util.Arrays;
34
import java.util.BitSet;
45

56
/**
@@ -115,7 +116,38 @@ private static class Hash<T> {
115116
* @return the computed hash value
116117
*/
117118
public int compute(T key) {
118-
return index * asciiString(String.valueOf(key));
119+
String keyString;
120+
if (key instanceof byte[]) {
121+
keyString = Arrays.toString((byte[]) key);
122+
}
123+
else if (key instanceof short[]) {
124+
keyString = Arrays.toString((short[]) key);
125+
}
126+
else if (key instanceof int[]) {
127+
keyString = Arrays.toString((int[]) key);
128+
}
129+
else if (key instanceof long[]) {
130+
keyString = Arrays.toString((long[]) key);
131+
}
132+
else if (key instanceof char[]) {
133+
keyString = Arrays.toString((char[]) key);
134+
}
135+
else if (key instanceof float[]) {
136+
keyString = Arrays.toString((float[]) key);
137+
}
138+
else if (key instanceof double[]) {
139+
keyString = Arrays.toString((double[]) key);
140+
}
141+
else if (key instanceof boolean[]) {
142+
keyString = Arrays.toString((boolean[]) key);
143+
}
144+
else if (key instanceof Object[]) {
145+
keyString = Arrays.deepToString((Object[]) key);
146+
}
147+
else {
148+
keyString = String.valueOf(key);
149+
}
150+
return index * asciiString(String.valueOf(keyString));
119151
}
120152

121153
/**

src/test/java/com/thealgorithms/strings/RemoveStarsTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertNull;
5-
65
import org.junit.jupiter.api.Test;
76

87
class RemoveStarsTest {

0 commit comments

Comments
 (0)