当前位置: 首页 > news >正文

智库建设网站方案百度推广客户端下载网址

智库建设网站方案,百度推广客户端下载网址,西安软件公司招聘信息,wordpress登录后台没有加载css一、put方法的流程图 二、put方法的执行步骤 首先,根据key值计算哈希值。然后判断table数组是否为空或者数组长度是否为0,是的话则要扩容,resize()。接着,根据哈希值计算数组下标。如果这个下标位置为空&a…

一、put方法的流程图


二、put方法的执行步骤

  1. 首先,根据key值计算哈希值。
  2. 然后判断table数组是否为空或者数组长度是否为0,是的话则要扩容,resize()。
  3. 接着,根据哈希值计算数组下标。
  4. 如果这个下标位置为空,添加元素即可。
  5. 如果这个下标位置不为空,则判断此下标位置的首元素的key值与要添加元素的key值是否相同,相同的话,就直接覆盖元素。
  6. 不相同的话,则判断首元素是否为树节点,是的话,则向这个红黑树中插入元素(在红黑树中插入一个新节点时,首先会遍历树以找到这个新节点应该插入的位置。在这个遍历过程中,也会检查是否已经存在相同key值的节点。如果存在,也会覆盖元素;不存在,则新节点会被插入到正确的位置)。
  7. 如果是链表的话,那就需要遍历链表,看key是否已经存在,存在则覆盖元素,不存在则在链表尾部插入元素。插入之后,如果链表长度大于等于8,则需要把链表转换为红黑树。
  8. 最后,待所有元素处理完之后,还要判断容量是否超过阈值,超过了则需要扩容。

三、对应源码:

       /*** Computes key.hashCode() and spreads (XORs) higher bits of hash* to lower.  Because the table uses power-of-two masking, sets of* hashes that vary only in bits above the current mask will* always collide. (Among known examples are sets of Float keys* holding consecutive whole numbers in small tables.)  So we* apply a transform that spreads the impact of higher bits* downward. There is a tradeoff between speed, utility, and* quality of bit-spreading. Because many common sets of hashes* are already reasonably distributed (so don't benefit from* spreading), and because we use trees to handle large sets of* collisions in bins, we just XOR some shifted bits in the* cheapest possible way to reduce systematic lossage, as well as* to incorporate impact of the highest bits that would otherwise* never be used in index calculations because of table bounds.*/static final int hash(Object key) {//1.首先,根据key值计算哈希值。int h;return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);}/*** Associates the specified value with the specified key in this map.* If the map previously contained a mapping for the key, the old* value is replaced.** @param key key with which the specified value is to be associated* @param value value to be associated with the specified key* @return the previous value associated with <tt>key</tt>, or*         <tt>null</tt> if there was no mapping for <tt>key</tt>.*         (A <tt>null</tt> return can also indicate that the map*         previously associated <tt>null</tt> with <tt>key</tt>.)*/public V put(K key, V value) {return putVal(hash(key), key, value, false, true);//hash值}/*** Implements Map.put and related methods.** @param hash hash for key* @param key the key* @param value the value to put* @param onlyIfAbsent if true, don't change existing value* @param evict if false, the table is in creation mode.* @return previous value, or null if none*/final V putVal(int hash, K key, V value, boolean onlyIfAbsent,boolean evict) {Node<K,V>[] tab; Node<K,V> p; int n, i;//2.然后判断table数组是否为空或者数组长度是否为0,是的话则要扩容,resize()。if ((tab = table) == null || (n = tab.length) == 0)n = (tab = resize()).length;//3.接着,根据哈希值计算数组下标。
//4.如果这个下标位置为空,添加元素即可。if ((p = tab[i = (n - 1) & hash]) == null)tab[i] = newNode(hash, key, value, null);else {//5.如果这个下标位置不为空,则判断此下标位置的首元素的key值与要添加元素的key值是否相同,相同的话,就直接覆盖元素。Node<K,V> e; K k;if (p.hash == hash &&((k = p.key) == key || (key != null && key.equals(k))))e = p;//6.不相同的话,则判断首元素是否为树节点,是的话,则向这个红黑树中插入元素else if (p instanceof TreeNode)e = ((TreeNode<K,V>)p).putTreeVal(this, tab, hash, key, value);//7.如果是链表的话,那就需要遍历链表,看key是否已经存在,存在则覆盖元素,不存在则在链表尾部插入元素。不存在则在链表尾部插入元素。插入之后,如果链表长度大于等于8,则需要把链表转换为红黑树。else {for (int binCount = 0; ; ++binCount) {if ((e = p.next) == null) {p.next = newNode(hash, key, value, null);if (binCount >= TREEIFY_THRESHOLD - 1) // -1 for 1sttreeifyBin(tab, hash);//转为红黑树break;}if (e.hash == hash &&((k = e.key) == key || (key != null && key.equals(k))))break;p = e;}}if (e != null) { // existing mapping for keyV oldValue = e.value;if (!onlyIfAbsent || oldValue == null)e.value = value;afterNodeAccess(e);return oldValue;}}++modCount;//8.最后,待所有元素处理完之后,还要判断容量是否超过阈值,超过了则需要扩容。if (++size > threshold)resize();afterNodeInsertion(evict);return null;}

http://www.hkea.cn/news/441930/

相关文章:

  • 铜陵市住房和城乡建设委员会网站中国最新疫情最新消息
  • 动态网站建设 教程接广告推广的平台
  • 人力资源和社会保障部是干什么的seo最新快速排名
  • 网站标题关键优化网络营销代运营外包公司
  • 罗山网站建设seo网络推广优化
  • 如何在eclipse上做网站网站链接查询
  • 企业网站如何设计网页直通车推广计划方案
  • 简单的购物网站设计seo网络推广知识
  • 做众筹的网站关键词网站推广
  • 做网站 页面自适应渠道推广
  • 广东企业网站建设策划高端网站设计公司
  • wordpress文章批量编辑网站优化方案模板
  • 北京互联网公司开发的网站今日关注
  • 网站限制上传图片大小免费网络推广100种方法
  • 提供网站建设服务的网站价格快速推广
  • 政府网站建设原则 统筹规划进入百度官网
  • 网站如何做等级保护谷歌搜索引擎363
  • 天河网站建设网络推广不属于网络推广方法
  • 阜阳中国建设银行官网站百度提交入口网站网址
  • 游戏网站怎么建设广告营销公司
  • 韩城做网站b2b平台推广网站
  • 网站建设课程设计摘要生活中的网络营销有哪些
  • 简单网站建设优化推广100个电商平台
  • 网站建设的仿站seo顾问收费
  • 珠宝行业做网站的好处株洲seo排名
  • java web开发网站开发cpa推广接单平台
  • 广西南宁网络营销网站网站权重优化
  • 黄山网站设计公司营销网站建设多少钱
  • 网站建设招标评分表湖南关键词优化推荐
  • 淘宝上成都网站建设如何制作视频网站