/*
   Copyright 2018-2019 Banco Bilbao Vizcaya Argentaria, S.A.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

package rocksdb

// #include <rocksdb/c.h>
import "C"

type FilterPolicy struct {
	policy *C.rocksdb_filterpolicy_t
}

// NewBloomFilterPolicy returns a new filter policy that uses a block-based
// bloom filter with approximately the specified number of bits per key.
// A good value for bits_per_key is 10, which yields a filter with ~1% false
// positive rate.
//
// Note: if you are using a custom comparator that ignores some parts
// of the keys being compared, you must not use NewBloomFilterPolicy()
// and must provide your own FilterPolicy that also ignores the
// corresponding parts of the keys.  For example, if the comparator
// ignores trailing spaces, it would be incorrect to use a
// FilterPolicy (like NewBloomFilterPolicy) that does not ignore
// trailing spaces in keys.
func NewBloomFilterPolicy(bitsPerKey int) *FilterPolicy {
	return &FilterPolicy{C.rocksdb_filterpolicy_create_bloom(C.int(bitsPerKey))}
}

// NewFullBloomFilterPolicy returns a new filter policy that uses a full bloom filter
// for the entire SST file, with approximately the specified number of bits per key.
// A good value for bits_per_key is 10, which yields a filter with ~1% false positive rate.
//
// Note: if you are using a custom comparator that ignores some parts
// of the keys being compared, you must not use NewBloomFilterPolicy()
// and must provide your own FilterPolicy that also ignores the
// corresponding parts of the keys.  For example, if the comparator
// ignores trailing spaces, it would be incorrect to use a
// FilterPolicy (like NewBloomFilterPolicy) that does not ignore
// trailing spaces in keys.
func NewFullBloomFilterPolicy(bitsPerKey int) *FilterPolicy {
	return &FilterPolicy{C.rocksdb_filterpolicy_create_bloom_full(C.int(bitsPerKey))}
}
