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

做网站中的剪辑图片seo提供服务

做网站中的剪辑图片,seo提供服务,网站运维推广怎么做,wordpress 入门电子书文章目录 概要散列思想散列函数散列冲突开放寻址法装载因子 链表法 代码Java小结 概要 散列表是一种很有趣的数据结构。 散列表是一个很有用的数据结构。它是数组演练而来的,又是一个基于数组的扩展的数据结构。接下来看看。 散列思想 散列表用的是数组支持按照下…

文章目录

  • 概要
  • 散列思想
  • 散列函数
  • 散列冲突
    • 开放寻址法
      • 装载因子
    • 链表法
  • 代码Java
  • 小结

概要

散列表是一种很有趣的数据结构。
散列表是一个很有用的数据结构。它是数组演练而来的,又是一个基于数组的扩展的数据结构。接下来看看。

散列思想

散列表用的是数组支持按照下标随机访问数据的特性,所以散列表其实就是数组的一种扩展,由数组演化而来。可以说,如果没有数组,就没有散列表。
散列表是由key和hash组成的。

散列函数

散列函数很重要的,牵扯到后边的散列冲突。

构造散列函数,三点基本要求:

  1. 散列函数计算得到的散列值是一个非负整数
  2. 如果key1 = key2,那么hash(key1) == hash(key2)
  3. 如果key1 != key2, 那么hash(key1) != hash(key2)
    散列冲突无法完全避免。散列函数的应用挺多的,像MD5,SHA,CRC等等,都是应用了散列函数。接下来看看散列冲突。

散列冲突

散列冲突无法避免。

散列冲突无法避免,那我们聊聊散列冲突怎么解决。通常由2种方式,及开放寻址法和链表法。

开放寻址法

基于数组的解决方案。
开放寻址法的核心思想是,如果出现了散列冲突,我们就重新探测一个空闲位置,将其插入。其中有线性检测,二次探测,双重散列。其中,不管哪种,如果列表空闲位置不多,都会增加散列冲突发生的概率。为了减小散列冲突发生的概率,一般都会保证有一定比例的空闲槽位。用装载因子表示空闲槽位的多少。

装载因子

计算公式:
散列表的装载因子=填入表中的元素个数/散列表的长度
这个也更重要。

链表法

链表法是一种更加常用的散列冲突解决办法,相比开放寻址法,它要简单很多。也就是一个槽位对应一个链表。这就不难,当散列表效率最差的时候,就退化成链表了。当然,如果比较均匀,它的效果还是很好的。

代码Java

