-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/map functions #350
Feature/map functions #350
Conversation
68f5bc4
to
6f9d96e
Compare
@ldionne I think I should also add symmetric_difference implementation for maps. I'll try to update the PR with its commits soon. One doubt: As you must be aware of the other implementation: Is former implementation is chosen randomly, or is it faster than later one ? |
6f9d96e
to
42944a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall great, with a few nitpicks! Thanks a lot for the great PR!
As for symmetric_difference
, I think it would be quite nice to add it in this PR. I'm not sure why I chose one implementation over the other when I wrote it for hana::set
.
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | ||
|
||
#include <boost/hana/assert.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please order includes.
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | ||
|
||
#include <boost/hana/assert.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x2
include/boost/hana/fwd/map.hpp
Outdated
//! is present in `ys`. | ||
//! In other words, the following holds for any object `pair(k, v)`: | ||
//! @code | ||
//! pair(k, v) ^in^ intersection(xs, ys) if and only if (k, v) ^in^ xs && k ^in^ ys.keys() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ys.keys()
does not exist; consider using keys(ys)
instead
include/boost/hana/fwd/map.hpp
Outdated
//! | ||
//! | ||
//! @note | ||
//! This function is not commutative, i.e. `intersection(xs, ys)` is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reword to
//! This function is not commutative, i.e. `intersection(xs, ys)` is not
//! necessarily the same as `intersection(ys, xs)`. Indeed, the set of keys
//! in `intersection(xs, ys)` is always the same as the set of keys in
//! `intersection(ys, xs)`, but the value associated to each key may be
//! different. `intersection(xs, ys)` contains values present in `xs`, and
//! `intersection(ys, xs)` contains values present in `ys`.
include/boost/hana/fwd/map.hpp
Outdated
//! is not present in `keys(ys)`. | ||
//! In other words, the following holds for any object `pair(k, v)`: | ||
//! @code | ||
//! pair(k, v) ^in^ difference(xs, ys) if and only if (k, v) ^in^ xs && k ^not in^ ys.keys() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment for ys.keys()
.
include/boost/hana/map.hpp
Outdated
|
||
// Second template param will be pair | ||
// Get its key and check if it exists, if it does, insert key, value pair. | ||
template<typename Result, typename Pair> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space between template
and <typename
.
include/boost/hana/map.hpp
Outdated
return hana::insert(static_cast<Result&&>(result), static_cast<Pair&&>(pair)); | ||
} | ||
|
||
template<typename Result, typename Pair> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x2
test/map/difference.cpp
Outdated
#include <laws/base.hpp> | ||
#include <support/minimal_product.hpp> | ||
namespace hana = boost::hana; | ||
using hana::test::ct_eq; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need this.
p<1, 4>()) | ||
), | ||
hana::make_map() | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a bigger test case with something like 10 elements in the maps?
test/map/intersection.cpp
Outdated
#include <laws/base.hpp> | ||
#include <support/minimal_product.hpp> | ||
namespace hana = boost::hana; | ||
using hana::test::ct_eq; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed.
What is the reason for |
@ricejasonf
Performance based on asymptotic analysis should be same if want to intersect based on (key, value), although the overhead of comparison of value will be increased. |
@shreyans800755 Ah, right, it compares the keys. I wasn't even thinking about that. lol 😅 |
f8bc26f
to
a697773
Compare
One of the jobs failed with
|
a697773
to
c7e2b48
Compare
include/boost/hana/map.hpp
Outdated
@@ -51,9 +53,11 @@ Distributed under the Boost Software License, Version 1.0. | |||
#include <boost/hana/optional.hpp> | |||
#include <boost/hana/remove_if.hpp> | |||
#include <boost/hana/second.hpp> | |||
#include <boost/hana/tuple.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need #include <boost/hana/tuple.hpp>
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected.
I'll push symmetric_difference soon.
c7e2b48
to
71858c6
Compare
@@ -5,10 +5,14 @@ | |||
#include <boost/hana/assert.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like we did for the other functions, would it be possible to have an example/set/symmetric_difference.cpp
and an example/map/symmetric_difference.cpp
file? This would be consistent with the rest of the lib, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of that, too. I chose this way because we don't have different implementations for set and map.
test/symmetric_difference.cpp
Outdated
@@ -0,0 +1,134 @@ | |||
// Copyright Louis Dionne 2013-2017 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as for examples; it would be nice to have a test for map and a test for sets in different files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thought as example. So, I wasn't sure if we need two different files.
Regarding documentation of symmetric_difference, currently it exists only for set. Should I move it to |
I would duplicate the documentation for set and map. While duplication is generally bad, the rationale here is that the two implementations for set and map are conceptually unrelated, since they don't share a common concept. If we were to create a new concept and move |
5a7a216
to
311b052
Compare
That makes sense. I'll push the changes. |
311b052
to
3200dce
Compare
test/set/symmetric_difference.cpp
Outdated
@@ -2,8 +2,6 @@ | |||
// Distributed under the Boost Software License, Version 1.0. | |||
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | |||
|
|||
#include <boost/hana/assert.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those should stay, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is already coming from:
test/set/symmetric_difference.cpp:10
test/_include/laws/base.hpp:25
test/_include/support/tracked.hpp:11
And that's why tests are also passing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but you should always include what you use to avoid relying on such dependencies, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Will update soon.
3200dce
to
a88133a
Compare
|
Thanks a lot @shreyans800755, this is a great PR! |
Added intersection and difference functions for map along with docs.
Closes #341