Re: Filling an array at compile time

2022-02-09 Thread bauss via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 16:37:22 UTC, Ali Çehreli wrote: On 2/9/22 01:07, bauss wrote: > It will not run at compile-time because csvText is a runtime variable. > It should be enum to be accessible at compile-time. Yes. For the sake of completeness, any expression needed at compile

Re: how to handle very large array?

2022-02-09 Thread forkit via Digitalmars-d-learn
On Thursday, 10 February 2022 at 01:43:54 UTC, H. S. Teoh wrote: On Thu, Feb 10, 2022 at 01:32:00AM +, MichaelBi via Digitalmars-d-learn wrote: On Wednesday, 9 February 2022 at 19:48:49 UTC, H. S. Teoh wrote: > [...] thanks, very helpful! i am using a assocArray now... Are you sure

Re: how to handle very large array?

2022-02-09 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 10, 2022 at 01:32:00AM +, MichaelBi via Digitalmars-d-learn wrote: > On Wednesday, 9 February 2022 at 19:48:49 UTC, H. S. Teoh wrote: > > [...] > > thanks, very helpful! i am using a assocArray now... Are you sure that's what you need? T -- Computers are like a jungle: they

Re: how to handle very large array?

2022-02-09 Thread MichaelBi via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 19:48:49 UTC, H. S. Teoh wrote: [...] thanks, very helpful! i am using a assocArray now...

Re: How to use sets in D?

2022-02-09 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Feb 10, 2022 at 12:53:08AM +, Siarhei Siamashka via Digitalmars-d-learn wrote: > On Wednesday, 9 February 2022 at 21:05:47 UTC, Siarhei Siamashka wrote: > > Is the current implementation of associative arrays in D language > > resistant to Denial of Service hash collision attacks? >

Re: How to use sets in D?

