当前位置:网站首页>07_ Hash
07_ Hash
2022-07-02 15:13:00 【Listen to the rain】
Hash
What is hash :
Hash :hash; It's a hash function
1 Hash conflicting 4 Method of disposal :
- 1. Open addressing : Also called linear detection ;
The disadvantage of one detection is that the data will be concentrated in one piece , The solution is square detection ( Second detection ), Avoid stacking
Positive numbers : Represents right probe
negative : Represents left probe
2. Hash function again ( Hash ) Law :
3. Chain address :
As long as there is data conflict, the header is inserted under the same subscriptPublic spill area law :
A basic table , An overflow table ; Put the conflicting data into the overflow table .
The disadvantage is when the data is too large , The basic table is too small , The specification of overflow table will be very large
2 Chained hash
Structure definition :
#define HASHSIZE 12
typedef struct Node
{
int data;
struct Node* next;
}Node, * PNode;
typedef struct Head
{
//struct Node *arr[HASHSIZE];// Pointer array ( An array of pointers )
struct Node arr[HASHSIZE];// Array arr In the store Node In itself
}Head, * PHead;
API Realization
void Init_listhash(PHead ph)
{
//assert
for (int i = 0; i < HASHSIZE; i++)
{
//ph->arr[i].data;// Don't use
ph->arr[i].next = NULL;
}
}
bool Insert_hash(PHead ph, int key)// Head insertion
{
int hash = key % HASHSIZE;
// Create a new node
struct Node* pnewnode = (Node*)malloc(sizeof(Node) * 1);
assert(pnewnode != NULL);
pnewnode->data = key;
// Insert
pnewnode->next = ph->arr[hash].next;
ph->arr[hash].next = pnewnode;
return true;
}
bool Del_Hash(PHead ph, int key)
{
int hash = key % HASHSIZE;
struct Node* p = &ph->arr[hash];
for (p; p->next != NULL; p = p->next)
{
if (p->next->data == key)
{
// here p->next The node pointed to is the node we want to delete
struct Node* q = p->next;
p->next = q->next;
free(q);
q = NULL;
return true;
}
}
return false;
}
struct Node* Search(PHead ph, int key)
{
int hash = key % HASHSIZE;
struct Node* p = ph->arr[hash].next;
for (p; p != NULL; p = p->next)
{
if (p->data == key)
{
return p;
}
}
return NULL;
}
void Show_Hash(PHead ph)
{
for (int i = 0; i < HASHSIZE; i++)
{
printf("%3d: ", i);
struct Node* p = ph->arr[i].next;
for (p; p != NULL; p = p->next)
{
printf("%d ", p->data);
}
printf("\n");
}
}
3 Consistent hashes and virtual nodes
边栏推荐
- MFC 控制台打印,弹出对话框
- Why can't programmers who can only program become excellent developers?
- Record an interview
- Li Chuang EDA learning notes 15: draw border or import border (DXF file)
- Base64 coding can be understood this way
- Kibana basic operation
- Kityformula editor configure font size and spacing
- It's no exaggeration to say that this is the most user-friendly basic tutorial of pytest I've ever seen
- IE 浏览器正式退休
- 为什么只会编程的程序员无法成为优秀的开发者?
猜你喜欢
About text selection in web pages and counting the length of selected text
02_线性表_顺序表
编译原理课程实践——实现一个初等函数运算语言的解释器或编译器
MathML to latex
[C language] explain the initial and advanced levels of the pointer and points for attention (1)
vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
17_Redis_Redis发布订阅
List集合&UML图
Kityformula editor configure font size and spacing
你不知道的Set集合
随机推荐
MFC 定时器使用
Set set you don't know
SQL 后计算的利器 SPL
Edit the formula with MathType, and set it to include only mathjax syntax when copying and pasting
Table responsive layout tips
Points clés de l'examen de principe de compilation pour l'année scolaire 2021 - 2022 [Université chinoise d'outre - mer]
How does CTO help the business?
电脑怎么设置扬声器播放麦克风的声音
使用 TiUP 部署 TiDB 集群
TiDB 集群最小部署的拓扑架构
Map介绍
CTO如何帮助业务?
How to write sensor data into computer database
LeetCode 2310. The number of digits is the sum of integers of K
华为面试题: 没有回文串
2021-2022學年編譯原理考試重點[華僑大學]
可视化搭建页面工具的前世今生
07_哈希
C code audit practice + pre knowledge
Mfc a dialog calls B dialog function and passes parameters