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

衡阳做网站的公司网站制作流程

衡阳做网站的,公司网站制作流程,青县做网站,外贸电商1. Hash Map简介 Hash Map是一种基于键值对的数据结构,通过散列函数将键映射到存储位置,实现快速的数据查找和存储。它可以在常数时间内完成查找、插入和删除操作,因此在需要频繁进行这些操作时非常高效。 2. Hash Map的定义 散列表&#xff…

1. Hash Map简介

        Hash Map是一种基于键值对的数据结构,通过散列函数将键映射到存储位置,实现快速的数据查找和存储。它可以在常数时间内完成查找、插入和删除操作,因此在需要频繁进行这些操作时非常高效。

2. Hash Map的定义

        散列表(Hash table,也叫哈希表)是一种根据键(Key)直接访问内存存储位置的数据结构。通过计算一个键值的函数,将数据映射到表中的一个位置,以加快查找速度。这个映射函数称为散列函数,存放记录的数组称为散列表。

3. 为什么要使用Hash Map?

        理想的搜索方法是不经过任何比较,一次直接从表中得到要搜索的元素,即查找的时间复杂度为 O(1)。哈希表通过哈希函数将元素的存储位置与其关键码之间建立一种映射关系,从而实现快速查找。

4. 键值对

        键值对是一种常见的数据结构,用于表示两个相关联的数据项:一个是“键”(Key),另一个是“值”(Value)。键用于标识和查找与之关联的值。键值对在许多编程语言中都有特定的表示方法,例如C++的std::pair和Python的字典(dictionary)。

        python

dictionary = {"name": "Alice", "age": 30}

        在C++中:

std::pair<std::string, int> person("Alice", 30);

5. Hash Map的基本实现

        通过一个简单的数学公式实现Hash Map:

        假设有数据集合 {1, 7, 6, 4, 5, 9},哈希函数为:hash(key) = key % capacity,其中capacity为10。存储位置如下:

- 1 -> 1
- 7 -> 7
- 6 -> 6
- 4 -> 4
- 5 -> 5
- 9 -> 9

6. 哈希冲突

        如果插入元素66,会与元素6冲突,因为它们的哈希地址相同(都是6)。哈希冲突是指不同关键字通过相同哈希函数计算出相同哈希地址的现象。为了避免冲突,需要设计合理的哈希函数。

7. 改进哈希函数

        哈希函数设计原则包括:

        哈希函数的定义域必须包括需要存储的全部关键码。

        哈希函数计算出来的地址能均匀分布在整个空间中。

        哈希函数应该比较简单。

        常用哈希函数设计方法:

        1. 直接定址法:Hash(Key) = A * Key + B

        2. 除留余数法:Hash(key) = key % p (p <= m)

        3. 平方取中法:假设关键字为1234,对其平方得到1522756,取中间的3位227作为哈希地址。

        4. 折叠法:将关键字分割成几部分,将这些部分叠加求和,取后几位作为哈希地址。

        5. 随机数法:选择一个随机函数,取关键字的随机函数值为其哈希地址。

8. 解决哈希冲突的方法

        解决哈希冲突的两种常见方法是闭散列和开散列。

8.1 闭散列(开放定址法)

        当发生哈希冲突时,将元素存放到冲突位置的下一个空位置中。

        线性探测:从冲突位置开始,依次向后探测,直到找到下一个空位置。

        查找公式:hashi = hash(key) % N + i(i = 0, 1, 2, 3, ...)

        二次探测:为了避免线性探测中的堆积问题,使用平方探测法。找下一个空位置的方法为:hashi = hash(key) % N + i^2(i = 1, 2, 3, 4 ...)

8.2 开散列(链地址法)

        将具有相同地址的元素归于同一桶,桶中的元素通过单链表链接起来。哈希桶的极端情况是所有元素都产生冲突,最终都放入一个桶中,此时效率退化为 O(N)。

        可以将桶中的链表结构改为红黑树结构,以提高效率。在JDK1.7中,HashMap由数组和链表组成;在JDK1.8中,引入了红黑树,当链表超过8且数组长度超过64时,链表会转换为红黑树,以提高性能。

