Fix transposed ranges

Cym13 cpicard at openmailbox.org
Mon Apr 2 19:24:26 UTC 2018


On Monday, 2 April 2018 at 18:33:25 UTC, Steven Schveighoffer 
wrote:
> On 3/30/18 4:45 PM, Cym13 wrote:
>> On Friday, 30 March 2018 at 20:43:09 UTC, Cym13 wrote:
>>> Hi, I've got the following code that takes a list of files as 
>>> argument and xor them together (demo example sufficient for 
>>> that discussion).
>>>
>>> [...]
>> 
>> Forgot to mention but I'm also quite annoyed at the need for 
>> that ".array" because "transposed" requires the RoR to be 
>> assignable. That kills the laziness. I'm very much open to 
>> suggestions regarding that point.
>
> 1. The .save deprecation may not affect you. It's probably 
> being used by map or fold but may not need to be. Once it's 
> removed, you may just see the warning go away, and everything 
> still works just fine. I'm not 100% sure on this, as I don't 
> know where it's being used.

That's good to hear, although I don't realy like warnings on 
which I have no control.

> 2. The array is necessary, as map is lazy. what you want is a 
> range of the first byte of each file, then a range of the 
> second byte of each file, etc. mapping to a byte array can't 
> possibly do this, because what would happen is that map would 
> re-open the file, re-read it's contents, and then give you the 
> *second* byte. This is horribly inefficient.

While I agree that using an array is ugly, and that I want ranges 
of first byte (which is why I'm using transposed in the first 
place), transposed just doesn't let me work with the result of 
map itself. I suppose it's because its signature stipulates 
hasAssignableElements. I feel like I'm missing something there 
but I can't see what.

> But you can probably reduce the memory requirements by 
> streaming each file's bytes as you need it. Unfortunately, I 
> don't see a 'byByte' method on File, so you may have to look 
> elsewhere for that.
>
> -Steve




More information about the Digitalmars-d-learn mailing list