public static void BeginProcessInline(ref XXHash32Context context) { var seed = context.Seed; context.Current.V1 = seed + XXHash32Constants.PRIME32_1 + XXHash32Constants.PRIME32_2; context.Current.V2 = seed + XXHash32Constants.PRIME32_2; context.Current.V3 = seed + 0; context.Current.V4 = seed - XXHash32Constants.PRIME32_1; }
public static XXHash32Context ProcessInline(XXHash32Context context, byte *buffer, int size) { if (context.LeftoverCount != 0) { throw new NotSupportedException("Streaming process does not support resuming with buffers whose size is not 16 bytes aligned. Supporting it would impact performance."); } byte *bEnd = buffer + size; byte *limit = bEnd - Alignment; context.LeftoverCount = (int)(bEnd - buffer) % Alignment; if (context.BufferSize + size >= Alignment) { uint v1 = context.Current.V1; uint v2 = context.Current.V2; uint v3 = context.Current.V3; uint v4 = context.Current.V4; while (buffer <= limit) { v1 += ((uint *)buffer)[0] * XXHash32Constants.PRIME32_2; v2 += ((uint *)buffer)[1] * XXHash32Constants.PRIME32_2; v3 += ((uint *)buffer)[2] * XXHash32Constants.PRIME32_2; v4 += ((uint *)buffer)[3] * XXHash32Constants.PRIME32_2; buffer += 4 * sizeof(uint); v1 = Bits.RotateLeft32(v1, 13); v2 = Bits.RotateLeft32(v2, 13); v3 = Bits.RotateLeft32(v3, 13); v4 = Bits.RotateLeft32(v4, 13); v1 *= XXHash32Constants.PRIME32_1; v2 *= XXHash32Constants.PRIME32_1; v3 *= XXHash32Constants.PRIME32_1; v4 *= XXHash32Constants.PRIME32_1; context.BufferSize += Alignment; } context.Current.V1 = v1; context.Current.V2 = v2; context.Current.V3 = v3; context.Current.V4 = v4; } for (int i = 0; i < context.LeftoverCount; i++) { context.Leftover[i] = *buffer; buffer++; } return(context); }
public static XXHash32Context Process(XXHash32Context context, byte[] value, int size = -1) { if (size == -1) { size = value.Length; fixed(byte *buffer = value) { return(ProcessInline(context, buffer, size)); } } }
public static void Process(ref XXHash32Context context, byte[] value, int size = -1) { if (size == -1) { size = value.Length; fixed(byte *buffer = value) { ProcessInline(ref context, buffer, size); } } }
public static uint EndProcessInline(XXHash32Context context) { uint h32; if (context.BufferSize >= Alignment) { uint v1 = context.Current.V1; uint v2 = context.Current.V2; uint v3 = context.Current.V3; uint v4 = context.Current.V4; h32 = Bits.RotateLeft32(v1, 1) + Bits.RotateLeft32(v2, 7) + Bits.RotateLeft32(v3, 12) + Bits.RotateLeft32(v4, 18); } else { h32 = context.Seed + XXHash32Constants.PRIME32_5; } h32 += (uint)(context.BufferSize + context.LeftoverCount); if (context.LeftoverCount > 0) { fixed(byte *b = context.Leftover) { byte *buffer = b; byte *bEnd = b + context.LeftoverCount; while (buffer + 4 <= bEnd) { h32 += *((uint *)buffer) * XXHash32Constants.PRIME32_3; h32 = Bits.RotateLeft32(h32, 17) * XXHash32Constants.PRIME32_4; buffer += 4; } while (buffer < bEnd) { h32 += (uint)(*buffer) * XXHash32Constants.PRIME32_5; h32 = Bits.RotateLeft32(h32, 11) * XXHash32Constants.PRIME32_1; buffer++; } } } h32 ^= h32 >> 15; h32 *= XXHash32Constants.PRIME32_2; h32 ^= h32 >> 13; h32 *= XXHash32Constants.PRIME32_3; h32 ^= h32 >> 16; return(h32); }
public static XXHash32Context BeginProcessInline(uint seed = 0) { var context = new XXHash32Context { Seed = seed }; context.Current.V1 = seed + XXHash32Constants.PRIME32_1 + XXHash32Constants.PRIME32_2; context.Current.V2 = seed + XXHash32Constants.PRIME32_2; context.Current.V3 = seed + 0; context.Current.V4 = seed - XXHash32Constants.PRIME32_1; return(context); }
public static XXHash32Context Process(XXHash32Context context, byte *buffer, int size) { return(ProcessInline(context, buffer, size)); }
public static uint EndProcess(XXHash32Context context) { return(EndProcessInline(context)); }
public static void Process(ref XXHash32Context context, byte *buffer, int size) { ProcessInline(ref context, buffer, size); }
public static void BeginProcess(ref XXHash32Context context) { BeginProcessInline(ref context); }