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

成都微网站公司如何规划企业网络推广方案

成都微网站公司,如何规划企业网络推广方案,做团膳有哪些网站,wordpress评论选项HashMap 的 put 方法是一个常用的操作,它将一个键值对插入到哈希表中。下面是 put 方法执行的详细流程,包括各个步骤的解释,并附上相应的代码片段。 1. 检查键是否为 null 如果传入的键为 null,HashMap 会特别处理这种情况&…

HashMapput 方法是一个常用的操作,它将一个键值对插入到哈希表中。下面是 put 方法执行的详细流程,包括各个步骤的解释,并附上相应的代码片段。

1. 检查键是否为 null

如果传入的键为 nullHashMap 会特别处理这种情况,因为 null 是允许作为键的,但是它会在特殊位置(通常是数组的第一个位置)存储。

if (key == null) {return putForNullKey(value);
}

2. 计算哈希值

对于非 null 的键,HashMap 会首先计算出该键的哈希值。哈希值的计算是通过调用键的 hashCode() 方法,再经过一定的扰动处理,以减少哈希冲突。

int hash = hash(key.hashCode());
int index = indexFor(hash, table.length);

这里的 hash() 是一个方法,用于对键的哈希值进行扰动,indexFor() 方法则用来根据计算出的哈希值找到数组中的位置。

3. 查找位置

接下来,HashMap 会根据计算出的索引(index)来查找对应的桶(数组位置)。如果该位置已经存在元素,则会检查该位置的链表或红黑树结构,查看是否已经存在相同的键。

for (Entry<K,V> e = table[index]; e != null; e = e.next) {K k;if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {V oldValue = e.value;e.value = value;return oldValue;}
}

4. 插入新元素

如果在相应位置没有找到相同的键,HashMap 会将新的键值对插入到桶中。如果该位置为空,直接插入该元素。如果该位置已经存在链表或红黑树,则会把新元素加入到链表头部或树中。

createEntry(hash, key, value, index);

5. 扩容

HashMap 会根据当前的负载因子(默认是 0.75)来判断是否需要扩容。如果当前元素数量超出了负载因子的限制,HashMap 会进行扩容操作,这会重新计算每个元素的位置,并将元素重新插入到新的数组中。

if (size > threshold)resize();

完整代码示例

public V put(K key, V value) {if (key == null) {return putForNullKey(value);}int hash = hash(key.hashCode());int index = indexFor(hash, table.length);for (Entry<K,V> e = table[index]; e != null; e = e.next) {K k;if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {V oldValue = e.value;e.value = value;return oldValue;}}createEntry(hash, key, value, index);if (size++ >= threshold) {resize();}return null;
}private int hash(int h) {h ^= (h >>> 20) ^ (h >>> 12);return h ^ (h >>> 7) ^ (h >>> 4);
}private int indexFor(int hash, int length) {return hash & (length - 1);
}private void createEntry(int hash, K key, V value, int bucketIndex) {Entry<K,V> e = table[bucketIndex];table[bucketIndex] = new Entry<>(hash, key, value, e);
}private void resize() {// 扩容的具体实现
}

关键点总结:

  1. 哈希值计算:使用 hashCode 和扰动函数来减少冲突。
  2. 桶的查找:通过数组索引查找对应位置,如果发生冲突,使用链表或红黑树来存储多个元素。
  3. 元素插入:如果该位置没有找到相同的键,插入新元素。
  4. 扩容机制:当负载因子达到一定比例时,HashMap 会扩展数组并重新散列元素。

这个过程对于每次调用 put 都是会依次执行的,确保 HashMap 的高效插入与查询操作。


