コード例 #1
0
 public NodeHT(Object key, Object value, int hash, NodeHT next)
 {
     this.key   = key;
     this.value = value;
     this.hash  = hash;
     this.next  = next;
 }
コード例 #2
0
        public Object Get(Object key)
        {
            if (key == null)
            {
                return(null);
            }
            int    hash = HashCode(key);
            NodeHT node = table[hash];

            while (node != null)
            {
                if (node.key.Equals(key))
                {
                    return(node.value);
                }
                node = node.next;
            }
            return(null);
        }
コード例 #3
0
        public void Put(Object key, Object value)
        {
            int    hash    = HashCode(key);
            NodeHT newNode = new NodeHT(key, value, hash, null);
            NodeHT node    = table[hash];

            while (node != null)
            {
                if (node.key.Equals(key))
                {
                    node.value = value;
                    return;
                }
                node = node.next;
            }
            newNode.next = table[hash];
            table[hash]  = newNode;
            size++;
        }