From 0849937aead1f7bd802394e50fc6f53844b199bf Mon Sep 17 00:00:00 2001 From: Tonko Sabolcec Date: Mon, 6 May 2019 15:46:26 +0200 Subject: [PATCH] Add less than operator for property value Summary: This change will allow comparison of sets/maps containing `PropertyValue`s. Reviewers: teon.banek, msantl Reviewed By: msantl Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2008 --- src/storage/common/types/property_value.cpp | 22 +++++++++++++++++++++ src/storage/common/types/property_value.hpp | 1 + 2 files changed, 23 insertions(+) diff --git a/src/storage/common/types/property_value.cpp b/src/storage/common/types/property_value.cpp index 2c28fc6b9..3cb706047 100644 --- a/src/storage/common/types/property_value.cpp +++ b/src/storage/common/types/property_value.cpp @@ -316,3 +316,25 @@ bool operator==(const PropertyValue &first, const PropertyValue &second) { second.Value>(); } } + +bool operator<(const PropertyValue &first, const PropertyValue &second) { + if (first.type() != second.type()) return first.type() < second.type(); + switch (first.type()) { + case PropertyValue::Type::Null: + return false; + case PropertyValue::Type::Bool: + return first.Value() < second.Value(); + case PropertyValue::Type::Int: + return first.Value() < second.Value(); + case PropertyValue::Type::Double: + return first.Value() < second.Value(); + case PropertyValue::Type::String: + return first.Value() < second.Value(); + case PropertyValue::Type::List: + return first.Value>() < + second.Value>(); + case PropertyValue::Type::Map: + return first.Value>() < + second.Value>(); + } +} diff --git a/src/storage/common/types/property_value.hpp b/src/storage/common/types/property_value.hpp index d34114eae..558eee2d3 100644 --- a/src/storage/common/types/property_value.hpp +++ b/src/storage/common/types/property_value.hpp @@ -128,3 +128,4 @@ std::ostream &operator<<(std::ostream &os, const PropertyValue &value); // comparison bool operator==(const PropertyValue &first, const PropertyValue &second); +bool operator<(const PropertyValue &first, const PropertyValue &second);