Re: Guid question
From: Jon Shemitz (jon_at_midnightbeach.com)
Date: 03/15/05
- Next message: Steve Trefethen (Borland R&D): "Re: Why no language improvements?"
- Previous message: Satya: "Re: D2005 Pro Update2 updates nothing!"
- In reply to: Mike Margerum: "Guid question"
- Next in thread: Mike Margerum: "Re: Guid question"
- Reply: Mike Margerum: "Re: Guid question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 15 Mar 2005 08:45:36 -0800
Mike Margerum wrote:
> I am using guids (strings) as id's for my objects in a system i'm
> building. They work great but they are very large in string form (38
> bytes). Would it be a crazy idea to use the CRC of a guid string
> instead? that would be 4 bytes. That would still be pretty unique right?
I agree with those who say just use the full 16-byte binary Guid.
But, I recently had to write a hash routine for a Guid, and found that
multiplying each byte together (turning 0's into 1's) made a pretty
decent hash. I didn't do any mathematical analysis - but I did do a
NUnit test where I'd create a new Guid, hash it, and then create and
hash 100,000 or so other Guids without a collision.
Pretty simple to code - something like
int Accumulator = 1;
foreach (byte B in ThisGuid.ToByteArray())
Accumulator = unchecked (Accumulator * ((B != 0) ? B : 1));
- which is probably a bit faster than a CRC.
-- www.midnightbeach.com
- Next message: Steve Trefethen (Borland R&D): "Re: Why no language improvements?"
- Previous message: Satya: "Re: D2005 Pro Update2 updates nothing!"
- In reply to: Mike Margerum: "Guid question"
- Next in thread: Mike Margerum: "Re: Guid question"
- Reply: Mike Margerum: "Re: Guid question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|