On Tuesday, 25 October 2016 at 14:40:17 UTC, Steven Schveighoffer wrote:
I will note, that in addition to the other comments, this is going to result in corruption. Simply put, the buffer that 'line' uses is reused for each line. So the string data used inside the associative array is going to change. This will result in not finding words already added when using the 'word in dictionary' check.

You need to use dictionary[word.idup] = newId; This will duplicate the line into a GC string that will live as long as the AA uses it.

If there's a case where you have immutable data AND can reference it (say... mmap files?) then referencing the string would work rather than having to duplicate it.

 However it isn't going to work with stdin input and in this case.

Reply via email to