1 /*
2 * Copyright 2010 The Apache Software Foundation
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 package org.apache.hadoop.hbase.util;
21
22 import java.nio.ByteBuffer;
23
24 /**
25 * Defines the general behavior of a bloom filter.
26 *
27 * <p>
28 * The Bloom filter is a data structure that was introduced in 1970 and that
29 * has been adopted by the networking research community in the past decade
30 * thanks to the bandwidth efficiencies that it offers for the transmission of
31 * set membership information between networked hosts. A sender encodes the
32 * information into a bit vector, the Bloom filter, that is more compact than a
33 * conventional representation. Computation and space costs for construction
34 * are linear in the number of elements. The receiver uses the filter to test
35 * whether various elements are members of the set. Though the filter will
36 * occasionally return a false positive, it will never return a false negative.
37 * When creating the filter, the sender can choose its desired point in a
38 * trade-off between the false positive rate and the size.
39 *
40 * @see BloomFilterWriter for the ability to add elements to a Bloom filter
41 */
42 public interface BloomFilter extends BloomFilterBase {
43
44 /**
45 * Check if the specified key is contained in the bloom filter.
46 *
47 * @param buf data to check for existence of
48 * @param offset offset into the data
49 * @param length length of the data
50 * @param bloom bloom filter data to search. This can be null if auto-loading
51 * is supported.
52 * @return true if matched by bloom, false if not
53 */
54 boolean contains(byte [] buf, int offset, int length, ByteBuffer bloom);
55
56 /**
57 * @return true if this Bloom filter can automatically load its data
58 * and thus allows a null byte buffer to be passed to contains()
59 */
60 boolean supportsAutoLoading();
61 }