- Remove unused data manager classes.

PiperOrigin-RevId: 596628112
This commit is contained in:
Francis Tsui
2024-01-08 10:08:39 -08:00
committed by Copybara-Service
parent 6ae46a9496
commit 97a3ceb311
7 changed files with 0 additions and 479 deletions
-3
View File
@@ -9,10 +9,8 @@ package(default_visibility = [
cc_library(
name = "data_manager",
hdrs = [
"data_manager.h",
"data_set.h",
"leveldb_data_set.h",
"memory_data_set.h",
],
deps = [
"//internal/platform:types",
@@ -43,7 +41,6 @@ cc_test(
timeout = "short",
srcs = [
"leveldb_data_set_test.cc",
"memory_data_set_test.cc",
],
shard_count = 8,
deps = [
-53
View File
@@ -1,53 +0,0 @@
// Copyright 2022 Google LLC
//
// 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
//
// https://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 THIRD_PARTY_NEARBY_INTERNAL_DATA_DATA_MANAGER_H_
#define THIRD_PARTY_NEARBY_INTERNAL_DATA_DATA_MANAGER_H_
#include <memory>
#include "absl/strings/string_view.h"
#include "internal/data/data_set.h"
#include "internal/data/leveldb_data_set.h"
#include "internal/data/memory_data_set.h"
namespace nearby {
namespace data {
class DataManager {
public:
enum class DataStorageType : int { kMemory = 0, kLevelDb = 1 };
explicit DataManager(DataStorageType data_storage_type)
: data_storage_type_(data_storage_type) {}
~DataManager() = default;
template <typename T>
std::unique_ptr<DataSet<T>> GetDataSet(absl::string_view path) {
if (data_storage_type_ == DataStorageType::kMemory) {
return std::make_unique<MemoryDataSet<T>>(path);
} else if (data_storage_type_ == DataStorageType::kLevelDb) {
return std::make_unique<LeveldbDataSet<T>>(path);
} else {
return nullptr;
}
}
private:
DataStorageType data_storage_type_;
};
} // namespace data
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_INTERNAL_DATA_DATA_MANAGER_H_
-109
View File
@@ -1,109 +0,0 @@
// Copyright 2022 Google LLC
//
// 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
//
// https://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 THIRD_PARTY_NEARBY_INTERNAL_DATA_MEMORY_DATA_SET_H_
#define THIRD_PARTY_NEARBY_INTERNAL_DATA_MEMORY_DATA_SET_H_
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/functional/any_invocable.h"
#include "absl/strings/string_view.h"
#include "absl/synchronization/mutex.h"
#include "internal/data/data_set.h"
namespace nearby {
namespace data {
template <typename T>
class MemoryDataSet : public DataSet<T> {
public:
using KeyEntryVector = std::vector<std::pair<std::string, T>>;
explicit MemoryDataSet(absl::string_view path) : path_(path) {}
~MemoryDataSet() override = default;
void Initialize(absl::AnyInvocable<void(InitStatus) &&> callback) override;
void LoadEntries(
absl::AnyInvocable<void(bool, std::unique_ptr<std::vector<T>>) &&>
callback) override;
void UpdateEntries(std::unique_ptr<KeyEntryVector> entries_to_save,
std::unique_ptr<std::vector<std::string>> keys_to_remove,
absl::AnyInvocable<void(bool) &&> callback) override;
void Destroy(absl::AnyInvocable<void(bool) &&> callback) override;
private:
std::string path_;
absl::Mutex mutex_;
absl::flat_hash_map<std::string, T> entries_;
};
template <typename T>
void MemoryDataSet<T>::Initialize(
absl::AnyInvocable<void(InitStatus) &&> callback) {
std::move(callback)(InitStatus::kOK);
}
template <typename T>
void MemoryDataSet<T>::LoadEntries(
absl::AnyInvocable<void(bool, std::unique_ptr<std::vector<T>>) &&>
callback) {
auto result = std::make_unique<std::vector<T>>();
auto it = entries_.begin();
while (it != entries_.end()) {
result->push_back(it->second);
++it;
}
std::move(callback)(true, std::move(result));
}
template <typename T>
void MemoryDataSet<T>::UpdateEntries(
std::unique_ptr<KeyEntryVector> entries_to_save,
std::unique_ptr<std::vector<std::string>> keys_to_remove,
absl::AnyInvocable<void(bool) &&> callback) {
if (entries_to_save != nullptr) {
auto it = entries_to_save->begin();
while (it != entries_to_save->end()) {
entries_.emplace(it->first, it->second);
++it;
}
}
if (keys_to_remove != nullptr) {
auto it = keys_to_remove->begin();
while (it != keys_to_remove->end()) {
entries_.erase(*it);
++it;
}
}
std::move(callback)(true);
}
template <typename T>
void MemoryDataSet<T>::Destroy(absl::AnyInvocable<void(bool) &&> callback) {
entries_.clear();
std::move(callback)(true);
}
} // namespace data
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_INTERNAL_DATA_MEMORY_DATA_SET_H_
-71
View File
@@ -1,71 +0,0 @@
// Copyright 2022 Google LLC
//
// 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
//
// https://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.
#include "internal/data/memory_data_set.h"
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
namespace nearby {
namespace data {
namespace {
TEST(MemoryDataSet, TestUpdateEntries) {
bool result = false;
MemoryDataSet<std::string> string_set{""};
auto temp = MemoryDataSet<std::string>::KeyEntryVector(
{{"id1", "string1"}, {"id2", "string2"}});
auto data =
std::make_unique<MemoryDataSet<std::string>::KeyEntryVector>(temp);
string_set.UpdateEntries(std::move(data), nullptr,
[&result](bool res) { result = res; });
EXPECT_TRUE(result);
}
TEST(MemoryDataSet, TestLoadEntries) {
std::vector<std::string> result = {};
MemoryDataSet<std::string> string_set{""};
auto temp = MemoryDataSet<std::string>::KeyEntryVector(
{{"id1", "string1"}, {"id2", "string2"}});
auto data =
std::make_unique<MemoryDataSet<std::string>::KeyEntryVector>(temp);
string_set.UpdateEntries(std::move(data), nullptr, [](bool ans) {});
string_set.LoadEntries(
[&result](bool ans, std::unique_ptr<std::vector<std::string>> res) {
auto it = res->begin();
while (it != res->end()) {
result.push_back(*it);
++it;
}
});
EXPECT_THAT(result, testing::SizeIs(2));
std::sort(result.begin(), result.end());
EXPECT_EQ(result, std::vector<std::string>({"string1", "string2"}));
}
} // namespace
} // namespace data
} // namespace nearby