2022-02-09 Thread Siarhei Siamashka via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 21:05:47 UTC, Siarhei Siamashka wrote: Is the current implementation of associative arrays in D language resistant to Denial of Service hash collision attacks? Answering to myself. No, it isn't. Here's a simple example: ```D import std, core.time; const ulong

Re: How to use sets in D?

2022-02-09 Thread Siarhei Siamashka via Digitalmars-d-learn
On Tuesday, 8 February 2022 at 21:42:06 UTC, H. S. Teoh wrote: But as I said, this is overkill for something so trivial. Using `bool[E]` or an RBTree works just fine. Is the current implementation of associative arrays in D language resistant to Denial of Service hash collision attacks? *

Re: how to handle very large array?

2022-02-09 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 09, 2022 at 11:05:23AM -0800, Ali Çehreli via Digitalmars-d-learn wrote: > On 2/9/22 10:38, MoonlightSentinel wrote: > > > There's a way to use a much smaller array to manage the lanternfish > > population... > > As soon as I read your comment, I was reminded of a certain ingenious

Re: how to handle very large array?

2022-02-09 Thread Ali Çehreli via Digitalmars-d-learn
On 2/9/22 10:38, MoonlightSentinel wrote: > There's a way to use a much smaller array to manage the lanternfish > population... As soon as I read your comment, I was reminded of a certain ingenious sorting algorithm that is O(N). ;) After reading the problem description, I see your hint was

Re: how to handle very large array?

2022-02-09 Thread MoonlightSentinel via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 10:03:21 UTC, MichaelBi wrote: day6 of the advent of code 2021 needs to handle an array of 10^12 length, or even bigger... As others have mentioned, huge arrays require appropriate memory / the use of memory-mapped files to actually store it. But the

Re: Filling an array at compile time

2022-02-09 Thread Ali Çehreli via Digitalmars-d-learn
On 2/9/22 08:37, Ali Çehreli wrote: > In any case, some people may find a compile-time file parsing example > that I included in a presentation: That should mean "may find interesting". And I've just realized that the chapter link is off in that video. This is the beginning of that section:

Re: Filling an array at compile time

2022-02-09 Thread Ali Çehreli via Digitalmars-d-learn
On 2/9/22 01:07, bauss wrote: > It will not run at compile-time because csvText is a runtime variable. > It should be enum to be accessible at compile-time. Yes. For the sake of completeness, any expression needed at compile time will be (attempted to be) executed at compile time. For example,

Re: Filling an array at compile time

2022-02-09 Thread user1234 via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 10:25:34 UTC, bauss wrote: Is it guaranteed that the value is initialized at compiletime however? yes, D guarentees this at 100%.

Re: Filling an array at compile time

2022-02-09 Thread Vindex via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 10:01:15 UTC, Anonymouse wrote: On Wednesday, 9 February 2022 at 08:12:52 UTC, Vindex wrote: [...] I would do this. ``` import std; alias Record = Tuple!(string, string, string); static immutable string[][] table = () { string[][] table; string

Re: how to handle very large array?

2022-02-09 Thread user1234 via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 10:29:03 UTC, ag0aep6g wrote: Try to think of a more efficient way of storing the information. I cant agree more. The problem of OP is not dynamic arrays, it's that he uses an inadequate data structure.

Re: how to handle very large array?

2022-02-09 Thread bauss via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 10:03:21 UTC, MichaelBi wrote: day6 of the advent of code 2021 needs to handle an array of 10^12 length, or even bigger... plus change elements and append elements. normal implementation such as length, appender and ref element etc, seems cannot handle that big

Re: how to handle very large array?

2022-02-09 Thread ag0aep6g via Digitalmars-d-learn
On 09.02.22 11:09, MichaelBi wrote: On Wednesday, 9 February 2022 at 10:05:23 UTC, MichaelBi wrote: [...] got outofmemory error: core.exception.OutOfMemoryError@src\core\lifetime.d(126): Memory allocation failed https://adventofcode.com/2021/day/6#part2 "Suppose the lanternfish live

Re: Filling an array at compile time

2022-02-09 Thread bauss via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 10:01:15 UTC, Anonymouse wrote: On Wednesday, 9 February 2022 at 08:12:52 UTC, Vindex wrote: Will the loop (foreach) run at compile time? How can I make it work at compile time? ``` import std.csv, std.stdio; alias Record = Tuple!(string, string, string);

Re: how to handle very large array?

2022-02-09 Thread MichaelBi via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 10:03:21 UTC, MichaelBi wrote: day6 of the advent of code 2021 needs to handle an array of 10^12 length, or even bigger... plus change elements and append elements. normal implementation such as length, appender and ref element etc, seems cannot handle that big

Re: how to handle very large array?

2022-02-09 Thread MichaelBi via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 10:05:23 UTC, MichaelBi wrote: On Wednesday, 9 February 2022 at 10:03:21 UTC, MichaelBi wrote: day6 of the advent of code 2021 needs to handle an array of 10^12 length, or even bigger... plus change elements and append elements. normal implementation such as

Re: Filling an array at compile time

2022-02-09 Thread Anonymouse via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 08:12:52 UTC, Vindex wrote: Will the loop (foreach) run at compile time? How can I make it work at compile time? ``` import std.csv, std.stdio; alias Record = Tuple!(string, string, string); immutable string[][] table; shared static this() { string

how to handle very large array?

2022-02-09 Thread MichaelBi via Digitalmars-d-learn
day6 of the advent of code 2021 needs to handle an array of 10^12 length, or even bigger... plus change elements and append elements. normal implementation such as length, appender and ref element etc, seems cannot handle that big array? is there any alternative data structure or algorithm can

Re: Filling an array at compile time

2022-02-09 Thread bauss via Digitalmars-d-learn
On Wednesday, 9 February 2022 at 08:12:52 UTC, Vindex wrote: Will the loop (foreach) run at compile time? How can I make it work at compile time? ``` import std.csv, std.stdio; alias Record = Tuple!(string, string, string); immutable string[][] table; shared static this() { string

Re: How to verify DMD download with GPG?

2022-02-09 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Tuesday, 8 February 2022 at 20:15:50 UTC, forkit wrote: btw. the key is listed there - not sure what you mean. I didn't see "3AAF1A18E61F6FAA3B7193E4DB8C5218B9329CF8" on the listing on the webpage https://dlang.org/gpg_keys.html That pages is not similar to what I get with "--list-keys

Filling an array at compile time

2022-02-09 Thread Vindex via Digitalmars-d-learn
Will the loop (foreach) run at compile time? How can I make it work at compile time? ``` import std.csv, std.stdio; alias Record = Tuple!(string, string, string); immutable string[][] table; shared static this() { string csvText = import("file.csv"); foreach (record;