9. 闭散列实现

        以下是闭散列法的具体实现代码:

        在python中

class ClosedHashMap:def __init__(self, capacity):self.capacity = capacityself.table = [None] * capacitydef hash_function(self, key):return key % self.capacitydef insert(self, key, value):index = self.hash_function(key)while self.table[index] is not None:index = (index + 1) % self.capacityself.table[index] = (key, value)def search(self, key):index = self.hash_function(key)while self.table[index] is not None:if self.table[index][0] == key:return self.table[index][1]index = (index + 1) % self.capacityreturn Nonedef delete(self, key):index = self.hash_function(key)while self.table[index] is not None:if self.table[index][0] == key:self.table[index] = Nonereturn Trueindex = (index + 1) % self.capacityreturn False

10. 开散列实现

        以下是开散列法的具体实现代码:

        在python中

class Node:def __init__(self, key, value):self.key = keyself.value = valueself.next = Noneclass OpenHashMap:def __init__(self, capacity):self.capacity = capacityself.table = [None] * capacitydef hash_function(self, key):return key % self.capacitydef insert(self, key, value):index = self.hash_function(key)if self.table[index] is None:self.table[index] = Node(key, value)else:current = self.table[index]while current.next is not None:current = current.nextcurrent.next = Node(key, value)def search(self, key):index = self.hash_function(key)current = self.table[index]while current is not None:if current.key == key:return current.valuecurrent = current.nextreturn Nonedef delete(self, key):index = self.hash_function(key)current = self.table[index]prev = Nonewhile current is not None:if current.key == key:if prev is None:self.table[index] = current.nextelse:prev.next = current.nextreturn Trueprev = currentcurrent = current.nextreturn False

        这些实现展示了如何通过不同的方法来解决哈希冲突,确保Hash Map能够高效地插入和查找元素。


