Esempio n. 1
0
        public int Get(int key)
        {
            int hash = key % TABLE_SIZE; // Division Method; good marking

            if (table[hash] == null)
            {
                return(-1);
            }
            else
            {
                LinkedHashEntry entry = table[hash]; // marking that entry
                while (entry != null && entry.Key != key)
                {
                    entry = entry.Next;
                }
                if (entry == null)
                {
                    return(-1);
                }
                else
                {
                    return(entry.Value);
                }
            }
        }
Esempio n. 2
0
        public void Insert(int key, int value)
        {
            int hash = key % TABLE_SIZE;

            if (table[hash] == null) // value to be given at main
            {
                table[hash] = new LinkedHashEntry(key, value);
            }
            else
            {
                LinkedHashEntry entry = table[hash];
                while (entry.Next != null && entry.Key != key)
                {
                    entry = entry.Next;
                }
                if (entry.Key == key)
                {
                    entry.Value = value;
                }
                else
                {
                    entry.Next = new LinkedHashEntry(key, value);
                }
            }
        }
Esempio n. 3
0
        public void Remove(int key)
        {
            int             hash      = key % TABLE_SIZE;
            LinkedHashEntry prevEntry = null;
            LinkedHashEntry entry     = table[hash];

            while (entry.Next != null && entry.Key != key)
            {
                prevEntry = entry;
                entry     = entry.Next;
            }
            if (entry.Key != key)
            {
                if (prevEntry != null)
                {
                    table[hash] = entry.Next;
                }
                else
                {
                    prevEntry.Next = entry.Next;
                }
            }
        }
Esempio n. 4
0
        LinkedHashEntry next; // linker to the next value

        public LinkedHashEntry(int key, int valueOf)
        {
            this.key     = key;
            this.valueOf = valueOf;
            this.next    = null;
        }