Skip to content

Commit

Permalink
Take function-like parameters as universal references
Browse files Browse the repository at this point in the history
Summary: There are a few cases where we were taking const references for function-like parameters. There is no real reason for that, let's just use universal references and be consistent with the rest of the codebase.

Reviewed By: anwesht

Differential Revision: D49771704

fbshipit-source-id: 77ae5332ecc73d48b071b4a8e70249bdca2ee9c4
  • Loading branch information
arthaud authored and facebook-github-bot committed Sep 30, 2023
1 parent b3160b0 commit d0cb5ac
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
5 changes: 2 additions & 3 deletions include/sparta/FlatMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class FlatMap final {
// Requires CombiningFunction to coerce to
// std::function<void(mapped_type*, const mapped_type&)>
template <typename CombiningFunction>
void union_with(const CombiningFunction& combine, const FlatMap& other) {
void union_with(CombiningFunction&& combine, const FlatMap& other) {
auto it = m_map.begin(), end = m_map.end();
auto other_it = other.m_map.begin(), other_end = other.m_map.end();
while (other_it != other_end) {
Expand All @@ -284,8 +284,7 @@ class FlatMap final {
// Requires CombiningFunction to coerce to
// std::function<void(mapped_type*, const mapped_type&)>
template <typename CombiningFunction>
void intersection_with(const CombiningFunction& combine,
const FlatMap& other) {
void intersection_with(CombiningFunction&& combine, const FlatMap& other) {
auto it = m_map.begin(), end = m_map.end();
auto other_it = other.m_map.begin(), other_end = other.m_map.end();
while (it != end) {
Expand Down
5 changes: 2 additions & 3 deletions include/sparta/HashMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class HashMap final {
// Requires CombiningFunction to coerce to
// std::function<void(mapped_type*, const mapped_type&)>
template <typename CombiningFunction>
void union_with(const CombiningFunction& combine, const HashMap& other) {
void union_with(CombiningFunction&& combine, const HashMap& other) {
for (const auto& other_binding : other.m_map) {
auto binding = m_map.find(other_binding.first);
if (binding == m_map.end()) {
Expand All @@ -259,8 +259,7 @@ class HashMap final {
// Requires CombiningFunction to coerce to
// std::function<void(mapped_type*, const mapped_type&)>
template <typename CombiningFunction>
void intersection_with(const CombiningFunction& combine,
const HashMap& other) {
void intersection_with(CombiningFunction&& combine, const HashMap& other) {
auto it = m_map.begin(), end = m_map.end();
while (it != end) {
auto other_binding = other.m_map.find(it->first);
Expand Down
27 changes: 15 additions & 12 deletions include/sparta/PatriciaTreeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,48 +173,51 @@ class PatriciaTreeMap final {
// Requires CombiningFunction to coerce to
// std::function<mapped_type(const mapped_type&, const mapped_type&)>
template <typename CombiningFunction>
PatriciaTreeMap& union_with(const CombiningFunction& combine,
PatriciaTreeMap& union_with(CombiningFunction&& combine,
const PatriciaTreeMap& other) {
m_core.merge(apply_leafs(combine), other.m_core);
m_core.merge(apply_leafs(std::forward<CombiningFunction>(combine)),
other.m_core);
return *this;
}

template <typename CombiningFunction>
PatriciaTreeMap& intersection_with(const CombiningFunction& combine,
PatriciaTreeMap& intersection_with(CombiningFunction&& combine,
const PatriciaTreeMap& other) {
m_core.intersect(apply_leafs(combine), other.m_core);
m_core.intersect(apply_leafs(std::forward<CombiningFunction>(combine)),
other.m_core);
return *this;
}

// Requires that `combine(bottom, ...) = bottom`.
template <typename CombiningFunction>
PatriciaTreeMap& difference_with(const CombiningFunction& combine,
PatriciaTreeMap& difference_with(CombiningFunction&& combine,
const PatriciaTreeMap& other) {
m_core.diff(apply_leafs(combine), other.m_core);
m_core.diff(apply_leafs(std::forward<CombiningFunction>(combine)),
other.m_core);
return *this;
}

template <typename CombiningFunction>
PatriciaTreeMap get_union_with(const CombiningFunction& combine,
PatriciaTreeMap get_union_with(CombiningFunction&& combine,
const PatriciaTreeMap& other) const {
auto result = *this;
result.union_with(combine, other);
result.union_with(std::forward<CombiningFunction>(combine), other);
return result;
}

template <typename CombiningFunction>
PatriciaTreeMap get_intersection_with(const CombiningFunction& combine,
PatriciaTreeMap get_intersection_with(CombiningFunction&& combine,
const PatriciaTreeMap& other) const {
auto result = *this;
result.intersection_with(combine, other);
result.intersection_with(std::forward<CombiningFunction>(combine), other);
return result;
}

template <typename CombiningFunction>
PatriciaTreeMap get_difference_with(const CombiningFunction& combine,
PatriciaTreeMap get_difference_with(CombiningFunction&& combine,
const PatriciaTreeMap& other) const {
auto result = *this;
result.difference_with(combine, other);
result.difference_with(std::forward<CombiningFunction>(combine), other);
return result;
}

Expand Down

0 comments on commit d0cb5ac

Please sign in to comment.