From f2b35084bfaa8a391597ac09b1cf8d0000e2418a Mon Sep 17 00:00:00 2001 From: Vito G Castellana Date: Mon, 26 Sep 2022 10:22:34 -0700 Subject: [PATCH] [#204] Unique and AsyncUnique methods in Multimap. --- include/shad/data_structures/multimap.h | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/include/shad/data_structures/multimap.h b/include/shad/data_structures/multimap.h index 1dff21ed..7cc2b522 100644 --- a/include/shad/data_structures/multimap.h +++ b/include/shad/data_structures/multimap.h @@ -341,6 +341,37 @@ class Multimap : public AbstractDataStructure< Multimap & value, + ObjectID & oid) { + auto mapPtr = HmapT::GetPtr(oid); + uint64_t orig_size = value.size(); + std::sort(value.begin(), value.end()); + value.erase(std::unique(value.begin(), value.end()), value.end()); + uint64_t new_size = value.size(); + mapPtr->localMultimap_.size_ -= (orig_size - new_size); + }; + HmapT::GetPtr(oid_)->ForEachEntry(uniqueLambda, oid_); + } + + /// @brief Asynchronously remove duplicate elements from each value. + /// The routine first sorts the value and then removes duplicates. + /// @param[in,out] handle Reference to the handle. + inline void AsyncUnique(rt::Handle &handle,) { + auto uniqueLambda = [](rt::Handle &, const KTYPE & key, + std::vector & value, ObjectID & oid) { + auto mapPtr = HmapT::GetPtr(oid); + uint64_t orig_size = value.size(); + std::sort(value.begin(), value.end()); + value.erase(std::unique(value.begin(), value.end()), value.end()); + uint64_t new_size = value.size(); + mapPtr->localMultimap_.size_ -= (orig_size - new_size); + }; + HmapT::GetPtr(oid_)->AsyncForEachEntry(handle, uniqueLambda, oid_); + } + // FIXME it should be protected void BufferEntryInsert(const EntryT &entry) { localMultimap_.Insert(entry.key, entry.value);