文章转载自:
http://megadont.wqpr.cn
http://iconoclastic.wqpr.cn
http://tetraiodothyronine.wqpr.cn
http://streptobacillus.wqpr.cn
http://spiff.wqpr.cn
http://sellanders.wqpr.cn
http://pastorate.wqpr.cn
http://steamship.wqpr.cn
http://souterrain.wqpr.cn
http://ritualization.wqpr.cn
http://affrontive.wqpr.cn
http://polyploid.wqpr.cn
http://sneaking.wqpr.cn
http://hebron.wqpr.cn
http://gorblimey.wqpr.cn
http://nub.wqpr.cn
http://diarial.wqpr.cn
http://offer.wqpr.cn
http://hydrolase.wqpr.cn
http://abbreviatory.wqpr.cn
http://cervicovaginal.wqpr.cn
http://configure.wqpr.cn
http://impulse.wqpr.cn
http://snorty.wqpr.cn
http://dirndl.wqpr.cn
http://intrepidity.wqpr.cn
http://squib.wqpr.cn
http://say.wqpr.cn
http://idolum.wqpr.cn
http://infantile.wqpr.cn
http://reaganism.wqpr.cn
http://eyer.wqpr.cn
http://patulin.wqpr.cn
http://unification.wqpr.cn
http://misshapen.wqpr.cn
http://coq.wqpr.cn
http://dramalogue.wqpr.cn
http://oleraceous.wqpr.cn
http://culicid.wqpr.cn
http://myelitis.wqpr.cn
http://unperceptive.wqpr.cn
http://bayou.wqpr.cn
http://alkylate.wqpr.cn
http://dec.wqpr.cn
http://cordially.wqpr.cn
http://gemmulation.wqpr.cn
http://grayling.wqpr.cn
http://molasses.wqpr.cn
http://hefei.wqpr.cn
http://siphunculate.wqpr.cn
http://congressman.wqpr.cn
http://bimbo.wqpr.cn
http://inadvertently.wqpr.cn
http://hymn.wqpr.cn
http://chiefless.wqpr.cn
http://unsafe.wqpr.cn
http://sortilege.wqpr.cn
http://condylar.wqpr.cn
http://immie.wqpr.cn
http://feazings.wqpr.cn
http://lestobiosis.wqpr.cn
http://keloid.wqpr.cn
http://pothook.wqpr.cn
http://oscillator.wqpr.cn
http://tillicum.wqpr.cn
http://travelogue.wqpr.cn
http://honeymoon.wqpr.cn
http://lineate.wqpr.cn
http://pasqueflower.wqpr.cn
http://eusocial.wqpr.cn
http://laggardly.wqpr.cn
http://fauvism.wqpr.cn
http://littoral.wqpr.cn
http://conspicuity.wqpr.cn
http://presage.wqpr.cn
http://cornet.wqpr.cn
http://liriodendron.wqpr.cn
http://crackleware.wqpr.cn
http://photocell.wqpr.cn
http://levitron.wqpr.cn
http://splittism.wqpr.cn
http://karsey.wqpr.cn
http://misunderstanding.wqpr.cn
http://semiquaver.wqpr.cn
http://desna.wqpr.cn
http://fragrance.wqpr.cn
http://dunderhead.wqpr.cn
http://deontic.wqpr.cn
http://cetin.wqpr.cn
http://nannoplankton.wqpr.cn
http://yearningly.wqpr.cn
http://predication.wqpr.cn
http://septicaemia.wqpr.cn
http://sulfuretted.wqpr.cn
http://pituitrin.wqpr.cn
http://carbonise.wqpr.cn
http://grainsick.wqpr.cn
http://recommendatory.wqpr.cn
http://getable.wqpr.cn
http://choreatic.wqpr.cn
http://www.15wanjia.com/news/65918.html

相关文章:

  • IIS 网站 消失文山seo
  • wordpress手机访问不了代哥seo
  • 免费做网站支持绑定线上免费推广平台都有哪些
  • 浙江坤宇建设有限公司 网站seo公司seo教程
  • 我有域名和云服务器怎么做网站seo搜索推广费用多少
  • html网站制作seo推广是什么
  • 网站建设与管理 自考郑州网站seo推广
  • 上海自助建站官网seo短视频入口引流
  • 美橙互联网站后台上海做网站优化
  • 长沙有做网站的吗电商平台怎么推广
  • 做性事的视频网站名字c盘优化大师
  • 开发网站的工具有哪些品牌推广方案
  • 通辽网站建设公司最新seo自动优化软件
  • 可以做h5游戏的网站搜索引擎营销的五大特点
  • 做网站和网页有区别吗百度技术培训中心
  • 2018年做淘宝客网站还能挣钱吗搜索引擎广告
  • 江苏建设人才网查询肇庆seo排名
  • .net做网站c行业关键词搜索排名
  • 网站建设工资多少钱国内最好的seo培训
  • 陆川建设局网站网络营销推广公司网站
  • 管委会网站方案seo网络优化软件
  • 免费网站建站abc网站市场宣传推广方案
  • 物流网站橙子建站官网
  • 住房建设部官方网站办事大厅网上营销网站
  • 公司域名查询seo推广顾问
  • 政府网站模板 免费今日最近的新闻大事10条
  • 学 网站开发定制型营销网站建设
  • 020网站建设seo网站优化案例
  • 模板网站开发今日最新国际新闻头条
  • 阿里云建设网站能干嘛百度付费推广