Esempio n. 1
0
                public static void BeginProcessInline(ref XXHash64Context context)
                {
                    var seed = context.Seed;

                    context.Current.V1 = seed + XXHash64Constants.PRIME64_1 + XXHash64Constants.PRIME64_2;
                    context.Current.V2 = seed + XXHash64Constants.PRIME64_2;
                    context.Current.V3 = seed + 0;
                    context.Current.V4 = seed - XXHash64Constants.PRIME64_1;
                }
Esempio n. 2
0
                public static XXHash64Context Process(XXHash64Context context, byte[] value, int size = -1)
                {
                    if (size == -1)
                        size = value.Length;

                    fixed(byte *buffer = value)
                    {
                        return(ProcessInline(context, buffer, size));
                    }
                }
Esempio n. 3
0
                public static void Process(ref XXHash64Context context, byte[] value, int size = -1)
                {
                    if (size == -1)
                        size = value.Length;

                    fixed(byte *buffer = value)
                    {
                        ProcessInline(ref context, buffer, size);
                    }
                }
Esempio n. 4
0
                public static XXHash64Context ProcessInline(XXHash64Context 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)
                    {
                        ulong v1 = context.Current.V1;
                        ulong v2 = context.Current.V2;
                        ulong v3 = context.Current.V3;
                        ulong v4 = context.Current.V4;

                        while (buffer <= limit)
                        {
                            v1 += ((ulong *)buffer)[0] * XXHash64Constants.PRIME64_2;
                            v2 += ((ulong *)buffer)[1] * XXHash64Constants.PRIME64_2;
                            v3 += ((ulong *)buffer)[2] * XXHash64Constants.PRIME64_2;
                            v4 += ((ulong *)buffer)[3] * XXHash64Constants.PRIME64_2;

                            buffer += 4 * sizeof(ulong);

                            v1 = Bits.RotateLeft64(v1, 31);
                            v2 = Bits.RotateLeft64(v2, 31);
                            v3 = Bits.RotateLeft64(v3, 31);
                            v4 = Bits.RotateLeft64(v4, 31);

                            v1 *= XXHash64Constants.PRIME64_1;
                            v2 *= XXHash64Constants.PRIME64_1;
                            v3 *= XXHash64Constants.PRIME64_1;
                            v4 *= XXHash64Constants.PRIME64_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);
                }
Esempio n. 5
0
                public static XXHash64Context BeginProcessInline(ulong seed = 0)
                {
                    var context = new XXHash64Context
                    {
                        Seed = seed
                    };

                    context.Current.V1 = seed + XXHash64Constants.PRIME64_1 + XXHash64Constants.PRIME64_2;
                    context.Current.V2 = seed + XXHash64Constants.PRIME64_2;
                    context.Current.V3 = seed + 0;
                    context.Current.V4 = seed - XXHash64Constants.PRIME64_1;

                    return(context);
                }
Esempio n. 6
0
 public static XXHash64Context Process(XXHash64Context context, byte *buffer, int size)
 {
     return(ProcessInline(context, buffer, size));
 }
Esempio n. 7
0
 public static ulong EndProcess(XXHash64Context context)
 {
     return(EndProcessInline(context));
 }
Esempio n. 8
0
                public static ulong EndProcessInline(XXHash64Context context)
                {
                    ulong h64;

                    if (context.BufferSize >= Alignment)
                    {
                        ulong v1 = context.Current.V1;
                        ulong v2 = context.Current.V2;
                        ulong v3 = context.Current.V3;
                        ulong v4 = context.Current.V4;

                        h64 = Bits.RotateLeft64(v1, 1) + Bits.RotateLeft64(v2, 7) + Bits.RotateLeft64(v3, 12) + Bits.RotateLeft64(v4, 18);

                        v1 *= XXHash64Constants.PRIME64_2;
                        v2 *= XXHash64Constants.PRIME64_2;
                        v3 *= XXHash64Constants.PRIME64_2;
                        v4 *= XXHash64Constants.PRIME64_2;

                        v1 = Bits.RotateLeft64(v1, 31);
                        v2 = Bits.RotateLeft64(v2, 31);
                        v3 = Bits.RotateLeft64(v3, 31);
                        v4 = Bits.RotateLeft64(v4, 31);

                        v1 *= XXHash64Constants.PRIME64_1;
                        v2 *= XXHash64Constants.PRIME64_1;
                        v3 *= XXHash64Constants.PRIME64_1;
                        v4 *= XXHash64Constants.PRIME64_1;

                        h64 ^= v1;
                        h64  = h64 * XXHash64Constants.PRIME64_1 + XXHash64Constants.PRIME64_4;

                        h64 ^= v2;
                        h64  = h64 * XXHash64Constants.PRIME64_1 + XXHash64Constants.PRIME64_4;

                        h64 ^= v3;
                        h64  = h64 * XXHash64Constants.PRIME64_1 + XXHash64Constants.PRIME64_4;

                        h64 ^= v4;
                        h64  = h64 * XXHash64Constants.PRIME64_1 + XXHash64Constants.PRIME64_4;
                    }
                    else
                    {
                        h64 = context.Seed + XXHash64Constants.PRIME64_5;
                    }

                    h64 += (uint)(context.BufferSize + context.LeftoverCount);

                    if (context.LeftoverCount > 0)
                    {
                        fixed(byte *b = context.Leftover)
                        {
                            byte *buffer = b;
                            byte *bEnd   = b + context.LeftoverCount;

                            while (buffer + 8 <= bEnd)
                            {
                                ulong k1 = *((ulong *)buffer);
                                k1     *= XXHash64Constants.PRIME64_2;
                                k1      = Bits.RotateLeft64(k1, 31);
                                k1     *= XXHash64Constants.PRIME64_1;
                                h64    ^= k1;
                                h64     = Bits.RotateLeft64(h64, 27) * XXHash64Constants.PRIME64_1 + XXHash64Constants.PRIME64_4;
                                buffer += 8;
                            }

                            if (buffer + 4 <= bEnd)
                            {
                                h64    ^= *(uint *)buffer * XXHash64Constants.PRIME64_1;
                                h64     = Bits.RotateLeft64(h64, 23) * XXHash64Constants.PRIME64_2 + XXHash64Constants.PRIME64_3;
                                buffer += 4;
                            }

                            while (buffer < bEnd)
                            {
                                h64 ^= ((ulong)*buffer) * XXHash64Constants.PRIME64_5;
                                h64  = Bits.RotateLeft64(h64, 11) * XXHash64Constants.PRIME64_1;
                                buffer++;
                            }
                        }
                    }

                    h64 ^= h64 >> 33;
                    h64 *= XXHash64Constants.PRIME64_2;
                    h64 ^= h64 >> 29;
                    h64 *= XXHash64Constants.PRIME64_3;
                    h64 ^= h64 >> 32;

                    return(h64);
                }
Esempio n. 9
0
 public static void Process(ref XXHash64Context context, byte *buffer, int size)
 {
     ProcessInline(ref context, buffer, size);
 }
Esempio n. 10
0
 public static void BeginProcess(ref XXHash64Context context)
 {
     BeginProcessInline(ref context);
 }