Re: Variable-Length Bit-Level Encoding

2016-11-12 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 12 November 2016 at 19:13:13 UTC, Nordlöw wrote: 0 => [0] 1 => [1,0] 2 => [1,1,0] is easy but assumes a too extreme input value distribution. Does anybody have a suggestion for an encoder that is more suitable for real-world values that are, for instance, normally distributed?

Re: Is it possible to store different generic types in ex. an

2016-11-12 Thread Charles Hixson via Digitalmars-d-learn
On 11/09/2016 07:46 AM, Is it possible to store different generic types? via Digitalmars-d-learn wrote: On Wednesday, 9 November 2016 at 15:44:59 UTC, Is it possible to store different generic types? wrote: Is it possible to store different generic types in ex. somekind of container such as an a

Re: Variable-Length Bit-Level Encoding

2016-11-12 Thread James Buren via Digitalmars-d-learn
On Saturday, 12 November 2016 at 19:13:13 UTC, Nordlöw wrote: Does anybody have a suggestion for an encoder that is more suitable for real-world values that are, for instance, normally distributed? I don't recall the name, but there is an algorithm for encoding data of an arbitrary number of

Variable-Length Bit-Level Encoding

2016-11-12 Thread Nordlöw via Digitalmars-d-learn
I'm looking for libraries/snippets (either in D or similar languages) that perform variable-length encoding of unsigned integers onto a bit-stream. Requirement is that smaller inputs (integer values) should be encoded with equal or fewer bits. This 0 => [0] 1 => [1,0] 2 => [1,1,0] is easy bu

Re: Variable-Length Bit-Level Encoding

2016-11-12 Thread Nordlöw via Digitalmars-d-learn
On Saturday, 12 November 2016 at 19:13:13 UTC, Nordlöw wrote: Does anybody have a suggestion for an encoder that is more suitable for real-world values that are, for instance, normally distributed? Doh, forget the normal distribution thing here. It, of course, doesn't work with unsigned integ

Re: Is it possible to store different generic types in ex. an

2016-11-12 Thread Erik van Velzen via Digitalmars-d-learn
On Wednesday, 9 November 2016 at 15:44:59 UTC, Is it possible to store different generic types? wrote: Foo[] foos; // Where Foo of course should allow any generic version of Foo You can use an array of std.variant

Re: static array internal & dangling reference

2016-11-12 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 12 November 2016 at 13:11:02 UTC, Mike Parker wrote: void func2(int[] foo) { foo ~= 10; } Sorry, this should be (ref int[] foo)

Re: static array internal & dangling reference

2016-11-12 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 12 November 2016 at 12:16:02 UTC, Andrew wrote: Bear in mind that static arrays are implicitly sliced when passed to or returned from a function anywhere a dynamic array is expected. If you modify f() to look like this: int[] f() { int[10] sa; foreach(int i, ref sa_i;sa){

Re: static array internal & dangling reference

2016-11-12 Thread Andrew via Digitalmars-d-learn
On Saturday, 12 November 2016 at 11:03:31 UTC, Mike Parker wrote: [...] You *have* created a dangling pointer. It's just that for such a simple little program, the part of the stack where the original array was allocated isn't stomped at the point where you access it after the function call.

Re: static array internal & dangling reference

2016-11-12 Thread Picaud Vincent via Digitalmars-d-learn
On Saturday, 12 November 2016 at 11:03:31 UTC, Mike Parker wrote: Thank you very much for your clarifications & explanations, I am reassured to see that things work like in C. I will also look the links you provided, thank you again for your time. Vincent

Re: static array internal & dangling reference

2016-11-12 Thread Picaud Vincent via Digitalmars-d-learn
Thank you for your answer cym13. I reproduced your result for: On Saturday, 12 November 2016 at 10:45:23 UTC, cym13 wrote: void f_test() { auto sb=f(); sb[2] = 100; writeln(sb[2]); // prints 100 int test[100]; writeln(sb[2]); // prints 0 } now I am convinced of the invalid

Re: static array internal & dangling reference

2016-11-12 Thread Mike Parker via Digitalmars-d-learn
On Saturday, 12 November 2016 at 10:33:05 UTC, Picaud Vincent wrote: Hi all, Still learning... This time what surprised me is how static arrays work. I assume (is it true?) that for efficiency reason static size arrays like int[10] are on the stack and do not involve dynamic memory allocation:

Re: static array internal & dangling reference

2016-11-12 Thread cym13 via Digitalmars-d-learn
On Saturday, 12 November 2016 at 10:33:05 UTC, Picaud Vincent wrote: Hi all, Still learning... This time what surprised me is how static arrays work. I assume (is it true?) that for efficiency reason static size arrays like int[10] are on the stack and do not involve dynamic memory allocation:

static array internal & dangling reference

2016-11-12 Thread Picaud Vincent via Digitalmars-d-learn
Hi all, Still learning... This time what surprised me is how static arrays work. I assume (is it true?) that for efficiency reason static size arrays like int[10] are on the stack and do not involve dynamic memory allocation: First surprise: it is possible to share a static array: void main(