Пример #1
0
        /// <summary>
        /// Returns true if and only if the key is already specified
        /// which will also in return update the given value with the specified.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool Put(K key, V value)
        {
            int initEntryIndex = HashSlingerSlasher(key);

            Console.WriteLine(initEntryIndex + " is the value");
            SGLEntry <K, V> entry = new SGLEntry <K, V>(key, value);

            if (Entries[initEntryIndex] == null || Entries[initEntryIndex].Key.Equals(entry.Key))
            {
                // Either the position is of the same key, or it is not in use
                if (Entries[initEntryIndex] == null)
                {
                    Entries[initEntryIndex] = entry;
                    return(false);
                }
                else
                {
                    Entries[initEntryIndex].SetValue(entry.Value);
                    return(true);
                }
            }
            else
            {
                SGLEntry <K, V> iter = Entries[initEntryIndex];

                while (iter.Next != null || iter.Next.Key.Equals(entry.Key))
                {
                    iter = iter.Next;
                    Console.WriteLine(iter.Value + "  -  ");
                }

                // There was nothing in the next entry.
                // else, we have this entry already.
                if (iter.Next == null)
                {
                    iter.SetNext(entry);
                    return(false);
                }
                else
                {
                    iter.SetValue(entry.Value);
                    return(true);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Sets the next entry.
 /// </summary>
 /// <param name="entry"></param>
 public void SetNext(SGLEntry <X, Y> entry)
 {
     Next = entry;
 }