1 文本格式
using System;
using System.Collections;
using System.Collections.Generic;
namespace Legalsoft.Truffer
{
public class Hashfn2
{
private static ulong[] hashfn_tab { get; set; } = new ulong[256];
private ulong h { get; set; }
public Hashfn2(int nn)
{
h = 0x544B2FBACAAF1684L;
for (int j = 0; j < 256; j++)
{
for (int i = 0; i < 31; i++)
{
h = (h >> 7) ^ h;
h = (h << 11) ^ h;
h = (h >> 10) ^ h;
}
hashfn_tab[j] = h;
}
}
public ulong fn(byte[] key)
{
h = 0xBB40E64DA205B064L;
int j = 0;
while (j < key.Length)
{
h = (h * 7664345821815920749L) ^ hashfn_tab[key[j] & 0xFF];
j++;
}
return h & 0x7FFFFFFFFFFFFFFFL;
#if __UNUSED__
while (n ? j++ < n : *k)
{
h = (h * 7664345821815920749L) ^ hashfn_tab[(byte)(*k)];
k++;
}
while ((n > 0 && j < n) || (n == 0 && k[j] > 0))
{
h = (h * 7664345821815920749L) ^ hashfn_tab[(byte)(k[j])];
j++;
}
return h;
#endif
}
}
}
2 代码格式
using System;
using System.Collections;
using System.Collections.Generic;
namespace Legalsoft.Truffer
{
public class Hashfn2
{
private static ulong[] hashfn_tab { get; set; } = new ulong[256];
private ulong h { get; set; }
public Hashfn2(int nn)
{
h = 0x544B2FBACAAF1684L;
for (int j = 0; j < 256; j++)
{
for (int i = 0; i < 31; i++)
{
h = (h >> 7) ^ h;
h = (h << 11) ^ h;
h = (h >> 10) ^ h;
}
hashfn_tab[j] = h;
}
}
public ulong fn(byte[] key)
{
h = 0xBB40E64DA205B064L;
int j = 0;
while (j < key.Length)
{
h = (h * 7664345821815920749L) ^ hashfn_tab[key[j] & 0xFF];
j++;
}
return h & 0x7FFFFFFFFFFFFFFFL;
#if __UNUSED__
while (n ? j++ < n : *k)
{
h = (h * 7664345821815920749L) ^ hashfn_tab[(byte)(*k)];
k++;
}
while ((n > 0 && j < n) || (n == 0 && k[j] > 0))
{
h = (h * 7664345821815920749L) ^ hashfn_tab[(byte)(k[j])];
j++;
}
return h;
#endif
}
}
}