Re: Best way to clear dynamic array for reuse

2016-07-14 Thread Miguel L via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 17:19:09 UTC, Steven Schveighoffer wrote: On 7/13/16 8:41 AM, Lodovico Giaretta wrote: On Wednesday, 13 July 2016 at 12:37:26 UTC, Miguel L wrote: I tried Appender, but for some reason garbage collector still seems to be running every few iterations. I will try

Re: Best way to clear dynamic array for reuse

2016-07-14 Thread Miguel L via Digitalmars-d-learn
On Thursday, 14 July 2016 at 09:12:50 UTC, Jonathan M Davis wrote: So, whether you should be using Appender or assumeSafeAppend or neither depends entirely on what you're doing. However, in general, simply appending to dynamic arrays does not result in many reallocations (just like it doesn't

Best way to clear dynamic array for reuse

2016-07-13 Thread Miguel L via Digitalmars-d-learn
I am using a temporary dynamic array inside a loop this way: A[] a; for() { a=[]; //discard array contents ... appends thousand of elements to a ... use a for some calculations } I would like to know which would be the best way to clear a contents avoiding reallocations, as there seems to

Re: Best way to clear dynamic array for reuse

2016-07-13 Thread Miguel L via Digitalmars-d-learn
On Wednesday, 13 July 2016 at 12:05:18 UTC, Lodovico Giaretta wrote: On Wednesday, 13 July 2016 at 11:59:18 UTC, Miguel L wrote: I am using a temporary dynamic array inside a loop this way: A[] a; for() { a=[]; //discard array contents ... appends thousand of elements to a ... use a for

Most elegant way for split array of struct into components

2016-07-05 Thread Miguel L via Digitalmars-d-learn
Hello I would like advice in the most elegant way for doing this in D: I have something like this: struct A { int x; int y; } A[] my_array; And I would need something like this: assert( my_array[0..n].x == [ my_array[0].x, my_array[1].x, ... my_array[n-1].x ]); assert( my_array[0..n].y == [

Re: Most elegant way for split array of struct into components

2016-07-05 Thread Miguel L via Digitalmars-d-learn
On Tuesday, 5 July 2016 at 07:33:40 UTC, Ali Çehreli wrote: On 07/04/2016 11:07 PM, Miguel L wrote: > [...] > [...] my_array? The simplest is to pick the element by std.algorithm.map: [...] Thank you Ali, that works. On the same subject, could it be possible to implement some class or

Re: Different array rotation algorithms benchmark

2016-09-01 Thread Miguel L via Digitalmars-d-learn
On Thursday, 1 September 2016 at 09:36:16 UTC, Miguel L wrote: Hi I recently needed a very optimized array rotation algorithm, so I did this benchmark, hope you find it interesting. I am a bit surprised by the poor results of std.algorithm.bringToFront: [...] Sorry Rotate4 had a bug,

Re: Different array rotation algorithms benchmark

2016-09-01 Thread Miguel L via Digitalmars-d-learn
On Thursday, 1 September 2016 at 09:53:59 UTC, Miguel L wrote: On Thursday, 1 September 2016 at 09:36:16 UTC, Miguel L wrote: Hi I recently needed a very optimized array rotation algorithm, so I did this benchmark, hope you find it interesting. I am a bit surprised by the poor results of

Different array rotation algorithms benchmark

2016-09-01 Thread Miguel L via Digitalmars-d-learn
Hi I recently needed a very optimized array rotation algorithm, so I did this benchmark, hope you find it interesting. I am a bit surprised by the poor results of std.algorithm.bringToFront: These are the different algorithms: void Rotate0(T)(T[] input, int n) pure {

Re: Different array rotation algorithms benchmark

2016-09-02 Thread Miguel L via Digitalmars-d-learn
On Thursday, 1 September 2016 at 13:16:19 UTC, Johan Engelen wrote: On Thursday, 1 September 2016 at 10:37:18 UTC, Miguel L wrote: Also, forgot to specify I am using LDC with -05. And the version of LDC too please ;-) LDC version is: ldc2-1.1.0-beta2-win64-msvc

Re: Static array with parameter based size?

2017-07-11 Thread Miguel L via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 05:45:13 UTC, Miguel L wrote: Hi I need to create a non-dynamic array like this void f(int x) { int[x] my_array; ... this does not compile as x value needs to be known at compile time. The closest to this I can get is: void f(int x) { int[] my_array;

Static array with parameter based size?

2017-07-11 Thread Miguel L via Digitalmars-d-learn
Hi I need to create a non-dynamic array like this void f(int x) { int[x] my_array; ... this does not compile as x value needs to be known at compile time. The closest to this I can get is: void f(int x) { int[] my_array; my_array.length=x; but I don't really need a dynamic array as length

Function with static array as parameter

2017-07-12 Thread Miguel L via Digitalmars-d-learn
What is the best way in D to create a function that receives a static array of any length?

Static array with parameter based size?

2017-07-11 Thread Miguel L via Digitalmars-d-learn
I need to create a non-dynamic array like this void f(int x) { int[x] my_array; ... this does not compile as x value needs to be known at compile time. The closest to this I can get is: void f(int x) { int[] my_array; my_array.length=x; but I don't really need a dynamic array as length is

Re: Static array with parameter based size?

2017-07-13 Thread Miguel L via Digitalmars-d-learn
On Wednesday, 12 July 2017 at 18:49:23 UTC, Jack Applegame wrote: On Wednesday, 12 July 2017 at 05:45:13 UTC, Miguel L wrote: Also what is it possible in D to write a function that accepts an static array of any size? void foo(size_t N)(ref int[N] arr) { ... } int[10] arr; foo(arr);

Re: Function with static array as parameter

2017-07-13 Thread Miguel L via Digitalmars-d-learn
Thanks for your help.

How to init immutable static array?

2017-07-18 Thread Miguel L via Digitalmars-d-learn
Hi, I need help again. I have an immutable static array and i need to initialize its contents inside a for loop. Something like this: void f(int n)() { immutable float[n] my_array; for(int i=0;i

Re: How to init immutable static array?

2017-07-18 Thread Miguel L via Digitalmars-d-learn
On Tuesday, 18 July 2017 at 07:31:22 UTC, Era Scarecrow wrote: On Tuesday, 18 July 2017 at 07:30:30 UTC, Era Scarecrow wrote: my_array[i]=some calculations(based on constants and n) i meant: tmp[i]=some calculations(based on constants and n) That does work, thanks.

Re: signbit question

2018-03-15 Thread Miguel L via Digitalmars-d-learn
On Thursday, 15 March 2018 at 17:31:38 UTC, rumbu wrote: On Thursday, 15 March 2018 at 17:18:08 UTC, Miguel L wrote: On Thursday, 15 March 2018 at 16:31:56 UTC, Stefan Koch wrote: On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote: [...] integers don't have a sign-bit. since they

Re: signbit question

2018-03-15 Thread Miguel L via Digitalmars-d-learn
On Thursday, 15 March 2018 at 16:31:56 UTC, Stefan Koch wrote: On Thursday, 15 March 2018 at 15:28:16 UTC, Miguel L wrote: Why does std.math.signbit only work for floating point types? Is there an analogue function for integer types? what is the best way to compare the sign of a float with the

signbit question

2018-03-15 Thread Miguel L via Digitalmars-d-learn
Why does std.math.signbit only work for floating point types? Is there an analogue function for integer types? what is the best way to compare the sign of a float with the sign of an integer? Thanks in advance