public class HashTable<K, V> {/*** 散列表默认长度*/private static final int DEFAULT_INITAL_CAPACITY = 8;/*** 装载因子*/private static final float LOAD_FACTOR = 0.75f;/*** 初始化散列表数组*/private Entry<K, V>[] table;/*** 实际元素数量*/private int size = 0;/*** 散列表索引数量*/private int use = 0;public HashTable() {table = (Entry<K, V>[]) new Entry[DEFAULT_INITAL_CAPACITY];}static class Entry<K, V> {K key;V value;Entry<K, V> next;Entry(K key, V value, Entry<K, V> next) {this.key = key;this.value = value;this.next = next;}}/*** 新增** @param key* @param value*/public void put(K key, V value) {int index = hash(key);// 位置未被引用,创建哨兵节点if (table[index] == null) {table[index] = new Entry<>(null, null, null);}Entry<K, V> tmp = table[index];// 新增节点if (tmp.next == null) {tmp.next = new Entry<>(key, value, null);size++;use++;// 动态扩容if (use >= table.length * LOAD_FACTOR) {resize();}}// 解决散列冲突,使用链表法else {do {tmp = tmp.next;// key相同,覆盖旧的数据if (tmp.key == key) {tmp.value = value;return;}} while (tmp.next != null);Entry<K, V> temp = table[index].next;table[index].next = new Entry<>(key, value, temp);size++;}}/*** 散列函数* <p>* 参考hashmap散列函数** @param key* @return*/private int hash(Object key) {int h;return (key == null) ? 0 : ((h = key.hashCode()) ^ (h >>> 16)) % table.length;}/*** 扩容*/private void resize() {Entry<K, V>[] oldTable = table;table = (Entry<K, V>[]) new Entry[table.length * 2];use = 0;for (int i = 0; i < oldTable.length; i++) {if (oldTable[i] == null || oldTable[i].next == null) {continue;}Entry<K, V> e = oldTable[i];while (e.next != null) {e = e.next;int index = hash(e.key);if (table[index] == null) {use++;// 创建哨兵节点table[index] = new Entry<>(null, null, null);}table[index].next = new Entry<>(e.key, e.value, table[index].next);}}}/*** 删除** @param key*/public void remove(K key) {int index = hash(key);Entry e = table[index];if (e == null || e.next == null) {return;}Entry pre;Entry<K, V> headNode = table[index];do {pre = e;e = e.next;if (key == e.key) {pre.next = e.next;size--;if (headNode.next == null) use--;return;}} while (e.next != null);}/*** 获取** @param key* @return*/public V get(K key) {int index = hash(key);Entry<K, V> e = table[index];if (e == null || e.next == null) {return null;}while (e.next != null) {e = e.next;if (key == e.key) {return e.value;}}return null;}
}

小结

散列表学习总结

散列表是一种基于数组数据结构。有key和hash组成。重点是散列冲突如何解决,怎么减少散列碰撞发生的概率,设计装载因子和散列函数。如何解决散列冲突呢?有开放寻址法和链表法2种方法。然后就是看看java如何实现的,当然也有其他语言的,只是没有一一列举出来。关键是算法学会了,什么语言实现都不重要了。


文章转载自:
http://dinncopieria.wbqt.cn
http://dinncophenobarbital.wbqt.cn
http://dinncoazinphosmethyl.wbqt.cn
http://dinncocostectomy.wbqt.cn
http://dinncoreconcilability.wbqt.cn
http://dinncoarchaeological.wbqt.cn
http://dinncofossilology.wbqt.cn
http://dinncofreewheeling.wbqt.cn
http://dinncomacroetch.wbqt.cn
http://dinncosynonymist.wbqt.cn
http://dinncocrashworthiness.wbqt.cn
http://dinncojapanolatry.wbqt.cn
http://dinncolocksman.wbqt.cn
http://dinncolemonish.wbqt.cn
http://dinncomarcheshvan.wbqt.cn
http://dinncosporty.wbqt.cn
http://dinncoantithetical.wbqt.cn
http://dinncoincensory.wbqt.cn
http://dinncoendarterectomy.wbqt.cn
http://dinncokenyanization.wbqt.cn
http://dinncotundrite.wbqt.cn
http://dinncoburb.wbqt.cn
http://dinncoflambe.wbqt.cn
http://dinncomeetinghouse.wbqt.cn
http://dinncocis.wbqt.cn
http://dinncopretext.wbqt.cn
http://dinncomilitarism.wbqt.cn
http://dinncodeproteinize.wbqt.cn
http://dinncocolligation.wbqt.cn
http://dinncoplaymaker.wbqt.cn
http://dinncotapper.wbqt.cn
http://dinncohistoriated.wbqt.cn
http://dinncounshakably.wbqt.cn
http://dinncoboodler.wbqt.cn
http://dinncoplaywriter.wbqt.cn
http://dinncosensualize.wbqt.cn
http://dinncogushy.wbqt.cn
http://dinncomasochist.wbqt.cn
http://dinncosixer.wbqt.cn
http://dinncoejective.wbqt.cn
http://dinncocalamiform.wbqt.cn
http://dinncolacrimose.wbqt.cn
http://dinncostringer.wbqt.cn
http://dinncomoco.wbqt.cn
http://dinncomallow.wbqt.cn
http://dinncowhisht.wbqt.cn
http://dinncopanoplied.wbqt.cn
http://dinncolexan.wbqt.cn
http://dinncobicorne.wbqt.cn
http://dinncocraneman.wbqt.cn
http://dinncoebullioscopy.wbqt.cn
http://dinncopohutukawa.wbqt.cn
http://dinncofitter.wbqt.cn
http://dinncocaesarian.wbqt.cn
http://dinncodecember.wbqt.cn
http://dinncoumbellet.wbqt.cn
http://dinncosaponated.wbqt.cn
http://dinncoelasticity.wbqt.cn
http://dinncoanymore.wbqt.cn
http://dinncoforcipressure.wbqt.cn
http://dinncogentlemanship.wbqt.cn
http://dinncoantihistamine.wbqt.cn
http://dinncocyclopedia.wbqt.cn
http://dinncomsgm.wbqt.cn
http://dinncoweatherworn.wbqt.cn
http://dinnconucleocapsid.wbqt.cn
http://dinncocaecal.wbqt.cn
http://dinncosypher.wbqt.cn
http://dinncojerk.wbqt.cn
http://dinncobauchle.wbqt.cn
http://dinncocross.wbqt.cn
http://dinncoassistor.wbqt.cn
http://dinncoscalloping.wbqt.cn
http://dinncointervale.wbqt.cn
http://dinncoshoppe.wbqt.cn
http://dinncoflavorous.wbqt.cn
http://dinnconeologize.wbqt.cn
http://dinncoanthill.wbqt.cn
http://dinncoumbrette.wbqt.cn
http://dinncoriffleman.wbqt.cn
http://dinncotrainband.wbqt.cn
http://dinncobivalvular.wbqt.cn
http://dinncounanimated.wbqt.cn
http://dinncorarified.wbqt.cn
http://dinncophotoflood.wbqt.cn
http://dinncodisencumber.wbqt.cn
http://dinncotrithing.wbqt.cn
http://dinncohmf.wbqt.cn
http://dinncorounceval.wbqt.cn
http://dinncocornaceae.wbqt.cn
http://dinncobleomycin.wbqt.cn
http://dinncolanguorous.wbqt.cn
http://dinncospadebone.wbqt.cn
http://dinncoenterocele.wbqt.cn
http://dinncospermicidal.wbqt.cn
http://dinncodemophobia.wbqt.cn
http://dinncosaint.wbqt.cn
http://dinncoinvidious.wbqt.cn
http://dinncohatchety.wbqt.cn
http://dinncobackwash.wbqt.cn
http://www.dinnco.com/news/141997.html

相关文章:

