Exemplo n.º 1
0
        public ResultItem InsertProbe(string key, string value)
        {
            ResultItem result   = new ResultItem();
            int        hashCode = key.GetHashCode() & OnlyPositiveNumbersMask;
            int        location = hashCode % buckets.Length;
            var        entry    = buckets[location];

            while (true)
            {
                result.Probe++;
                if (entry == null)
                {
                    break;
                }
                if (entry.hashCode == hashCode && string.Equals(entry.key, key))
                {
                    result.Result = ResultType.DublicateKey;
                    return(result);
                }
                entry = entry.next;
            }

            var node = new SC_ObjectEntry(hashCode, key, value);

            node.next         = buckets[location];
            buckets[location] = node;
            Count++;

            result.Result = ResultType.Okey;
            return(result);
        }
Exemplo n.º 2
0
        public ResultType Insert(string key, string value)
        {
            int hashCode = key.GetHashCode() & OnlyPositiveNumbersMask;
            int location = hashCode % buckets.Length;
            var entry    = buckets[location];

            while (entry != null)
            {
                if (entry.hashCode == hashCode && string.Equals(entry.key, key))
                {
                    return(ResultType.DublicateKey);
                }
                entry = entry.next;
            }

            var node = new SC_ObjectEntry(hashCode, key, value);

            node.next         = buckets[location];
            buckets[location] = node;
            Count++;

            return(ResultType.Okey);
        }