`touches` is poorly specified
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 42/100
Research direction
Start with include/boost/icl/concept/interval.hpp at the touches implementation linked in the issue, then compare its behavior with the documented function reference and the two reproductions. Decide and implement consistent behavior for reversed argument order and empty intervals, updating documentation and tests to define the expected cases.
Written by the indexing model from the issue text.
Description
The implementation of touches:
assumes that left is to the left of right, yet this precondition is not documented:
touches(x,y)Between the disjoint intervalsxandyare no elements.
So, we end up with touches not being symmetric (https://godbolt.org/z/7zPoe6hYj):
#include <boost/icl/interval.hpp>
#include <iostream>
int main()
{
boost::icl::closed_interval<int> x(0, 1), y(2, 3);
std::cout << touches(x, y) << "\n"; // outputs 1
std::cout << touches(y, x) << "\n"; // outputs 0
}
Additionally, empty intervals are handled in a way that is inconsistent with interval equality (https://godbolt.org/z/dxjGbsYr8):
#include <boost/icl/interval.hpp>
#include <iostream>
int main()
{
boost::icl::right_open_interval<int> empty0(0, 0), empty1(5, 5), y(0, 1);
std::cout << (empty0 == empty1) << "\n"; // outputs 1
std::cout << touches(empty0, y) << "\n"; // outputs 1
std::cout << touches(empty1, y) << "\n"; // outputs 0
}
In the example empty0 and empty1 are equal, yet one touches y and the other does not, thus breaking the generally assumed equality preservation property.
My suggestions for improvement are:
- Document the precondition that
xmust precedeyintouches(x, y)or else maketouchesbehave symmetrically (touches(x, y) == touches(y, x)whenevertouches(x, y)is well defined). - Clarify what "
xtouchesy" means when one or both ofx,yare empty, or else explicitly disqualify passing empty intervals totouches. - If empty intervals are allowed, make the implementation of
touchesequality-preserving when an empty interval is replaced by another empty interval.
- Dominant language
- C++
- Stars
- 15
- Forks
- 51
- Avg merge
- 8d 6h
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/icl
-
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
sprintf deprecatedOpen
Difficulty 1/5 Under an hour Newbie friendliness 62/100
-
Difficulty 3/5 1-2 days Newbie friendliness 56/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Similar issues
-
agent:WSL code-review linux pri:medium refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
kind/enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
psi29a/d2decomped#691 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
CachyOS/packageinstaller#144 ·
Maintainers usually reply within 1 day
-
(S1 - Need confirmation)
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
CleverRaven/Cataclysm-DDA#89715 ·
Maintainers usually reply within 1 day