Re: Circular Buffer

2014-02-13 Thread Artem Tarasov
On Thursday, 13 February 2014 at 20:56:32 UTC, Frustrated wrote: how efficient is ufcs? It seems like it would be very slow in general and way better to manually do the code. I wonder if anyone has done any tests? LDC and GDC are pretty darn good at inlining these UFCS chains, but the yielded

Re: Circular Buffer

2014-02-13 Thread Frustrated
On Monday, 10 February 2014 at 10:41:06 UTC, Russel Winder wrote: On Mon, 2014-02-10 at 09:16 +, Gary Willoughby wrote: On Monday, 10 February 2014 at 03:14:31 UTC, Jonathan Dunlap wrote: > (disclaimer: I'm new around here) > Is it possible to cycle backwards? If not, what's the best > app

Re: Circular Buffer

2014-02-13 Thread Tobias Pankrath
On Thursday, 13 February 2014 at 20:40:21 UTC, Tobias Pankrath wrote: On Monday, 10 February 2014 at 03:14:31 UTC, Jonathan Dunlap wrote: (disclaimer: I'm new around here) Is it possible to cycle backwards? If not, what's the best approach? Example of some ideal "takeBack" function: data = cy

Re: Circular Buffer

2014-02-13 Thread Tobias Pankrath
On Monday, 10 February 2014 at 03:14:31 UTC, Jonathan Dunlap wrote: (disclaimer: I'm new around here) Is it possible to cycle backwards? If not, what's the best approach? Example of some ideal "takeBack" function: data = cycle([1,2,3][]) take(data, 4) is [1,2,3,1][] takeBack(data, 4) would be

Re: Circular Buffer

2014-02-13 Thread Russel Winder
On Thu, 2014-02-13 at 18:03 +, bearophile wrote: […] > Take also a look at itertools.cycle. How about this: #! /usr/bin/env py.test-3.3 from itertools import cycle, islice data = [1, 2, 3] def test_forward(): assert tuple

Re: Circular Buffer

2014-02-13 Thread Russel Winder
On Thu, 2014-02-13 at 18:03 +, bearophile wrote: […] > Take also a look at itertools.cycle. Indeed. I keep forgetting about itertools when rushed, which is a definite error. -- Russel. = Dr Russel Winder t: +44

Re: Circular Buffer

2014-02-13 Thread bearophile
Russel Winder: I had a quick go at doing a Python 3 version using PyTest: def provide(sourceSequence, resultLength): return (sourceSequence[i % len(sourceSequence)] for i in range(resultLength)) def provideReverse(sourceSequence, resultLength): sourceLength = len(sourceSequence)

Re: Circular Buffer

2014-02-13 Thread monarch_dodra
On Monday, 10 February 2014 at 03:14:31 UTC, Jonathan Dunlap wrote: (disclaimer: I'm new around here) Is it possible to cycle backwards? If not, what's the best approach? Example of some ideal "takeBack" function: data = cycle([1,2,3][]) take(data, 4) is [1,2,3,1][] takeBack(data, 4) would be

Re: Circular Buffer

2014-02-12 Thread Russel Winder
On Mon, 2014-02-10 at 11:33 +, bearophile wrote: > Russel Winder: > > >This really needs to get onto the D website somewhere. > > retro+cycle is very simple code, you can also combine them: > > alias retroCycle = compose!(cycle, retro); point-free composition. We like this :-) > Ranges and

Re: Circular Buffer

2014-02-12 Thread Russel Winder
On Mon, 2014-02-10 at 09:16 +, Gary Willoughby wrote: > On Monday, 10 February 2014 at 03:14:31 UTC, Jonathan Dunlap > wrote: > > (disclaimer: I'm new around here) > > Is it possible to cycle backwards? If not, what's the best > > approach? > > import std.algorithm; > import std.array; > imp

Re: Circular Buffer

2014-02-11 Thread Jonathan Dunlap
Ooo.. I like the drop and take approach! I wonder if this could be something that makes it into the standard library (std.range?). What would be the best way to approach in suggesting that? Why not drop and take? http://dpaste.dzfl.pl/0649b809c81e

Re: Circular Buffer

2014-02-11 Thread Andrea Fontana
On Tuesday, 11 February 2014 at 16:30:42 UTC, Rene Zwanenburg wrote: On Tuesday, 11 February 2014 at 16:26:06 UTC, Rene Zwanenburg wrote: On Tuesday, 11 February 2014 at 03:10:02 UTC, Jonathan Dunlap wrote: Wow! This is GREAT stuff. My use-case is slightly more complex, and I'm not sure how to

Re: Circular Buffer

2014-02-11 Thread Rene Zwanenburg
On Tuesday, 11 February 2014 at 03:10:02 UTC, Jonathan Dunlap wrote: Wow! This is GREAT stuff. My use-case is slightly more complex, and I'm not sure how to best apply this knowledge. The retro reverses the array which is problematic in itself as well as losing the starting index location. I ha

Re: Circular Buffer

2014-02-11 Thread Rene Zwanenburg
On Tuesday, 11 February 2014 at 16:26:06 UTC, Rene Zwanenburg wrote: On Tuesday, 11 February 2014 at 03:10:02 UTC, Jonathan Dunlap wrote: Wow! This is GREAT stuff. My use-case is slightly more complex, and I'm not sure how to best apply this knowledge. The retro reverses the array which is prob

Re: Circular Buffer

2014-02-11 Thread Andrea Fontana
On Tuesday, 11 February 2014 at 09:10:16 UTC, Andrea Fontana wrote: On Tuesday, 11 February 2014 at 03:10:02 UTC, Jonathan Dunlap wrote: Wow! This is GREAT stuff. My use-case is slightly more complex, and I'm not sure how to best apply this knowledge. The retro reverses the array which is probl

Re: Circular Buffer

2014-02-11 Thread Andrea Fontana
On Tuesday, 11 February 2014 at 03:10:02 UTC, Jonathan Dunlap wrote: Wow! This is GREAT stuff. My use-case is slightly more complex, and I'm not sure how to best apply this knowledge. The retro reverses the array which is problematic in itself as well as losing the starting index location. I ha

Re: Circular Buffer

2014-02-11 Thread Martijn Pot
auto data = [1,2,3]; assert( data.cycle.rotate(2) == [3,1,2] ); assert( data.cycle.rotate(-2) == [2,3,1] ); It's not of immediate help, but it might trigger other answers. Matlab offers this for multi-dimensional arrays: http://www.mathworks.nl/help/matlab/ref/circshift.html

Re: Circular Buffer

2014-02-11 Thread Jonathan Dunlap
Wow! This is GREAT stuff. My use-case is slightly more complex, and I'm not sure how to best apply this knowledge. The retro reverses the array which is problematic in itself as well as losing the starting index location. I have an array that I'd like to elegantly "rotate". Best way I can show

Re: Circular Buffer

2014-02-10 Thread bearophile
Russel Winder: This really needs to get onto the D website somewhere. retro+cycle is very simple code, you can also combine them: alias retroCycle = compose!(cycle, retro); Ranges and algorithms can be combined together in so many ways :-) For an imperative/OO programmer writing code based

Re: Circular Buffer

2014-02-10 Thread Russel Winder
On Mon, 2014-02-10 at 09:16 +, Gary Willoughby wrote: > On Monday, 10 February 2014 at 03:14:31 UTC, Jonathan Dunlap > wrote: > > (disclaimer: I'm new around here) > > Is it possible to cycle backwards? If not, what's the best > > approach? > > import std.algorithm; > import std.array; > imp

Re: Circular Buffer

2014-02-10 Thread Gary Willoughby
On Monday, 10 February 2014 at 03:14:31 UTC, Jonathan Dunlap wrote: (disclaimer: I'm new around here) Is it possible to cycle backwards? If not, what's the best approach? import std.algorithm; import std.array; import std.range; import std.stdio; void main(string[] args) { auto data =

Re: Circular Buffer

2014-02-09 Thread Chris Cain
On Monday, 10 February 2014 at 03:14:31 UTC, Jonathan Dunlap wrote: (disclaimer: I'm new around here) Is it possible to cycle backwards? If not, what's the best approach? Example of some ideal "takeBack" function: data = cycle([1,2,3][]) take(data, 4) is [1,2,3,1][] takeBack(data, 4) would be

Re: Circular Buffer

2014-02-09 Thread Jonathan Dunlap
(disclaimer: I'm new around here) Is it possible to cycle backwards? If not, what's the best approach? Example of some ideal "takeBack" function: data = cycle([1,2,3][]) take(data, 4) is [1,2,3,1][] takeBack(data, 4) would be [1,3,2,1][] Thoughts?

Re: Circular Buffer

2013-12-21 Thread simendsjo
On Friday, 20 December 2013 at 15:45:04 UTC, Frustrated wrote: I'm in need of a circular buffer/array. I am using std.container.array to avoid the GC. I suppose I could copy and modify the code but is there any easier way? It looks like it is defined as templates so could I somehow hijac

Re: Circular Buffer

2013-12-21 Thread ponce
On Friday, 20 December 2013 at 15:45:04 UTC, Frustrated wrote: I'm in need of a circular buffer/array. I am using std.container.array to avoid the GC. I suppose I could copy and modify the code but is there any easier way? It looks like it is defined as templates so could I somehow hijac

Re: Circular Buffer

2013-12-20 Thread lomereiter
Use std.range.cycle with std.container.Array (slice the array to get a range). http://dlang.org/phobos/std_range.html#.cycle

Re: Circular Buffer

2013-12-20 Thread Timon Gehr
On 12/20/2013 04:45 PM, Frustrated wrote: I'm in need of a circular buffer/array. I am using std.container.array to avoid the GC. I suppose I could copy and modify the code but is there any easier way? ... What prevents you from implementing your buffer using an std.container.Array a

Re: Circular Buffer

2013-12-20 Thread Orvid King
On 12/20/13, Frustrated wrote: > But does it rely on the GC? > Nope, the template you wanted is vibe.utils.array:FixedRingBuffer.

Re: Circular Buffer

2013-12-20 Thread bearophile
Frustrated: I'm in need of a circular buffer/array. I am using std.container.array to avoid the GC. Why do you need to avoid the GC? Bye, bearophile

Circular Buffer

2013-12-20 Thread Frustrated
I'm in need of a circular buffer/array. I am using std.container.array to avoid the GC. I suppose I could copy and modify the code but is there any easier way? It looks like it is defined as templates so could I somehow hijack the code and modify only what is needed rather than duplicate

Re: Circular Buffer

2013-12-20 Thread Frustrated
But does it rely on the GC?

Re: Circular Buffer

2013-12-20 Thread Orvid King
There's actually already a circular buffer implemented in vibe.d, and if I remember right it's not dependent on anything from vibe. On 12/20/13, Frustrated wrote: > I'm in need of a circular buffer/array. I am using > std.container.array to avoid the GC. I suppose I could