On 8/8/2012 1:44 AM, Johannes Pfau wrote:
Am Tue, 07 Aug 2012 17:39:15 -0700
schrieb Walter Bright <newshou...@digitalmars.com>:
On 8/7/2012 10:39 AM, Dmitry Olshansky wrote:
std.hash.hash is a new module for Phobos defining an uniform
interface for hashes and checksums. It also provides some useful
helper functions to deal with this new API.
The hash functions must use a Range interface, not a file interface.
This is extremely important.
I guess this is meant as a general statement and not specifically
targeted at my std.hash proposal?
Both.
I'm a little confused as all hashes already are OutputRanges in my
proposal. It's probably not explicit enough in the documentation, but
it's mentioned in one example and in the documentation for 'put';
It should accept an input range. But using an Output Range confuses me. A hash
function is a reduce algorithm - it accepts a sequence of input values, and
produces a single value. You should be able to write code like:
ubyte[] data;
...
auto crc = data.crc32();
For example, the hash example given is:
foreach (buffer; file.byChunk(4096 * 1024))
hash.put(buffer);
auto result = hash.finish();
Instead it should be something like:
auto result = file.byChunk(4096 * 1025).joiner.hash();
The magic is that any input range that produces bytes could be used, and that
byte producing input range can be hooked up to the input of any reducing function.
The use of a member finish() is not what any other reduce algorithm has, and so
the interface is not a general component interface.
I know the documentation on ranges in Phobos is incomplete and confusing.
I appreciate the effort and care you're putting into this.