1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.collections4.bloomfilter;
18
19 import java.util.Objects;
20 import java.util.function.IntPredicate;
21
22
23
24
25
26
27 public final class ArrayHasher implements Hasher {
28 private final class Extractor implements IndexExtractor {
29 Shape shape;
30
31 Extractor(final Shape shape) {
32 this.shape = shape;
33 }
34
35 @Override
36 public boolean processIndices(final IntPredicate consumer) {
37 Objects.requireNonNull(consumer, "consumer");
38
39 int pos = 0;
40 for (int i = 0; i < shape.getNumberOfHashFunctions(); i++) {
41 final int result = values[pos++] % shape.getNumberOfBits();
42 pos %= values.length;
43 if (!consumer.test(result)) {
44 return false;
45 }
46 }
47 return true;
48 }
49 }
50
51 private final int[] values;
52
53 public ArrayHasher(final int... values) {
54 this.values = values;
55 }
56
57 @Override
58 public IndexExtractor indices(final Shape shape) {
59 Objects.requireNonNull(shape, "shape");
60 return new Extractor(shape);
61 }
62 }