[Rosettacode] Growable slices

bearophile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 16 02:47:24 PDT 2014


> There are of course ways to implement a really efficient ZLW 
> compressor in D, and such implementation could be added as 
> third D entry if it manages to be not too much long,

Third version added:
http://rosettacode.org/wiki/LZW_compression#More_Efficient_Version

I have tried to make it idiomatic D, but some of the C style is 
probably still present. The D code currently still requires five 
casts, and I have guarded them with asserts, like:

assert(tmp >> oBits <= ubyte.max);
result[outLen] = cast(ubyte)(tmp >> oBits);

Perhaps with some more semantic knowledge of the program it's 
possible to avoid one or two of those casts.

The D code contains a little less "type insanity" than the 
original C version :-)

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list