コード例 #1
0
        public static Int32 GetValueTypeHashKey32(object obj)
        {
            if (obj is IUnique)
            {
                return(((IUnique)obj).GetKeyBytes().BitAggregate64to32().ToInt32());
            }

            if (obj.GetType().IsPrimitive)
            {
                byte *ps = stackalloc byte[8];
                Marshal.StructureToPtr(obj, (IntPtr)ps, false);
                return(BitAggregate64to32(ps));
            }

            if (obj is DateTime)
            {
                return(((DateTime)obj).ToBinary().GetBytes().BitAggregate64to32().ToInt32());
            }
            if (obj is Enum)
            {
                return(Convert.ToInt32(obj));
            }

            if (obj.GetType().IsLayoutSequential)
            {
                byte *ps = stackalloc byte[8];
                ExtractOperation.ValueStructureToPointer(obj, ps, 0);
                return(BitAggregate64to32(ps));
            }


            return((int)HashHandle32.ComputeHashCode(obj.GetBytes()));
        }
コード例 #2
0
 public override unsafe UInt64 ComputeHashCode(byte[] bytes)
 {
     fixed(byte *pa = bytes)
     {
         return(HashHandle32.ComputeHashCode(pa, bytes.Length, 0));
     }
 }
コード例 #3
0
 public static Int32 GetHashKey32(this IList obj)
 {
     if (obj is Byte[])
     {
         return(GetHashKey32((Byte[])obj));
     }
     return((int)HashHandle32.ComputeHashCode(obj.GetBytes()));
 }
コード例 #4
0
        public override unsafe Byte[] ComputeHash(byte[] bytes)
        {
            byte[] b = new byte[8];
            fixed(byte *pb = b, pa = bytes)
            {
                *((ulong *)pb) = HashHandle32.ComputeHashCode(pa, bytes.Length, 0);
            }

            return(b);
        }
コード例 #5
0
 public static Byte[] GetHashBytes32(this Object obj)
 {
     if (obj is ValueType)
     {
         return(GetValueTypeHashBytes32(obj));
     }
     if (obj is string)
     {
         return((((string)obj)).GetHashBytes32());
     }
     if (obj is IList)
     {
         return(GetHashBytes32((IList)obj));
     }
     return(HashHandle32.ComputeHash(obj.GetBytes()));
 }
コード例 #6
0
 public static Int32 GetHashKey32(this Object obj)
 {
     if (obj is ValueType)
     {
         return(GetValueTypeHashKey32(obj));
     }
     if (obj is IUnique)
     {
         return(((IUnique)obj).GetHashKey32());
     }
     if (obj is string)
     {
         return((((string)obj)).GetHashKey32());
     }
     if (obj is IList)
     {
         return(GetHashKey32((IList)obj));
     }
     return((int)HashHandle32.ComputeHashCode(obj.GetBytes()));
 }
コード例 #7
0
 public static Int32 GetHashKey32(this string obj)
 {
     fixed(char *c = obj)
     return((int)HashHandle32.ComputeHashCode((byte *)c, obj.Length * sizeof(char), 0));
 }
コード例 #8
0
 public static Int32 GetHashKey32(this Byte[] obj)
 {
     return((int)HashHandle32.ComputeHashCode(obj));
 }
コード例 #9
0
 public static Byte[] GetHashBytes32(this String obj)
 {
     fixed(char *c = obj)
     return(HashHandle32.ComputeHash((byte *)c, obj.Length * sizeof(char), 0));
 }
コード例 #10
0
 public static Byte[] GetHashBytes32(this IList obj)
 {
     return(HashHandle32.ComputeHash(obj.GetBytes()));
 }
コード例 #11
0
 public static Byte[] GetHashBytes32(this Byte[] bytes)
 {
     return(HashHandle32.ComputeHash(bytes));
 }
コード例 #12
0
 public override unsafe UInt64 ComputeHashCode(byte *bytes, int length, uint seed = 0)
 {
     return(HashHandle32.ComputeHashCode(bytes, length, 0));
 }