-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.h
More file actions
95 lines (83 loc) · 2.5 KB
/
Copy pathhash.h
File metadata and controls
95 lines (83 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#define Number 18278
typedef struct node
{
char word[46];
struct node *next;
}
node;
node *table[Number];
int hash(const char *word)
{
// Key is the same whether the first character is upper case or lower case
unsigned int key = 0, First_Letter_Index = 0, Second_Letter_Index = 0, Third_Letter_Index = 0;
// Calculate the length of the word that needs to be inserted in the hash table
int Word_Lengh = strlen(word);
if (Word_Lengh == 1)
{
if (65 <= word[0] && word[0] <= 90)
{
Third_Letter_Index = (word[0] - 65 + 1) % Number;
}
else if (97 <= word[0] && word[0] <= 122)
{
Third_Letter_Index = (word[0] - 97 + 1) % Number;
}
}
if (Word_Lengh == 2)
{
if (65 <= word[0] && word[0] <= 90)
{
Second_Letter_Index = (word[0] - 65 + 1) % Number;
}
else if (97 <= word[0] && word[0] <= 122)
{
Second_Letter_Index = (word[0] - 97 + 1) % Number;
}
/********************************************************/
if (65 <= word[1] && word[1] <= 90)
{
Third_Letter_Index = (word[1] - 65 + 1) % Number;
}
else if (97 <= word[1] && word[1] <= 122)
{
Third_Letter_Index = (word[1] - 97 + 1) % Number;
}
}
if (Word_Lengh >= 3)
{
if (65 <= word[0] && word[0] <= 90)
{
First_Letter_Index = (word[0] - 65 + 1) % Number;
}
else if (97 <= word[0] && word[0] <= 122)
{
First_Letter_Index = (word[0] - 97 + 1) % Number;
}
/********************************************************/
if (65 <= word[1] && word[1] <= 90)
{
Second_Letter_Index = (word[1] - 65 + 1) % Number;
}
else if (97 <= word[1] && word[1] <= 122)
{
Second_Letter_Index = (word[1] - 97 + 1) % Number;
}
/********************************************************/
if (65 <= word[2] && word[2] <= 90)
{
Third_Letter_Index = (word[2] - 65 + 1) % Number;
}
else if (97 <= word[2] && word[2] <= 122)
{
Third_Letter_Index = (word[2] - 97 + 1) % Number;
}
}
key = (First_Letter_Index * 26 * 26) + (Second_Letter_Index * 26) + (Third_Letter_Index * 1);
return (key - 1);
}