Exemplo n.º 1
0
        public static bool TryFind <K, V>(this ImHashMap <K, V> map, K key, out V value)
        {
            var hash = key.GetHashCode();

            while (map != null)
            {
                if (map.Hash == hash)
                {
                    if (ReferenceEquals(key, map.Key) || key.Equals(map.Key))
                    {
                        value = map.Value;
                        return(true);
                    }
                    return(map.TryFindConflictedValue(key, out value));
                }

                map = hash < map.Hash
                    ? (map as ImHashMap <K, V> .Branch)?.LeftNode
                    : (map as ImHashMap <K, V> .Branch)?.RightNode;
            }

            value = default(V);
            return(false);
        }