当前位置:网站首页>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
边栏推荐
- 二叉树的遍历方式主要有:先序遍历、中序遍历、后序遍历、层次遍历。先序、中序、后序其实指的是父节点被访问的次序。若在遍历过程中,父节点先于它的子节点被访问,就是先序遍历;
- HUSTPC2022
- C language exercises - (array)
- 编译原理课程实践——实现一个初等函数运算语言的解释器或编译器
- TiDB 软件和硬件环境建议配置
- Deploy tidb cluster with tiup
- C # delay, start the timer in the thread, and obtain the system time
- Practical debugging skills
- . Net core logging system
- 可视化搭建页面工具的前世今生
猜你喜欢
随机推荐
[C language] explain the initial and advanced levels of the pointer and points for attention (1)
Apprendre le Code de la méthode de conversion du calendrier lunaire grégorien en utilisant PHP
Why can't programmers who can only program become excellent developers?
实用调试技巧
Practical debugging skills
List集合&UML图
C语言习题---(数组)
LeetCode 2310. The number of digits is the sum of integers of K
05_队列
Li Chuang EDA learning notes 15: draw border or import border (DXF file)
LeetCode - 搜索二维矩阵
【C语音】详解指针进阶和注意点(2)
XML配置文件
03_ Linear table_ Linked list
02_线性表_顺序表
06_栈和队列转换
Slashgear shares 2021 life changing technology products, which are somewhat unexpected
MathML to latex
Solve the problem that El radio group cannot be edited after echo
表格响应式布局小技巧



![[noi simulation] Elis (greedy, simulation)](/img/a2/f8c8ab3bc8dd779327be3f76990976.png)





