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值 然后与特定数相与获取索引 然后存储
    取出也一样




  • 相关阅读:
    [CF920E] Connected Components?
    [CF981E] Addition on Segments
    [BZOJ2152] 聪聪可可
    [CF1355E] Restorer Distance
    [CF1101D] GCD Counting
    [CF827C] DNA Evolution
    [HNOI2008] 明明的烦恼
    [CF712D] Memory and Scores
    [CF609E] Minimum spanning tree for each edge
    后缀自动机应用小结 I
  • 原文地址:https://www.cnblogs.com/wwwsss/p/15594125.html
Copyright © 2011-2022 走看看