Zach Laine
On Wed, Jun 17, 2015 at 9:58 AM, Louis Dionne
wrote: Zach Laine
writes: [...]
The current implementation of filter for Tuple will be as good as I described. The generic implementation for other sequence types (say an adapted std::tuple) will be slower. So there's room for improvement, of course.
When you say "slower" do you mean 2*N or N^2?
Definitely more like 2*N. But I'll let you count . For generic sequences, the implementation is roughly equivalent to (once simplified):
. [...]
So it's O(k*N) for some constant k (say k <= 10 to be safe), but not O(N^2).
That will be unacceptably slow for many-to-most C++ users.
Can't you use Hana's Tuple, then? It's very hard to give good compile-time performance and runtime performance without knowing the internal representation of the data structures. One way to get good runtime performance is to use iterators and views like Fusion, but then you get lifetime issues. Hana takes for granted that types should be cheap to move. If that's not the case, can't you use a reference_wrapper or something like that?
[...]
Also, it just occurred to me that some algorithms simply can't write their result into an existing sequence, because the type of that resulting sequence isn't even known yet. Consider:
hana::tuple xs; hana::tuple<?, ?, ?> result;
// should write the resulting sequence into 'result'. filter_mutate(xs, result, predicate);
You don't know what's the type of the tuple before you have performed the algorithm.
Right. I can certainly live with only copy(), convert(), move(), and transform_mutate().
I don't easily see how these mutating algorithms would fit in Hana given
its functional design, but I'm not giving up. However, I suspect there
might be better (read more functional :-) ways to achieve this optimal
performance.
To get there, I'd like to make sure I understand exactly what operation
you're trying to avoid. Let's assume you wrote the following instead of
a transform_mutate equivalent:
hana::tuple