1 文本格式
using System;
namespace Legalsoft.Truffer
{
/// <summary>
/// High-quality random hash of an integer into several numeric types.
/// </summary>
public class Ranhash
{
public Ranhash()
{
}
public ulong int64(ulong u)
{
ulong v = u * 3935559000370003845L + 2691343689449507681L;
v ^= v >> 21;
v ^= v << 37;
v ^= v >> 4;
v *= 4768777513237032717L;
v ^= v << 20;
v ^= v >> 41;
v ^= v << 5;
return v;
}
public uint int32(ulong u)
{
return (uint)((long)u & 0xffffffff);
}
/// <summary>
/// Returns hash of u as a double-precision
/// floating value between 0. and 1.
/// </summary>
/// <param name="u"></param>
/// <returns></returns>
public double doub(ulong u)
{
double r = 5.42101086242752217E-20 * int64(u);
return (r < 0.0) ? (1 + r) : r;
}
}
}
2 代码格式
using System;
namespace Legalsoft.Truffer
{
/// <summary>
/// High-quality random hash of an integer into several numeric types.
/// </summary>
public class Ranhash
{
public Ranhash()
{
}
public ulong int64(ulong u)
{
ulong v = u * 3935559000370003845L + 2691343689449507681L;
v ^= v >> 21;
v ^= v << 37;
v ^= v >> 4;
v *= 4768777513237032717L;
v ^= v << 20;
v ^= v >> 41;
v ^= v << 5;
return v;
}
public uint int32(ulong u)
{
return (uint)((long)u & 0xffffffff);
}
/// <summary>
/// Returns hash of u as a double-precision
/// floating value between 0. and 1.
/// </summary>
/// <param name="u"></param>
/// <returns></returns>
public double doub(ulong u)
{
double r = 5.42101086242752217E-20 * int64(u);
return (r < 0.0) ? (1 + r) : r;
}
}
}