Converting uint[] slice to string for the purpose of hashing?
Enjoys Math via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Jul 23 05:14:09 PDT 2015
On Thursday, 23 July 2015 at 12:10:04 UTC, Enjoys Math wrote:
> On Thursday, 23 July 2015 at 11:49:05 UTC, cym13 wrote:
>> [...]
>
> Thanks. That worked. Here's my code:
>
> module hashtools;
> import std.conv;
> import std.digest.md;
>
> string uintSliceToHash(const uint[] slice) {
> auto md5 = new MD5Digest();
> md5.put(slice.to!(ubyte[]));
> return md5.finish().to!(string);
> }
>
> unittest {
> import std.stdio;
> uint[] slice = [1,2,3,4];
> writeln(uintSliceToHash(slice));
> }
Actually, uint[] seems to be hashable:
import std.stdio;
int[uint[]] aa;
aa[[1,2,3]] = 5;
writeln(aa[[1,2,3]]);
WORKS
More information about the Digitalmars-d-learn
mailing list