@@ -122,33 +122,37 @@ public BloomFilter(int bitSetSize, int expectedNumberOfFilterElements, int actua
122122 *
123123 * @param val specifies the input data.
124124 * @param charset specifies the encoding of the input data.
125+ * @param salt to use for the digest function
125126 * @return digest as long.
126127 */
127- public static long createHash (String val , Charset charset ) {
128- return createHash (val .getBytes (charset ));
128+ public static int createHash (String val , Charset charset , byte salt ) {
129+ return createHash (val .getBytes (charset ), salt );
129130 }
130131
131132 /**
132133 * Generates a digest based on the contents of a String.
133134 *
134135 * @param val specifies the input data. The encoding is expected to be UTF-8.
136+ * @param salt to use for the digest function
135137 * @return digest as long.
136138 */
137- public static long createHash (String val ) {
138- return createHash (val , charset );
139+ public static int createHash (String val , byte salt ) {
140+ return createHash (val , charset , salt );
139141 }
140142
141143 /**
142144 * Generates a digest based on the contents of an array of bytes.
143145 *
144146 * @param data specifies input data.
147+ * @param salt to use for the digest function
145148 * @return digest as long.
146149 */
147- public static long createHash (byte [] data ) {
148- long h = 0 ;
150+ public static int createHash (byte [] data , byte salt ) {
151+ int h = 0 ;
149152 byte [] res ;
150153
151154 synchronized (digestFunction ) {
155+ digestFunction .update (salt );
152156 res = digestFunction .digest (data );
153157 }
154158
@@ -272,9 +276,9 @@ public void clear() {
272276 */
273277 public void add (E element ) {
274278 long hash ;
275- String valString = element .toString ();
279+ byte [] data = element .toString (). getBytes ( charset );
276280 for (int x = 0 ; x < k ; x ++) {
277- hash = createHash (valString + Integer . toString ( x ) );
281+ hash = createHash (data , ( byte ) x );
278282 hash = hash % (long )bitSetSize ;
279283 bitset .set (Math .abs ((int )hash ), true );
280284 }
@@ -300,9 +304,9 @@ public void addAll(Collection<? extends E> c) {
300304 */
301305 public boolean contains (E element ) {
302306 long hash ;
303- String valString = element .toString ();
307+ byte [] data = element .toString (). getBytes ( charset );
304308 for (int x = 0 ; x < k ; x ++) {
305- hash = createHash (valString + Integer . toString ( x ) );
309+ hash = createHash (data , ( byte ) x );
306310 hash = hash % (long )bitSetSize ;
307311 if (!bitset .get (Math .abs ((int )hash )))
308312 return false ;
0 commit comments