]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/main/java/org/rocksdb/BloomFilter.java
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / BloomFilter.java
1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
5
6 package org.rocksdb;
7
8 /**
9 * Bloom filter policy that uses a bloom filter with approximately
10 * the specified number of bits per key.
11 *
12 * <p>
13 * Note: if you are using a custom comparator that ignores some parts
14 * of the keys being compared, you must not use this {@code BloomFilter}
15 * and must provide your own FilterPolicy that also ignores the
16 * corresponding parts of the keys. For example, if the comparator
17 * ignores trailing spaces, it would be incorrect to use a
18 * FilterPolicy (like {@code BloomFilter}) that does not ignore
19 * trailing spaces in keys.</p>
20 */
21 public class BloomFilter extends Filter {
22
23 private static final int DEFAULT_BITS_PER_KEY = 10;
24 private static final boolean DEFAULT_MODE = true;
25
26 /**
27 * BloomFilter constructor
28 *
29 * <p>
30 * Callers must delete the result after any database that is using the
31 * result has been closed.</p>
32 */
33 public BloomFilter() {
34 this(DEFAULT_BITS_PER_KEY, DEFAULT_MODE);
35 }
36
37 /**
38 * BloomFilter constructor
39 *
40 * <p>
41 * bits_per_key: bits per key in bloom filter. A good value for bits_per_key
42 * is 10, which yields a filter with ~ 1% false positive rate.
43 * </p>
44 * <p>
45 * Callers must delete the result after any database that is using the
46 * result has been closed.</p>
47 *
48 * @param bitsPerKey number of bits to use
49 */
50 public BloomFilter(final int bitsPerKey) {
51 this(bitsPerKey, DEFAULT_MODE);
52 }
53
54 /**
55 * BloomFilter constructor
56 *
57 * <p>
58 * bits_per_key: bits per key in bloom filter. A good value for bits_per_key
59 * is 10, which yields a filter with ~ 1% false positive rate.
60 * <p><strong>default bits_per_key</strong>: 10</p>
61 *
62 * <p>use_block_based_builder: use block based filter rather than full filter.
63 * If you want to builder full filter, it needs to be set to false.
64 * </p>
65 * <p><strong>default mode: block based filter</strong></p>
66 * <p>
67 * Callers must delete the result after any database that is using the
68 * result has been closed.</p>
69 *
70 * @param bitsPerKey number of bits to use
71 * @param useBlockBasedMode use block based mode or full filter mode
72 */
73 public BloomFilter(final int bitsPerKey, final boolean useBlockBasedMode) {
74 super(createNewBloomFilter(bitsPerKey, useBlockBasedMode));
75 }
76
77 private native static long createNewBloomFilter(final int bitsKeyKey,
78 final boolean useBlockBasedMode);
79 }