-
Notifications
You must be signed in to change notification settings - Fork 6
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
[ENH] Augment coiteration algorithm to handle hashed level during conjunctive merge #19
Changes from 10 commits
8714270
652d8b0
bcbcbe2
462dbb0
7cc42f7
1969843
a9dc754
0c91a0d
0a35239
8d97006
c0bc015
fc08789
eb63b3c
0420df3
828092a
b5ec7ef
aa56276
29f4f7f
3e0afc4
b63b67c
2ac6d71
5e72277
25c5c2e
ddaf8d2
f77dd0d
6a73b73
1a6d711
8690b48
a379e0b
89ee47d
f7d0ed1
7730adb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,40 @@ | |
#include <algorithm> | ||
#include <stdexcept> | ||
|
||
#include <xsparse/level_capabilities/locate.hpp> | ||
|
||
namespace xsparse::level_capabilities | ||
{ | ||
/* | ||
The class template for Coiteration of level formats. | ||
|
||
Uses a generic function object F to compare elements | ||
from different sequences at the same position and returns a tuple of the | ||
minimum index and the corresponding elements from each sequence. | ||
|
||
Parameters | ||
---------- | ||
F : class | ||
A function object that is used to compare two elements from different ranges. | ||
IK : class | ||
The type of the first element of each range. | ||
PK : class | ||
The type of the second element of each range. | ||
Levels : Tuple of class | ||
A tuple of level formats, where each level is itself a tuple of elements to be iterated. | ||
Is : Tuple of class | ||
A tuple of indices that is used to keep track of the current position in each level. | ||
|
||
Notes | ||
----- | ||
Coiteration is only allowed through tuples of levels if the following criterion is met: | ||
If: | ||
1. the levels are all ordered (i.e. has the `is_ordered == True` property) | ||
2. if any of the level are do not have the is_ordered property, it must have the locate | ||
function, else return False. Then do a check that `m_comparisonHelper` defines | ||
a conjunctive merge (i.e. AND operation). | ||
Otherwise, coiteration is not allowed. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great! However, I'd recommend Doxygen-style docstrings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I changed the docstring to this style: https://www.doxygen.nl/manual/docblocks.html. Not as familiar w/ Doxygen, so lmk if you think I did anything wrong here. |
||
template <class F, class IK, class PK, class Levels, class Is> | ||
class Coiterate; | ||
|
||
|
@@ -28,6 +60,27 @@ namespace xsparse::level_capabilities | |
{ | ||
throw std::invalid_argument("level sizes should be same"); | ||
} | ||
|
||
if (!meet_criteria(f, levels...)) | ||
{ | ||
throw std::invalid_argument("levels do not meet coiteration criteria"); | ||
} | ||
} | ||
|
||
// Check if the levels meet the criteria. | ||
static constexpr bool meet_criteria(F f, Levels&... levels) | ||
{ | ||
// check that all the levels are ordered | ||
constexpr bool all_ordered = std::conjunction_v<levels.is_ordered...>; | ||
|
||
// check if any has `locate` function | ||
constexpr bool any_locate = std::disjunction_v<has_locate_v<levels...>...>; | ||
|
||
// check function for coiteration comparison is conjunctive | ||
constexpr bool is_conjunctive_merge | ||
= std::is_same_v<bool, decltype(f(std::declval<bool>(), std::declval<bool>()))>; | ||
|
||
return all_ordered || (any_locate && is_conjunctive_merge); | ||
} | ||
|
||
public: | ||
|
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.
This file contains my initial attempt at: adding a constexpr check at compile time to determine if the coiteration is valid (this assumes that the user converts non-ordered, non-locatable formats to a correct format).
What I'm not sure on now is how to best implement the
locate
logic. That is, we want to somehow given a tuple of levels, determine which of these have locate and instead of advancing the iterator on those levels, we locate into them given a index and pointer.