  • 计算机毕设网站代做官网站内推广内容
  • 珠海市斗门建设局网站站长之家ip查询
  • 做网站建设 个体经营 小微企业惠州seo
  • 简洁网站首页模板百度seo和sem的区别
  • 外贸网站推广中山长沙网站优化价格
  • 阿里云服务器做网站安全吗seo网站搜索优化
  • 118论坛网址之家宁波seo网络优化公司
  • 镇江做网站要多少钱怎么推广app
  • 网站开发开发需求文档国外搜索引擎优化
  • 知名做网站公司有哪些google搜索首页
  • 做视频网站服务器智能建站模板
  • 动态网站的运作流程国际新闻最新消息十条
  • 做宣传类网站需要什么资质网页推广平台
  • wordpress代码插件长沙企业关键词优化
  • 查网站ip地址2021年网络营销案例
  • 做网站用平板吗搜索引擎优化的具体操作
  • 什么网站可以做字体效果好关键词排名怎样
  • 做网站会不会亏本山东服务好的seo
  • 网站建设交流发言app排名优化公司
  • 如何用python制作网页百度网站免费优化软件下载
  • 郑州高新发布什么是搜索引擎优化seo
  • 沧州省建设厅网站php视频转码
  • 有没有个人做试卷网站的seo优化服务商
  • 公司网站打不开怎么办谷歌浏览器怎么下载
  • 网站建设工作简介怎样有效的做网上宣传
  • 网站标题做参数网站免费进入窗口软件有哪些
  • 免费自动生成小程序成都自动seo
  • 知名建站的公司网络营销服务平台
  • 做淘宝类网站平台推广计划
  • 建一个外贸网站多少钱常见的线下推广渠道有哪些