From d910bf9b8a986455a902580657f95261c6a5ab3c Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Thu, 16 Feb 2023 19:18:28 -0800 Subject: [PATCH 1/6] upload bloom_filter.h file --- Firestore/core/src/remote/bloom_filter.cpp | 5 ++ Firestore/core/src/remote/bloom_filter.h | 76 ++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 Firestore/core/src/remote/bloom_filter.cpp create mode 100644 Firestore/core/src/remote/bloom_filter.h diff --git a/Firestore/core/src/remote/bloom_filter.cpp b/Firestore/core/src/remote/bloom_filter.cpp new file mode 100644 index 00000000000..d3732b9c484 --- /dev/null +++ b/Firestore/core/src/remote/bloom_filter.cpp @@ -0,0 +1,5 @@ +// +// Created by Mila Mamat on 2023-02-16. +// + +#include "bloom_filter.h" diff --git a/Firestore/core/src/remote/bloom_filter.h b/Firestore/core/src/remote/bloom_filter.h new file mode 100644 index 00000000000..b46be590842 --- /dev/null +++ b/Firestore/core/src/remote/bloom_filter.h @@ -0,0 +1,76 @@ +/* + * Copyright 2023 Google + * + * 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. + */ + +#ifndef FIREBASE_BLOOM_FILTER_H +#define FIREBASE_BLOOM_FILTER_H + +#include +#include "absl/status/statusor.h" + +namespace firebase { +namespace firestore { +namespace remote { + +class BloomFilter { + public: + BloomFilter(std::vector bitmap, int32_t padding, int32_t hash_count); + + /** + * Check whether the given string is a possible member of the bloom filter. It + * might return false positive result, ie, the given string is not a member of + * the bloom filter, but the method returned true. + * + * @param value the string to be tested for membership. + * @return true if the given string might be contained in the bloom filter, or + * false if the given string is definitely not contained in the bloom filter. + */ + bool mightContain(std::string_view value) const; + + // Get the `bit_count_` field. Used for testing purpose. + int32_t GetBitCount() const { + return bit_count_; + } + + private: + // The number of bits in the bloom filter. Guaranteed to be non-negative, and + // less than the max number of bits `bitmap_` can represent, i.e., + // bitmap_.size() * 8. + int32_t bit_count_; + + // The number of hash functions used to construct the filter. Guaranteed to be + // non-negative. + int32_t hash_count_; + + // Bloom filter's bitmap. + std::vector bitmap_; + + public: + virtual ~BloomFilter() = default; + + // Copyable & movable. + BloomFilter(const BloomFilter&) = default; + BloomFilter(BloomFilter&&) = default; + BloomFilter& operator=(const BloomFilter&) = default; + BloomFilter& operator=(BloomFilter&&) = default; + + bool operator==(const BloomFilter& other) const; +}; + +} // namespace remote +} // namespace firestore +} // namespace firebase + +#endif // FIREBASE_BLOOM_FILTER_H From 42b7e58e855fae7c57039e8b0c9c116d4842025d Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Thu, 16 Feb 2023 19:25:14 -0800 Subject: [PATCH 2/6] update h name --- Firestore/core/src/remote/bloom_filter.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Firestore/core/src/remote/bloom_filter.h b/Firestore/core/src/remote/bloom_filter.h index b46be590842..307af2c8a8c 100644 --- a/Firestore/core/src/remote/bloom_filter.h +++ b/Firestore/core/src/remote/bloom_filter.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef FIREBASE_BLOOM_FILTER_H -#define FIREBASE_BLOOM_FILTER_H +#ifndef FIREBASE_CORE_SRC_REMOTE_BLOOM_FILTER_H +#define FIREBASE_CORE_SRC_REMOTE_BLOOM_FILTER_H #include #include "absl/status/statusor.h" @@ -73,4 +73,4 @@ class BloomFilter { } // namespace firestore } // namespace firebase -#endif // FIREBASE_BLOOM_FILTER_H +#endif // FIREBASE_CORE_SRC_REMOTE_BLOOM_FILTER_H From e16caba7a20be4e579dd6c489ce761dc2b85c90f Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Fri, 17 Feb 2023 10:32:36 -0800 Subject: [PATCH 3/6] Update bloom_filter.h --- Firestore/core/src/remote/bloom_filter.h | 36 +++++++++++------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/Firestore/core/src/remote/bloom_filter.h b/Firestore/core/src/remote/bloom_filter.h index 307af2c8a8c..2d06b58a417 100644 --- a/Firestore/core/src/remote/bloom_filter.h +++ b/Firestore/core/src/remote/bloom_filter.h @@ -18,16 +18,23 @@ #define FIREBASE_CORE_SRC_REMOTE_BLOOM_FILTER_H #include -#include "absl/status/statusor.h" +#include +#include "absl/strings/string_view.h" namespace firebase { namespace firestore { namespace remote { -class BloomFilter { +class BloomFilter final{ public: BloomFilter(std::vector bitmap, int32_t padding, int32_t hash_count); + // Copyable & movable. + BloomFilter(const BloomFilter&) = default; + BloomFilter(BloomFilter&&) = default; + BloomFilter& operator=(const BloomFilter&) = default; + BloomFilter& operator=(BloomFilter&&) = default; + /** * Check whether the given string is a possible member of the bloom filter. It * might return false positive result, ie, the given string is not a member of @@ -37,36 +44,25 @@ class BloomFilter { * @return true if the given string might be contained in the bloom filter, or * false if the given string is definitely not contained in the bloom filter. */ - bool mightContain(std::string_view value) const; + bool MightContain(absl::string_view value) const; - // Get the `bit_count_` field. Used for testing purpose. - int32_t GetBitCount() const { + // Get the `bit_count_` field. Used for testing purpose. + int32_t bit_count() const { return bit_count_; - } - + } + private: // The number of bits in the bloom filter. Guaranteed to be non-negative, and // less than the max number of bits `bitmap_` can represent, i.e., // bitmap_.size() * 8. - int32_t bit_count_; + int32_t bit_count_=0; // The number of hash functions used to construct the filter. Guaranteed to be // non-negative. - int32_t hash_count_; + int32_t hash_count_=0; // Bloom filter's bitmap. std::vector bitmap_; - - public: - virtual ~BloomFilter() = default; - - // Copyable & movable. - BloomFilter(const BloomFilter&) = default; - BloomFilter(BloomFilter&&) = default; - BloomFilter& operator=(const BloomFilter&) = default; - BloomFilter& operator=(BloomFilter&&) = default; - - bool operator==(const BloomFilter& other) const; }; } // namespace remote From 8fe8676d3cde3f64d986f648e7ae06972a3cfcae Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Fri, 17 Feb 2023 10:36:25 -0800 Subject: [PATCH 4/6] Delete bloom_filter.cpp --- Firestore/core/src/remote/bloom_filter.cpp | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 Firestore/core/src/remote/bloom_filter.cpp diff --git a/Firestore/core/src/remote/bloom_filter.cpp b/Firestore/core/src/remote/bloom_filter.cpp deleted file mode 100644 index d3732b9c484..00000000000 --- a/Firestore/core/src/remote/bloom_filter.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by Mila Mamat on 2023-02-16. -// - -#include "bloom_filter.h" From d5a44e7a553d0663ec5b66ac01d401cc8be4b948 Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Fri, 17 Feb 2023 10:48:34 -0800 Subject: [PATCH 5/6] format --- Firestore/core/src/remote/bloom_filter.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Firestore/core/src/remote/bloom_filter.h b/Firestore/core/src/remote/bloom_filter.h index 2d06b58a417..15ada43ddb9 100644 --- a/Firestore/core/src/remote/bloom_filter.h +++ b/Firestore/core/src/remote/bloom_filter.h @@ -25,7 +25,7 @@ namespace firebase { namespace firestore { namespace remote { -class BloomFilter final{ +class BloomFilter final { public: BloomFilter(std::vector bitmap, int32_t padding, int32_t hash_count); @@ -44,22 +44,22 @@ class BloomFilter final{ * @return true if the given string might be contained in the bloom filter, or * false if the given string is definitely not contained in the bloom filter. */ - bool MightContain(absl::string_view value) const; + bool MightContain(absl::string_view value) const; - // Get the `bit_count_` field. Used for testing purpose. - int32_t bit_count() const { + // Get the `bit_count_` field. Used for testing purpose. + int32_t bit_count() const { return bit_count_; - } - + } + private: // The number of bits in the bloom filter. Guaranteed to be non-negative, and // less than the max number of bits `bitmap_` can represent, i.e., // bitmap_.size() * 8. - int32_t bit_count_=0; + int32_t bit_count_ = 0; // The number of hash functions used to construct the filter. Guaranteed to be // non-negative. - int32_t hash_count_=0; + int32_t hash_count_ = 0; // Bloom filter's bitmap. std::vector bitmap_; From f80b7fe6ee085ee3e15146c5518f68bd33bd3efe Mon Sep 17 00:00:00 2001 From: milaGGL <107142260+milaGGL@users.noreply.github.com> Date: Fri, 17 Feb 2023 15:01:17 -0800 Subject: [PATCH 6/6] resolve comments --- Firestore/core/src/remote/bloom_filter.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firestore/core/src/remote/bloom_filter.h b/Firestore/core/src/remote/bloom_filter.h index 15ada43ddb9..33639619b8b 100644 --- a/Firestore/core/src/remote/bloom_filter.h +++ b/Firestore/core/src/remote/bloom_filter.h @@ -1,5 +1,5 @@ /* - * Copyright 2023 Google + * Copyright 2023 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef FIREBASE_CORE_SRC_REMOTE_BLOOM_FILTER_H -#define FIREBASE_CORE_SRC_REMOTE_BLOOM_FILTER_H +#ifndef FIRESTORE_CORE_SRC_REMOTE_BLOOM_FILTER_H_ +#define FIRESTORE_CORE_SRC_REMOTE_BLOOM_FILTER_H_ #include #include @@ -69,4 +69,4 @@ class BloomFilter final { } // namespace firestore } // namespace firebase -#endif // FIREBASE_CORE_SRC_REMOTE_BLOOM_FILTER_H +#endif // FIRESTORE_CORE_SRC_REMOTE_BLOOM_FILTER_H_