Add std::vector
based InitProperties
This commit is contained in:
parent
6c48399338
commit
8ed16d1c51
@ -1144,7 +1144,8 @@ bool PropertyStore::SetProperty(PropertyId property, const PropertyValue &value)
|
|||||||
return !existed;
|
return !existed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PropertyStore::InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties) {
|
template <typename TContainer>
|
||||||
|
bool PropertyStore::DoInitProperties(const TContainer &properties) {
|
||||||
uint64_t size = 0;
|
uint64_t size = 0;
|
||||||
uint8_t *data = nullptr;
|
uint8_t *data = nullptr;
|
||||||
std::tie(size, data) = GetSizeData(buffer_);
|
std::tie(size, data) = GetSizeData(buffer_);
|
||||||
@ -1201,6 +1202,20 @@ bool PropertyStore::InitProperties(const std::map<storage::PropertyId, storage::
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
template bool PropertyStore::DoInitProperties<std::map<PropertyId, PropertyValue>>(
|
||||||
|
const std::map<PropertyId, PropertyValue> &);
|
||||||
|
template bool PropertyStore::DoInitProperties<std::vector<std::pair<PropertyId, PropertyValue>>>(
|
||||||
|
const std::vector<std::pair<PropertyId, PropertyValue>> &);
|
||||||
|
|
||||||
|
bool PropertyStore::InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties) {
|
||||||
|
return DoInitProperties(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PropertyStore::InitProperties(std::vector<std::pair<storage::PropertyId, storage::PropertyValue>> properties) {
|
||||||
|
std::sort(properties.begin(), properties.end());
|
||||||
|
|
||||||
|
return DoInitProperties(properties);
|
||||||
|
}
|
||||||
|
|
||||||
bool PropertyStore::ClearProperties() {
|
bool PropertyStore::ClearProperties() {
|
||||||
bool in_local_buffer = false;
|
bool in_local_buffer = false;
|
||||||
|
@ -60,11 +60,17 @@ class PropertyStore {
|
|||||||
bool SetProperty(PropertyId property, const PropertyValue &value);
|
bool SetProperty(PropertyId property, const PropertyValue &value);
|
||||||
|
|
||||||
/// Init property values and return `true` if insertion took place. `false` is
|
/// Init property values and return `true` if insertion took place. `false` is
|
||||||
/// returned if there exists property in property store and insertion couldn't take place. The time complexity of this
|
/// returned if there is any existing property in property store and insertion couldn't take place. The time
|
||||||
/// function is O(n).
|
/// complexity of this function is O(n).
|
||||||
/// @throw std::bad_alloc
|
/// @throw std::bad_alloc
|
||||||
bool InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties);
|
bool InitProperties(const std::map<storage::PropertyId, storage::PropertyValue> &properties);
|
||||||
|
|
||||||
|
/// Init property values and return `true` if insertion took place. `false` is
|
||||||
|
/// returned if there is any existing property in property store and insertion couldn't take place. The time
|
||||||
|
/// complexity of this function is O(n*log(n)):
|
||||||
|
/// @throw std::bad_alloc
|
||||||
|
bool InitProperties(std::vector<std::pair<storage::PropertyId, storage::PropertyValue>> properties);
|
||||||
|
|
||||||
/// Remove all properties and return `true` if any removal took place.
|
/// Remove all properties and return `true` if any removal took place.
|
||||||
/// `false` is returned if there were no properties to remove. The time
|
/// `false` is returned if there were no properties to remove. The time
|
||||||
/// complexity of this function is O(1).
|
/// complexity of this function is O(1).
|
||||||
@ -72,6 +78,9 @@ class PropertyStore {
|
|||||||
bool ClearProperties();
|
bool ClearProperties();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
template <typename TContainer>
|
||||||
|
bool DoInitProperties(const TContainer &properties);
|
||||||
|
|
||||||
uint8_t buffer_[sizeof(uint64_t) + sizeof(uint8_t *)];
|
uint8_t buffer_[sizeof(uint64_t) + sizeof(uint8_t *)];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include "storage/v2/id_types.hpp"
|
||||||
#include "storage/v2/property_store.hpp"
|
#include "storage/v2/property_store.hpp"
|
||||||
#include "storage/v2/property_value.hpp"
|
#include "storage/v2/property_value.hpp"
|
||||||
#include "storage/v2/temporal.hpp"
|
#include "storage/v2/temporal.hpp"
|
||||||
@ -651,24 +652,40 @@ TEST(PropertyStore, IsPropertyEqualTemporalData) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST(PropertyStore, SetMultipleProperties) {
|
TEST(PropertyStore, SetMultipleProperties) {
|
||||||
memgraph::storage::PropertyStore store;
|
|
||||||
std::vector<memgraph::storage::PropertyValue> vec{memgraph::storage::PropertyValue(true),
|
std::vector<memgraph::storage::PropertyValue> vec{memgraph::storage::PropertyValue(true),
|
||||||
memgraph::storage::PropertyValue(123),
|
memgraph::storage::PropertyValue(123),
|
||||||
memgraph::storage::PropertyValue()};
|
memgraph::storage::PropertyValue()};
|
||||||
std::map<std::string, memgraph::storage::PropertyValue> map{{"nandare", memgraph::storage::PropertyValue(false)}};
|
std::map<std::string, memgraph::storage::PropertyValue> map{{"nandare", memgraph::storage::PropertyValue(false)}};
|
||||||
const memgraph::storage::TemporalData temporal{memgraph::storage::TemporalType::LocalDateTime, 23};
|
const memgraph::storage::TemporalData temporal{memgraph::storage::TemporalType::LocalDateTime, 23};
|
||||||
std::map<memgraph::storage::PropertyId, memgraph::storage::PropertyValue> data{
|
// The order of property ids are purposfully not monotonic to test that PropertyStore orders them properly
|
||||||
|
const std::vector<std::pair<memgraph::storage::PropertyId, memgraph::storage::PropertyValue>> data{
|
||||||
{memgraph::storage::PropertyId::FromInt(1), memgraph::storage::PropertyValue(true)},
|
{memgraph::storage::PropertyId::FromInt(1), memgraph::storage::PropertyValue(true)},
|
||||||
{memgraph::storage::PropertyId::FromInt(2), memgraph::storage::PropertyValue(123)},
|
{memgraph::storage::PropertyId::FromInt(10), memgraph::storage::PropertyValue(123)},
|
||||||
{memgraph::storage::PropertyId::FromInt(3), memgraph::storage::PropertyValue(123.5)},
|
{memgraph::storage::PropertyId::FromInt(3), memgraph::storage::PropertyValue(123.5)},
|
||||||
{memgraph::storage::PropertyId::FromInt(4), memgraph::storage::PropertyValue("nandare")},
|
{memgraph::storage::PropertyId::FromInt(4), memgraph::storage::PropertyValue("nandare")},
|
||||||
{memgraph::storage::PropertyId::FromInt(5), memgraph::storage::PropertyValue(vec)},
|
{memgraph::storage::PropertyId::FromInt(12), memgraph::storage::PropertyValue(vec)},
|
||||||
{memgraph::storage::PropertyId::FromInt(6), memgraph::storage::PropertyValue(map)},
|
{memgraph::storage::PropertyId::FromInt(6), memgraph::storage::PropertyValue(map)},
|
||||||
{memgraph::storage::PropertyId::FromInt(7), memgraph::storage::PropertyValue(temporal)}};
|
{memgraph::storage::PropertyId::FromInt(7), memgraph::storage::PropertyValue(temporal)}};
|
||||||
|
|
||||||
store.InitProperties(data);
|
const std::map<memgraph::storage::PropertyId, memgraph::storage::PropertyValue> data_in_map{data.begin(), data.end()};
|
||||||
|
|
||||||
for (auto &[key, value] : data) {
|
auto check_store = [data](const memgraph::storage::PropertyStore &store) {
|
||||||
ASSERT_TRUE(store.IsPropertyEqual(key, value));
|
for (auto &[key, value] : data) {
|
||||||
|
ASSERT_TRUE(store.IsPropertyEqual(key, value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
{
|
||||||
|
memgraph::storage::PropertyStore store;
|
||||||
|
EXPECT_TRUE(store.InitProperties(data));
|
||||||
|
check_store(store);
|
||||||
|
EXPECT_FALSE(store.InitProperties(data));
|
||||||
|
EXPECT_FALSE(store.InitProperties(data_in_map));
|
||||||
|
}
|
||||||
|
{
|
||||||
|
memgraph::storage::PropertyStore store;
|
||||||
|
EXPECT_TRUE(store.InitProperties(data_in_map));
|
||||||
|
check_store(store);
|
||||||
|
EXPECT_FALSE(store.InitProperties(data_in_map));
|
||||||
|
EXPECT_FALSE(store.InitProperties(data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user