Replace unordered_map with map in storage v2

Summary:
`std::unordered_map` is 56 bytes in size, `std::map` is 48 bytes in size.
Also, `std::map` doesn't require the key type to be hashable.

Reviewers: mtomic, teon.banek

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2218
This commit is contained in:
Matej Ferencevic 2019-07-18 12:35:15 +02:00
parent 111dd8bf19
commit 10136f43dc
6 changed files with 14 additions and 19 deletions

View File

@ -1,7 +1,7 @@
#pragma once
#include <limits>
#include <unordered_map>
#include <map>
#include "utils/spin_lock.hpp"
@ -20,7 +20,7 @@ struct Edge {
Gid gid;
std::unordered_map<uint64_t, storage::PropertyValue> properties;
std::map<uint64_t, storage::PropertyValue> properties;
utils::SpinLock lock;
bool deleted;

View File

@ -90,9 +90,8 @@ Result<PropertyValue> EdgeAccessor::GetProperty(uint64_t property, View view) {
return Result<PropertyValue>{std::move(value)};
}
Result<std::unordered_map<uint64_t, PropertyValue>> EdgeAccessor::Properties(
View view) {
std::unordered_map<uint64_t, PropertyValue> properties;
Result<std::map<uint64_t, PropertyValue>> EdgeAccessor::Properties(View view) {
std::map<uint64_t, PropertyValue> properties;
bool deleted = false;
Delta *delta = nullptr;
{
@ -137,11 +136,9 @@ Result<std::unordered_map<uint64_t, PropertyValue>> EdgeAccessor::Properties(
}
});
if (deleted) {
return Result<std::unordered_map<uint64_t, PropertyValue>>{
Error::DELETED_OBJECT};
return Result<std::map<uint64_t, PropertyValue>>{Error::DELETED_OBJECT};
}
return Result<std::unordered_map<uint64_t, PropertyValue>>{
std::move(properties)};
return Result<std::map<uint64_t, PropertyValue>>{std::move(properties)};
}
} // namespace storage

View File

@ -37,7 +37,7 @@ class EdgeAccessor final {
Result<PropertyValue> GetProperty(uint64_t property, View view);
Result<std::unordered_map<uint64_t, PropertyValue>> Properties(View view);
Result<std::map<uint64_t, PropertyValue>> Properties(View view);
Gid Gid() const { return edge_->gid; }

View File

@ -1,8 +1,8 @@
#pragma once
#include <limits>
#include <map>
#include <tuple>
#include <unordered_map>
#include <vector>
#include "utils/spin_lock.hpp"
@ -22,7 +22,7 @@ struct Vertex {
Gid gid;
std::vector<uint64_t> labels;
std::unordered_map<uint64_t, storage::PropertyValue> properties;
std::map<uint64_t, storage::PropertyValue> properties;
std::vector<std::tuple<uint64_t, Vertex *, Edge *>> in_edges;
std::vector<std::tuple<uint64_t, Vertex *, Edge *>> out_edges;

View File

@ -250,9 +250,9 @@ Result<PropertyValue> VertexAccessor::GetProperty(uint64_t property,
return Result<PropertyValue>{std::move(value)};
}
Result<std::unordered_map<uint64_t, PropertyValue>> VertexAccessor::Properties(
Result<std::map<uint64_t, PropertyValue>> VertexAccessor::Properties(
View view) {
std::unordered_map<uint64_t, PropertyValue> properties;
std::map<uint64_t, PropertyValue> properties;
bool deleted = false;
Delta *delta = nullptr;
{
@ -297,11 +297,9 @@ Result<std::unordered_map<uint64_t, PropertyValue>> VertexAccessor::Properties(
}
});
if (deleted) {
return Result<std::unordered_map<uint64_t, PropertyValue>>{
Error::DELETED_OBJECT};
return Result<std::map<uint64_t, PropertyValue>>{Error::DELETED_OBJECT};
}
return Result<std::unordered_map<uint64_t, PropertyValue>>{
std::move(properties)};
return Result<std::map<uint64_t, PropertyValue>>{std::move(properties)};
}
Result<std::vector<EdgeAccessor>>

View File

@ -37,7 +37,7 @@ class VertexAccessor final {
Result<PropertyValue> GetProperty(uint64_t property, View view);
Result<std::unordered_map<uint64_t, PropertyValue>> Properties(View view);
Result<std::map<uint64_t, PropertyValue>> Properties(View view);
Result<std::vector<EdgeAccessor>>
InEdges(const std::vector<uint64_t> &edge_types, View view);