|
From: | Graydon Hoare |
Subject: | [Monotone-devel] Re: RFC: Fake IDs |
Date: | Tue, 18 Jul 2006 17:24:08 -0700 |
User-agent: | Thunderbird 1.5.0.4 (Windows/20060516) |
Zack Weinberg wrote:
There are a small number of places that need a fake ID of some variety (ignoring all the unit tests, which use 'em heavily) and we currently just pick a "random" 160-bit number. I need to add a few more of these, so I thought it would be a good idea to have a principled way of generating them. The implementation I've picked is to have vocab.hh provide a fake_id() function/macro that hashes __FILE__ and __LINE__.
Eh.. I'd prefer to turn those cases where we pick fake IDs to actually loop, checking the db for a collision. It feels weird to be hard-coding collision conditions into the binary, however unlikely.
It's easy enough to start with the "all zero" SHA1 and count upwards. It's probably even fine if you just run through the first 2^64 of them for now; you can't store anywhere near that much data in an sqlite database. Something like this should do:
u8 buf[41]; for (u64 i = 0; i < UINT64_MAX; ++i) sprintf(buf, 41, "%40.40" PRIX64, i); or something slightly more tasteful, if you prefer. -graydon
[Prev in Thread] | Current Thread | [Next in Thread] |