18 return Slice(buffer,
sizeof(uint32_t));
44 std::vector<Slice> key_slices;
45 for (
size_t i = 0; i < keys_.size(); i++) {
46 key_slices.push_back(
Slice(keys_[i]));
49 policy_->
CreateFilter(&key_slices[0], static_cast<int>(key_slices.size()),
56 return filter_.size();
60 fprintf(stderr,
"F(");
61 for (
size_t i = 0; i+1 < filter_.size(); i++) {
62 const unsigned int c =
static_cast<unsigned int>(filter_[i]);
63 for (
int j = 0; j < 8; j++) {
64 fprintf(stderr,
"%c", (c & (1 <<j)) ?
'1' :
'.');
67 fprintf(stderr,
")\n");
78 char buffer[
sizeof(int)];
80 for (
int i = 0; i < 10000; i++) {
85 return result / 10000.0;
106 }
else if (length < 100) {
108 }
else if (length < 1000) {
117 char buffer[
sizeof(int)];
120 int mediocre_filters = 0;
121 int good_filters = 0;
123 for (
int length = 1; length <= 10000; length =
NextLength(length)) {
125 for (
int i = 0; i < length; i++) {
134 for (
int i = 0; i < length; i++) {
136 <<
"Length " << length <<
"; key " << i;
142 fprintf(stderr,
"False positives: %5.2f%% @ length = %6d ; bytes = %6d\n",
143 rate*100.0, length, static_cast<int>(
FilterSize()));
146 if (rate > 0.0125) mediocre_filters++;
150 fprintf(stderr,
"Filters: %d good, %d mediocre\n",
151 good_filters, mediocre_filters);
153 ASSERT_LE(mediocre_filters, good_filters/5);
160 int main(
int argc,
char** argv) {
virtual bool KeyMayMatch(const Slice &key, const Slice &filter) const =0
void EncodeFixed32(char *buf, uint32_t value)
std::string ToString() const
const FilterPolicy * NewBloomFilterPolicy(int bits_per_key)
TEST(AutoCompactTest, ReadAll)
int main(int argc, char **argv)
std::vector< std::string > keys_
bool Matches(const Slice &s)
double FalsePositiveRate()
size_t FilterSize() const
virtual void CreateFilter(const Slice *keys, int n, std::string *dst) const =0
static int NextLength(int length)
const FilterPolicy * policy_
static const int kVerbose