The review of std.hash package

Johannes Pfau nospam at example.com
Wed Aug 8 12:08:58 PDT 2012


Am Wed, 08 Aug 2012 11:40:10 -0700
schrieb Walter Bright <newshound2 at digitalmars.com>:

> 
> Take a look at the reduce function in 
> http://dlang.org/phobos/std_algorithm.html#reduce
> 
> It has provision for an initial state that can be the current running
> total.
> 

This can only work if the final state is valid as an initial state.
This is just not true for some hash algorithms.

---
auto sum = reduce!("a + b")(0, range);
auto sum2 = reduce!("a + b")(sum, range2);
---

---
MD5 hash;
hash.start();

auto sum = copy(range, hash);
auto sum2 = copy(range2, sum);

auto result = hash.finish();
---

No where's the difference, except that for hashes the context ('hash')
has to be setup and finished manually?


More information about the Digitalmars-d mailing list