Beispiel #1
0
        private static UInt128 GetHash(CosmosElement cosmosElement, UInt128 seed)
        {
            if (cosmosElement == null)
            {
                return(DistinctHash.GetUndefinedHash(seed));
            }

            return(cosmosElement.Accept(CosmosElementHasher.Singleton, seed));
        }
Beispiel #2
0
        /// <summary>
        /// Gets the hash of a JToken given a seed.
        /// </summary>
        /// <param name="cosmosElement">The cosmos element to hash.</param>
        /// <param name="seed">The seed to use.</param>
        /// <returns>The hash of the JToken.</returns>
        private static UInt128 GetHash(CosmosElement cosmosElement, UInt128 seed)
        {
            if (cosmosElement == null)
            {
                return(DistinctHash.GetUndefinedHash(seed));
            }

            CosmosElementType cosmosElementType = cosmosElement.Type;
            UInt128           hash;

            switch (cosmosElementType)
            {
            case CosmosElementType.Array:
                hash = DistinctHash.GetArrayHash(cosmosElement as CosmosArray, seed);
                break;

            case CosmosElementType.Boolean:
                hash = DistinctHash.GetBooleanHash((cosmosElement as CosmosBoolean).Value, seed);
                break;

            case CosmosElementType.Null:
                hash = DistinctHash.GetNullHash(seed);
                break;

            case CosmosElementType.Number:
                // TODO: we need to differentiate between the different number types.
                CosmosNumber cosmosNumber = cosmosElement as CosmosNumber;
                double       number;
                if (cosmosNumber.IsFloatingPoint)
                {
                    number = cosmosNumber.AsFloatingPoint().Value;
                }
                else
                {
                    number = cosmosNumber.AsInteger().Value;
                }

                hash = DistinctHash.GetNumberHash(number, seed);
                break;

            case CosmosElementType.Object:
                hash = DistinctHash.GetObjectHash(cosmosElement as CosmosObject, seed);
                break;

            case CosmosElementType.String:
                hash = DistinctHash.GetStringHash((cosmosElement as CosmosString).Value, seed);
                break;

            default:
                throw new ArgumentException($"Unexpected {nameof(CosmosElementType)} : {cosmosElementType}");
            }

            return(hash);
        }