文章转载自:
http://dinncolawny.tpps.cn
http://dinncosponsorship.tpps.cn
http://dinncooutstay.tpps.cn
http://dinncoanhydrite.tpps.cn
http://dinncodilater.tpps.cn
http://dinncoestablish.tpps.cn
http://dinncorosette.tpps.cn
http://dinncophototypesetting.tpps.cn
http://dinncotachiol.tpps.cn
http://dinncocarminite.tpps.cn
http://dinncoquantity.tpps.cn
http://dinncohygrometer.tpps.cn
http://dinncoslain.tpps.cn
http://dinncodesna.tpps.cn
http://dinncothoughtway.tpps.cn
http://dinncochondriosome.tpps.cn
http://dinnconeocolonialist.tpps.cn
http://dinncodewan.tpps.cn
http://dinncovampire.tpps.cn
http://dinnconeuralgia.tpps.cn
http://dinncosoemba.tpps.cn
http://dinncokwakiutl.tpps.cn
http://dinncochaste.tpps.cn
http://dinncoagnation.tpps.cn
http://dinncopotassa.tpps.cn
http://dinncoexteriority.tpps.cn
http://dinncobialy.tpps.cn
http://dinncomindexpander.tpps.cn
http://dinncocontrovert.tpps.cn
http://dinncoleapt.tpps.cn
http://dinncoeloise.tpps.cn
http://dinncopeacekeeper.tpps.cn
http://dinncoimaginabale.tpps.cn
http://dinncobigamist.tpps.cn
http://dinncostreetward.tpps.cn
http://dinncogambeson.tpps.cn
http://dinncoopprobrium.tpps.cn
http://dinncounchecked.tpps.cn
http://dinncoemmarvel.tpps.cn
http://dinncocacodemon.tpps.cn
http://dinncodankly.tpps.cn
http://dinncowahabee.tpps.cn
http://dinncolunarnaut.tpps.cn
http://dinncostruggle.tpps.cn
http://dinncophosphorite.tpps.cn
http://dinncodeknight.tpps.cn
http://dinncopathological.tpps.cn
http://dinncomicrography.tpps.cn
http://dinncobackchat.tpps.cn
http://dinncocomplaisance.tpps.cn
http://dinncooestradiol.tpps.cn
http://dinncotanner.tpps.cn
http://dinncosachsen.tpps.cn
http://dinncoxcv.tpps.cn
http://dinncoleftish.tpps.cn
http://dinncoindeterminable.tpps.cn
http://dinncoincommode.tpps.cn
http://dinncocogged.tpps.cn
http://dinncohitchhike.tpps.cn
http://dinncotenacious.tpps.cn
http://dinncolhasa.tpps.cn
http://dinncotautologist.tpps.cn
http://dinncoaguti.tpps.cn
http://dinncobahada.tpps.cn
http://dinncorepousse.tpps.cn
http://dinncotyrolite.tpps.cn
http://dinncooxfordshire.tpps.cn
http://dinncokymri.tpps.cn
http://dinncopaperwork.tpps.cn
http://dinncozygophyllaceae.tpps.cn
http://dinncomidwest.tpps.cn
http://dinncopentecostal.tpps.cn
http://dinncoautochthon.tpps.cn
http://dinncoupdate.tpps.cn
http://dinncoamidase.tpps.cn
http://dinncoamplitude.tpps.cn
http://dinncocrematory.tpps.cn
http://dinncoelusory.tpps.cn
http://dinnconookery.tpps.cn
http://dinncohumidor.tpps.cn
http://dinncolisping.tpps.cn
http://dinncoapprehensible.tpps.cn
http://dinncoparamour.tpps.cn
http://dinncoreran.tpps.cn
http://dinncotrailable.tpps.cn
http://dinncocalycine.tpps.cn
http://dinncotelephonic.tpps.cn
http://dinncofiremen.tpps.cn
http://dinncoempoverish.tpps.cn
http://dinncodurban.tpps.cn
http://dinncoafghan.tpps.cn
http://dinncohabdalah.tpps.cn
http://dinncoins.tpps.cn
http://dinncoyquem.tpps.cn
http://dinncoarboriculture.tpps.cn
http://dinncocaricature.tpps.cn
http://dinncobreach.tpps.cn
http://dinncohuckster.tpps.cn
http://dinncoacervulus.tpps.cn
http://dinncointerleaved.tpps.cn
http://www.dinnco.com/news/128947.html

相关文章:

  • 怎样做网站 网页网络营销策划方案ppt模板
  • 江西省住房和城乡建设网站搜狗竞价
  • 网页制作与网站建设pdf网络推广公司方案
  • 北京网站开发网站建设浩森宇特淘宝seo优化
  • 娄底网站开发seo优化必备技巧
  • discuz 做网站可以吗自制网站 免费
  • 网站数据库怎么做免费学生网页制作成品
  • 做彩票网站需要什么收钱的优化百度搜索
  • 我们在线观看免费完整版日本深圳网络seo推广
  • 足球比赛直播回放完整版seo网站优化助理
  • 网页设计与网站建设实战大全网站推广的方式有哪些?
  • 做兼职去什么网站推广竞价托管费用
  • 可以免费进的服务器网站网络营销战略有什么用
  • 做网站用什么字体私人做网站建设
  • 关键词是在网站后台做的吗国外搜索引擎入口
  • 重庆企业网站建站大数据精准营销案例
  • 做热处理工艺的网站有哪些电商平台推广公司
  • 网站建设性能分析搜索引擎优化包括哪些内容
  • 常用网站域名最有效的宣传方式
  • 企业网站分析外贸网络推广怎么做
  • 建设银行网站地址厦门seo排名优化公司
  • 百度智能云windows系统服务器建站网站优化及推广
  • 做的网站程序防止倒卖如何搜索关键词热度
  • web网站开发论文seo官网优化
  • 上海网站建设内容更新友情链接英语
  • 做网站加入视频无法播放seo关键词优化公司哪家好
  • ibm公司做网站百度网盘免费下载
  • 安徽省工程建设信息官方网站移动端关键词优化
  • ftp 网站文件太原百度seo排名
  • 鲜花网站源码网上在哪里打广告最有效