Re: D's rotateTail [was: C++'s std::rotate]

2014-08-24 Thread Fool via Digitalmars-d
On Saturday, 23 August 2014 at 18:07:43 UTC, Fool wrote: [2] http://dpaste.dzfl.pl/514a1ef77d0a The 'three reverses' algorihm could be actually improved. Updated code (along with additional unit tests and a strengthened assertion) is available at [3]. I compared this implementation to an

Re: D's rotateTail [was: C++'s std::rotate]

2014-08-24 Thread Fool via Digitalmars-d
There was a bug in my C++ translation of rotateTail. The only significant change in execution time is marked below: On Sunday, 24 August 2014 at 09:20:59 UTC, Fool wrote: compiler | algorithm| execution time --+--+ clang++ |

Re: D's rotateTail [was: C++'s std::rotate]

2014-08-23 Thread Fool via Digitalmars-d
After having some fun with rotateTail and friends a draft implementation [2] is now available and ready for comments aiming at formal specification, algorithmics, and implementation details. While most ideas were taken from [1], all mistakes are mine. Since this is my first D code, more or

Re: C++'s std::rotate

2014-08-22 Thread monarch_dodra via Digitalmars-d
On Monday, 11 August 2014 at 14:45:09 UTC, Andrei Alexandrescu wrote: On 8/11/14, 2:11 AM, Nordlöw wrote: On Monday, 11 August 2014 at 06:56:52 UTC, Dragos Carp wrote: bool sliceOf(T)(in T[] whole, in T[] slice) { return whole.ptr = slice.ptr whole.ptr + slice.length = whole.ptr +

Re: C++'s std::rotate

2014-08-19 Thread Fool via Digitalmars-d
On Monday, 18 August 2014 at 05:27:11 UTC, Andrei Alexandrescu wrote: On 8/17/14, 9:06 AM, Fool wrote: http://dpaste.dzfl.pl/8fc83cb06de8 Yah, it's a good option. Relevant code: if (right is whole) { //writeln(case identical); return tuple(right, whole.dropExactly(whole.length)); }

Re: C++'s std::rotate

2014-08-19 Thread Andrei Alexandrescu via Digitalmars-d
On 8/19/14, 12:32 PM, Fool wrote: On Monday, 18 August 2014 at 05:27:11 UTC, Andrei Alexandrescu wrote: On 8/17/14, 9:06 AM, Fool wrote: http://dpaste.dzfl.pl/8fc83cb06de8 Yah, it's a good option. Relevant code: if (right is whole) { //writeln(case identical); return tuple(right,

Re: C++'s std::rotate

2014-08-18 Thread Peter Alexander via Digitalmars-d
On Monday, 11 August 2014 at 03:29:56 UTC, Andrei Alexandrescu wrote: [...] can be implemented generically for ranges that offer front as a reference: bool sameFront(R1, R2)(R1 r1, R2 r2) { return r1.front == r2.front; } This doesn't work for ranges that visit the same element twice, e.g.

Re: C++'s std::rotate

2014-08-18 Thread Andrei Alexandrescu via Digitalmars-d
On 8/18/14, 1:44 AM, Peter Alexander wrote: On Monday, 11 August 2014 at 03:29:56 UTC, Andrei Alexandrescu wrote: [...] can be implemented generically for ranges that offer front as a reference: bool sameFront(R1, R2)(R1 r1, R2 r2) { return r1.front == r2.front; } This doesn't work for

Re: C++'s std::rotate

2014-08-17 Thread Fool via Digitalmars-d
On Monday, 11 August 2014 at 15:04:52 UTC, Andrei Alexandrescu wrote: http://dpaste.dzfl.pl/a0effbaee0a9 Is your design final with respect to handling degenerate cases? What do you think about http://dpaste.dzfl.pl/8fc83cb06de8 ?

Re: C++'s std::rotate

2014-08-17 Thread Andrei Alexandrescu via Digitalmars-d
On 8/17/14, 9:06 AM, Fool wrote: On Monday, 11 August 2014 at 15:04:52 UTC, Andrei Alexandrescu wrote: http://dpaste.dzfl.pl/a0effbaee0a9 Is your design final with respect to handling degenerate cases? What do you think about http://dpaste.dzfl.pl/8fc83cb06de8 ? Yah, it's a good

Re: C++'s std::rotate

2014-08-11 Thread Dragos Carp via Digitalmars-d
Nice work! Implementation is at http://dpaste.dzfl.pl/a0effbaee0a9. For historical reasons I've reused an undocumented function sameHead. sameHead is documented. I already use it a couple of times. The algorithm assumes that right is a subrange of whole sitting at its tail, ... sameTail

Re: C++'s std::rotate

2014-08-11 Thread Nordlöw
On Monday, 11 August 2014 at 06:56:52 UTC, Dragos Carp wrote: bool sliceOf(T)(in T[] whole, in T[] slice) { return whole.ptr = slice.ptr whole.ptr + slice.length = whole.ptr + slice.length; } Shouldn't the function arguments of sliceOf be reversed to given a more intuitive UCFS

Re: C++'s std::rotate

2014-08-11 Thread Peter Alexander via Digitalmars-d
This reminds me, we still need allBefore to implement nextPermutation correctly for bidirectional ranges. https://issues.dlang.org/show_bug.cgi?id=12188 I think this would help here also.

Re: C++'s std::rotate

2014-08-11 Thread Nordlöw
On Monday, 11 August 2014 at 06:56:52 UTC, Dragos Carp wrote: bool sliceOf(T)(in T[] whole, in T[] slice) { return whole.ptr = slice.ptr whole.ptr + slice.length = whole.ptr + slice.length; } Correction: This is what I think you mean: bool sliceOf(T)(in T[] part,

Re: C++'s std::rotate

2014-08-11 Thread Dragos Carp via Digitalmars-d
On Monday, 11 August 2014 at 10:09:53 UTC, Nordlöw wrote: On Monday, 11 August 2014 at 06:56:52 UTC, Dragos Carp wrote: bool sliceOf(T)(in T[] whole, in T[] slice) { return whole.ptr = slice.ptr whole.ptr + slice.length = whole.ptr + slice.length; } Correction: This is what I think

Re: C++'s std::rotate

2014-08-11 Thread Dragos Carp via Digitalmars-d
Correction: This is what I think you mean: bool sliceOf(T)(in T[] part, in T[] whole) { return (whole.ptr = part.ptr part.ptr + part.length = whole.ptr + whole.length); } Yes, of course. I had lhs, rhs and messed up the renaming of those.

Re: C++'s std::rotate

2014-08-11 Thread Nordlöw
On Monday, 11 August 2014 at 11:00:41 UTC, Dragos Carp wrote: https://github.com/dcarp/phobos/compare/sliceOf Why not use something like part and whole instead of lhs and rhs? It is more self-documenting.

Re: C++'s std::rotate

2014-08-11 Thread Ary Borenszweig via Digitalmars-d
On 8/11/14, 12:29 AM, Andrei Alexandrescu wrote: Hello, In which algorithms would one use std::rotate?

Re: C++'s std::rotate

2014-08-11 Thread via Digitalmars-d
On Monday, 11 August 2014 at 13:55:07 UTC, Ary Borenszweig wrote: On 8/11/14, 12:29 AM, Andrei Alexandrescu wrote: Hello, In which algorithms would one use std::rotate? http://en.wikipedia.org/wiki/Block_sort

Re: C++'s std::rotate

2014-08-11 Thread Peter Alexander via Digitalmars-d
On Monday, 11 August 2014 at 13:55:07 UTC, Ary Borenszweig wrote: On 8/11/14, 12:29 AM, Andrei Alexandrescu wrote: Hello, In which algorithms would one use std::rotate? Pushing N items to the front of a vector is implemented as pushing N to the back then rotating them to the front.

Re: C++'s std::rotate

2014-08-11 Thread Andrei Alexandrescu via Digitalmars-d
On 8/11/14, 2:11 AM, Nordlöw wrote: On Monday, 11 August 2014 at 06:56:52 UTC, Dragos Carp wrote: bool sliceOf(T)(in T[] whole, in T[] slice) { return whole.ptr = slice.ptr whole.ptr + slice.length = whole.ptr + slice.length; } Shouldn't the function arguments of sliceOf be

Re: C++'s std::rotate

2014-08-11 Thread Andrei Alexandrescu via Digitalmars-d
On 8/11/14, 6:55 AM, Ary Borenszweig wrote: On 8/11/14, 12:29 AM, Andrei Alexandrescu wrote: Hello, In which algorithms would one use std::rotate? Depends on whom you ask :o). I think it's a fairly obscure algorithm, better suited as representative of a class rather than frequently

Re: C++'s std::rotate

2014-08-11 Thread Dragos Carp via Digitalmars-d
isSliceOf - yum PR created: https://github.com/D-Programming-Language/phobos/pull/2416

Re: C++'s std::rotate

2014-08-11 Thread Nordlöw
On Monday, 11 August 2014 at 14:45:09 UTC, Andrei Alexandrescu wrote: isSliceOf - yum Can you elaborate on that?

Re: C++'s std::rotate

2014-08-11 Thread Nordlöw
On Monday, 11 August 2014 at 18:11:19 UTC, Nordlöw wrote: On Monday, 11 August 2014 at 14:45:09 UTC, Andrei Alexandrescu wrote: isSliceOf - yum Can you elaborate on that? I get it, Andrei :)

Re: C++'s std::rotate

2014-08-11 Thread Andrei Alexandrescu via Digitalmars-d
On 8/11/14, 11:12 AM, Nordlöw wrote: On Monday, 11 August 2014 at 18:11:19 UTC, Nordlöw wrote: On Monday, 11 August 2014 at 14:45:09 UTC, Andrei Alexandrescu wrote: isSliceOf - yum Can you elaborate on that? I get it, Andrei :) Yah, all about making a.isSliceOf(b) a nice phrase and keeping

C++'s std::rotate

2014-08-10 Thread Andrei Alexandrescu via Digitalmars-d
be done with ranges. Amid these observations, C++'s std::rotate (http://goo.gl/z8FjV) and derivative algorithms have been a prime category of examples. C++'s std::rotate takes a three-legged range, i.e. three iterators begin, middle, and end, and rotates the range [middle, end) to precede [begin