zoukankan      html  css  js  c++  java
  • hashtable

    /**
    * Returns the value to which the specified key is mapped,
    * or {@code null} if this map contains no mapping for the key.
    *
    * <p>More formally, if this map contains a mapping from a key
    * {@code k} to a value {@code v} such that {@code (key.equals(k))},
    * then this method returns {@code v}; otherwise it returns
    * {@code null}. (There can be at most one such mapping.)
    *
    * @param key the key whose associated value is to be returned
    * @return the value to which the specified key is mapped, or
    * {@code null} if this map contains no mapping for the key
    * @throws NullPointerException if the specified key is null
    * @see #put(Object, Object)
    */
    @SuppressWarnings("unchecked")
    public synchronized V get(Object key) {
    Entry<?,?> tab[] = table;
    int hash = key.hashCode();
    int index = (hash & 0x7FFFFFFF) % tab.length;
    for (Entry<?,?> e = tab[index] ; e != null ; e = e.next) {
    if ((e.hash == hash) && e.key.equals(key)) {
    return (V)e.value;
    }
    }
    return null;
    }

    根据key的hash值获取索引 然后取出数据
    你的数据本质存储在Entry数组中
    根据key的hash值 然后与特定数相与获取索引 然后存储
    取出也一样




  • 相关阅读:
    Linux系统安装Apache 2.4.6
    Redhat Server 5.7 安装配置PHP
    ORACLE基本数据类型总结
    Nagios学习实践系列——产品介绍篇
    Linux技术修复
    python的特殊方法:
    python获取对象信息
    python多重继承:
    python多态
    python类的继承
  • 原文地址:https://www.cnblogs.com/wwwsss/p/15594125.html
Copyright © 2011-2022 走看看