【发布时间】:2010-08-14 22:29:17
【问题描述】:
问题:当你有一个用于插入数据库的 .NET GUID 时,它的结构是这样的:
60 bits of timestamp,
48 bits of computer identifier,
14 bits of uniquifier, and
6 bits are fixed,
----
128 bits total
现在我遇到了 GUID 的问题,因为它是一个 128 位数字,而我使用的一些 DB 仅支持 64 位数字。
现在我不想通过使用自动增量 bigint 值来解决这个难题,因为我希望能够进行离线复制。
所以我产生了创建一个本地唯一标识符类的想法,它基本上是一个缩小为 64 位值的 GUID。
我想出了这个:
day 9 bit (12*31=372 d)
year 8 bit (2266-2010 = 256 y)
seconds 17 bit (24*60*60=86400 s)
hostname 12 bit (2^12=4096)
random 18 bit (2^18=262144)
------------------------
64 bits total
我现在的问题是:时间戳几乎固定为 34 位,主机名 + 随机数留给我 64-34=30 位。
现在我的问题是: 1)您是希望增加hostname-hash bitsize而减少random bitsize,还是增加random bitsize而减少hostname-hash bitsize。
2) 是否存在将每个字符串减少到 n 位的哈希算法? n 理想情况下 = 12 或尽可能接近。
【问题讨论】:
标签: c# .net vb.net guid uniqueidentifier