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