On 1/24/15 7:17 AM, zeljkog wrote:
private struct FilterResult(alias predicate, Range)
{
static if (is(predicate == struct))
predicate pred;
else
alias pred = predicate;
...
The problem is here - the creation of an empty object is unlikely to be
of use to the
On 1/24/15 9:34 AM, zeljkog wrote:
On 24.01.15 18:26, zeljkog wrote:
Until now I concluded:
1. Resulting range must be output range. Right?
Should be input range.
For filter it's a forward range if input is forward or better. -- Andrei
On 24.01.15 19:47, Andrei Alexandrescu wrote:
But here there is potential problem with shared state after save?
It's not a problem - save saves the state of the iteration, not the data
being iterated. -- Andrei
If you pass stateful object with opCall or closure it becomes part of state
On 1/24/15 11:00 AM, H. S. Teoh via Digitalmars-d wrote:
On Sat, Jan 24, 2015 at 10:35:13AM -0800, Andrei Alexandrescu via Digitalmars-d
wrote:
On 1/24/15 9:34 AM, zeljkog wrote:
On 24.01.15 18:26, zeljkog wrote:
Until now I concluded:
1. Resulting range must be output range. Right?
Should
On 24.01.15 18:26, zeljkog wrote:
Until now I concluded:
1. Resulting range must be output range. Right?
Should be input range.
On Sat, Jan 24, 2015 at 10:35:13AM -0800, Andrei Alexandrescu via Digitalmars-d
wrote:
On 1/24/15 9:34 AM, zeljkog wrote:
On 24.01.15 18:26, zeljkog wrote:
Until now I concluded:
1. Resulting range must be output range. Right?
Should be input range.
For filter it's a forward range if
On Sat, Jan 24, 2015 at 11:20:55AM -0800, Andrei Alexandrescu via Digitalmars-d
wrote:
On 1/24/15 11:00 AM, H. S. Teoh via Digitalmars-d wrote:
On Sat, Jan 24, 2015 at 10:35:13AM -0800, Andrei Alexandrescu via
Digitalmars-d wrote:
[...]
For filter it's a forward range if input is forward or
On Saturday, 24 January 2015 at 14:53:02 UTC, Andrei Alexandrescu
wrote:
On 1/24/15 3:50 AM, Peter Alexander wrote:
On Friday, 23 January 2015 at 18:22:08 UTC, zeljkog wrote:
On 23.01.15 19:13, Andrei Alexandrescu wrote:
On 1/23/15 10:05 AM, zeljkog wrote:
On 23.01.15 18:48, H. S. Teoh via
On 24.01.15 18:02, Andrei Alexandrescu wrote:
On 1/24/15 7:17 AM, zeljkog wrote:
private struct FilterResult(alias predicate, Range)
{
static if (is(predicate == struct))
predicate pred;
else
alias pred = predicate;
...
The problem is here - the creation of
On 24.01.15 19:35, Andrei Alexandrescu wrote:
On 1/24/15 9:34 AM, zeljkog wrote:
On 24.01.15 18:26, zeljkog wrote:
Until now I concluded:
1. Resulting range must be output range. Right?
Should be input range.
For filter it's a forward range if input is forward or better. -- Andrei
But
On 1/24/15 10:41 AM, zeljkog wrote:
On 24.01.15 19:35, Andrei Alexandrescu wrote:
On 1/24/15 9:34 AM, zeljkog wrote:
On 24.01.15 18:26, zeljkog wrote:
Until now I concluded:
1. Resulting range must be output range. Right?
Should be input range.
For filter it's a forward range if input is
On 24.01.15 15:53, Andrei Alexandrescu wrote:
On 1/24/15 4:13 AM, zeljkog wrote:
On 24.01.15 12:50, Peter Alexander wrote:
auto f = unique();
[1, 5, 5, 2, 1, 5, 6, 6].filter!(f).writeln; // [1, 5, 2, 6]
Filter needs an alias, and you cannot alias an R-value (it has no
symbol).
Yes, I see
On 24.01.15 16:17, zeljkog wrote:
template filter(alias predicate) if (is(typeof(unaryFun!predicate)))
Should be:
template filter(alias predicate)
if (is(typeof(unaryFun!predicate)) || is(predicate == struct))
The problem with RedBlackTree is that it's cache-unfriendly due
to the
memory allocation and per-node pointers. One reason quicksort
performs
so well is because it works in-place, and the partition
operation
accesses elements bilinearly (i.e., two linear traversals over
the same
stretch of
On 23.01.15 19:05, zeljkog wrote:
On 23.01.15 18:48, H. S. Teoh via Digitalmars-d wrote:
I think what he's trying to do is to call a function that returns a
delegate, and use that delegate to instantiate the filter template.
AFAIK I've never seen code like this before, and it looks like the
Ignore me, sorry! Obviously that will not work for reuse of
unique.
On 24.01.15 12:50, Peter Alexander wrote:
auto f = unique();
[1, 5, 5, 2, 1, 5, 6, 6].filter!(f).writeln; // [1, 5, 2, 6]
Filter needs an alias, and you cannot alias an R-value (it has no symbol).
Yes, I see :)
But I think this should be supported by std.algorithm:
import std.stdio,
On Friday, 23 January 2015 at 18:22:08 UTC, zeljkog wrote:
On 23.01.15 19:13, Andrei Alexandrescu wrote:
On 1/23/15 10:05 AM, zeljkog wrote:
On 23.01.15 18:48, H. S. Teoh via Digitalmars-d wrote:
I think what he's trying to do is to call a function that
returns a
delegate, and use that
import std.stdio, std.algorithm;
auto unique(){
bool[int] c;
return (int a){
if (a in c)
return false;
else{
c[a] = true;
return true;
}
};
}
void main()
{
[1, 5, 5, 2, 1, 5, 6, 6].filter!(unique()).writeln;
}
Just
On 1/24/15 3:50 AM, Peter Alexander wrote:
On Friday, 23 January 2015 at 18:22:08 UTC, zeljkog wrote:
On 23.01.15 19:13, Andrei Alexandrescu wrote:
On 1/23/15 10:05 AM, zeljkog wrote:
On 23.01.15 18:48, H. S. Teoh via Digitalmars-d wrote:
I think what he's trying to do is to call a function
On 1/24/15 4:13 AM, zeljkog wrote:
On 24.01.15 12:50, Peter Alexander wrote:
auto f = unique();
[1, 5, 5, 2, 1, 5, 6, 6].filter!(f).writeln; // [1, 5, 2, 6]
Filter needs an alias, and you cannot alias an R-value (it has no symbol).
Yes, I see :)
But I think this should be supported by
On 23.01.15 19:13, Andrei Alexandrescu wrote:
On 1/23/15 10:05 AM, zeljkog wrote:
On 23.01.15 18:48, H. S. Teoh via Digitalmars-d wrote:
I think what he's trying to do is to call a function that returns a
delegate, and use that delegate to instantiate the filter template.
AFAIK I've never
On 1/23/15 10:05 AM, zeljkog wrote:
On 23.01.15 18:48, H. S. Teoh via Digitalmars-d wrote:
I think what he's trying to do is to call a function that returns a
delegate, and use that delegate to instantiate the filter template.
AFAIK I've never seen code like this before, and it looks like the
On 1/23/15 7:04 AM, zeljkog wrote:
On 22.01.15 22:40, Andrei Alexandrescu wrote:
There's this classic patter on Unix: |sort|uniq, i.e. sort some data and
only display the unique elements.
Loosely-related, compiling
...
auto ret = arr.filter!(myFilter());
...
I got:
Error: closures are not
On Fri, Jan 23, 2015 at 09:40:42AM -0800, Andrei Alexandrescu via Digitalmars-d
wrote:
On 1/23/15 7:04 AM, zeljkog wrote:
On 22.01.15 22:40, Andrei Alexandrescu wrote:
There's this classic patter on Unix: |sort|uniq, i.e. sort some data
and only display the unique elements.
On 23.01.15 18:48, H. S. Teoh via Digitalmars-d wrote:
I think what he's trying to do is to call a function that returns a
delegate, and use that delegate to instantiate the filter template.
AFAIK I've never seen code like this before, and it looks like the
compiler isn't prepared to handle
On 22.01.15 22:40, Andrei Alexandrescu wrote:
There's this classic patter on Unix: |sort|uniq, i.e. sort some data and
only display the unique elements.
Loosely-related, compiling
...
auto ret = arr.filter!(myFilter());
...
I got:
Error: closures are not yet supported in CTFE
Using struct
zeljkog:
Loosely-related, compiling
...
auto ret = arr.filter!(myFilter());
...
I got:
Error: closures are not yet supported in CTFE
Using struct with opCall directly also does not pass.
Did I miss something?
Is it near?
Please show a minimal nonworking example in the D.learn newsgroup.
On Thursday, 22 January 2015 at 21:40:57 UTC, Andrei Alexandrescu
wrote:
There's this classic patter on Unix: |sort|uniq, i.e. sort some
data and only display the unique elements.
What would be a better integrated version - one that does
sorting and uniq in one shot? I suspect the combination
On Thu, Jan 22, 2015 at 01:40:56PM -0800, Andrei Alexandrescu via Digitalmars-d
wrote:
There's this classic patter on Unix: |sort|uniq, i.e. sort some data
and only display the unique elements.
What would be a better integrated version - one that does sorting and
uniq in one shot? I suspect
Andrei Alexandrescu:
There's this classic patter on Unix: |sort|uniq, i.e. sort some
data and only display the unique elements.
In Bugzilla I've asked for a hashGroup, it returns a built-in
associative array.
Bye,
bearophile
On Thu, 22 Jan 2015 13:40:56 -0800, Andrei Alexandrescu wrote:
There's this classic patter on Unix: |sort|uniq, i.e. sort some data and
only display the unique elements.
What would be a better integrated version - one that does sorting and
uniq in one shot? I suspect the combination could
There's this classic patter on Unix: |sort|uniq, i.e. sort some data and
only display the unique elements.
What would be a better integrated version - one that does sorting and
uniq in one shot? I suspect the combination could be quite a bit better
than doing the two in sequence.
A few
On 1/22/15 2:06 PM, Justin Whear wrote:
On Thu, 22 Jan 2015 13:40:56 -0800, Andrei Alexandrescu wrote:
There's this classic patter on Unix: |sort|uniq, i.e. sort some data and
only display the unique elements.
What would be a better integrated version - one that does sorting and
uniq in one
On Thursday, 22 January 2015 at 23:35:32 UTC, H. S. Teoh via
Digitalmars-d wrote:
On Thu, Jan 22, 2015 at 02:51:38PM -0800, H. S. Teoh via
Digitalmars-d wrote:
Wait, if R1 and R3, after the recursion, are sorted and
contain only
unique elements, doesn't that mean that we can just collapse
R2
On Thu, Jan 22, 2015 at 11:52:18PM +, Vladimir Panteleev via Digitalmars-d
wrote:
On Thursday, 22 January 2015 at 23:35:32 UTC, H. S. Teoh via Digitalmars-d
wrote:
On Thu, Jan 22, 2015 at 02:51:38PM -0800, H. S. Teoh via Digitalmars-d
wrote:
Wait, if R1 and R3, after the recursion, are
Andrei Alexandrescu:
What would be a better integrated version - one that does
sorting and uniq in one shot? I suspect the combination could
be quite a bit better than doing the two in sequence.
What I need most is a groping by hashing, since years. A unique
sort can be handy, but it's less
On Thu, Jan 22, 2015 at 02:51:38PM -0800, H. S. Teoh via Digitalmars-d wrote:
On Thu, Jan 22, 2015 at 02:29:58PM -0800, Andrei Alexandrescu via
Digitalmars-d wrote:
[...]
Thanks. I'm thinking of something based on general comparisons.
Something like a modified quicksort with fat pivot:
On 01/22/2015 07:06 PM, bearophile wrote:
Andrei Alexandrescu:
What would be a better integrated version - one that does sorting and
uniq in one shot? I suspect the combination could be quite a bit
better than doing the two in sequence.
What I need most is a groping by hashing, since
On Thu, Jan 22, 2015 at 02:29:58PM -0800, Andrei Alexandrescu via Digitalmars-d
wrote:
[...]
Thanks. I'm thinking of something based on general comparisons.
Something like a modified quicksort with fat pivot:
A. Partition into three subranges: R1pivot, R2=pivot, R3pivot
B. Recurse on R1
On 1/22/15 2:51 PM, H. S. Teoh via Digitalmars-d wrote:
Wait, if R1 and R3, after the recursion, are sorted and contain only
unique elements, doesn't that mean that we can just collapse R2 into a
single element along with the endpoints of R1 and R3? So if R1[$-1]
pivot, then we're done,
On 1/22/15 4:06 PM, bearophile wrote:
Andrei Alexandrescu:
What would be a better integrated version - one that does sorting and
uniq in one shot? I suspect the combination could be quite a bit
better than doing the two in sequence.
What I need most is a groping by hashing, since years. A
On 1/22/15 3:52 PM, Vladimir Panteleev wrote:
On Thursday, 22 January 2015 at 23:35:32 UTC, H. S. Teoh via
Digitalmars-d wrote:
On Thu, Jan 22, 2015 at 02:51:38PM -0800, H. S. Teoh via Digitalmars-d
wrote:
Wait, if R1 and R3, after the recursion, are sorted and contain only
unique elements,
Paul O'Neil:
Is that different than groupBy?
It works with hashing, and doesn't require a sorting, so it's
different. On the other hand it's just few lines of code long,
and it's quite easy to write...
Bye,
bearophile
could
be quite a bit better than doing the two in sequence.
A few google searches didn't yield much. Ideas?
Thanks,
Andrei
My thought is that uniq on a sorted list is only an O(n)
operation, so it's not an expensive operation by any means. If
there's to be any benefit to a sortUniq
to a sortUniq, it has to be capable of reducing work incurred
during the sorting process; else you're just going to end up with
something less efficient.
One solution may be RedBlackTree, which has an option to disallow
duplicate elements. This container has three useful properties:
The problem
On Thu, Jan 22, 2015 at 04:10:45PM -0800, Andrei Alexandrescu via Digitalmars-d
wrote:
On 1/22/15 2:51 PM, H. S. Teoh via Digitalmars-d wrote:
Wait, if R1 and R3, after the recursion, are sorted and contain only
unique elements, doesn't that mean that we can just collapse R2 into
a single
On 1/22/15 4:26 PM, H. S. Teoh via Digitalmars-d wrote:
The question, though, is whether this hybrid recursion actually wins us
anything, since heapsort is known to be somewhat slower than quicksort.
In the worst case, you choose a poor pivot and get*both* the worst case
of quicksort and the
On Thu, Jan 22, 2015 at 04:33:28PM -0800, Andrei Alexandrescu via Digitalmars-d
wrote:
On 1/22/15 4:26 PM, H. S. Teoh via Digitalmars-d wrote:
The question, though, is whether this hybrid recursion actually wins
us anything, since heapsort is known to be somewhat slower than
quicksort. In
49 matches
Mail list logo