-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericHashTable.h
More file actions
107 lines (85 loc) · 3.59 KB
/
GenericHashTable.h
File metadata and controls
107 lines (85 loc) · 3.59 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
96
97
98
99
100
101
102
103
104
105
106
107
#define INT_TYPE 0
#define STR_TYPE 1
typedef struct Object
{
void *data;
struct Object *next;
} Object;
typedef struct Table
{
Object **arr;
int dataType, originalSize, currentSize, numOfMultiply, listLength;
} Table;
/**
* The function gets the original size and the type of the data in the table elements.
* it initializes the Table struct members.
* On success, the function returns a pointer to the new created Table, otherwise, it return NULL.
*/
Table *createTable(int size, int dType, int listLength);
/**
* The function release all the allocated members of struct Table.
*/
void freeTable(Table *table);
/**
* The function adds data to the hashtable (as described in the exe definition)
* On success, the function returns the array index of the added data, otherwise, it return -1.
*/
int add(Table *table, void *data);
/**
* The function removes the Object which its data equals to data, if there are more than one, it removes the first one.
* On success, the function returns the array index of the removed data, otherwise, it returns -1.
* -1 is also returned in the case where there is no such object.
*/
int removeObj(Table *table, void *data);
/**
* The function search for an object that its data is equal to data and returns a pointer to that object.
* If there is no such object or in a case of an error, NULL is returned.
*/
Object *search(Table *table, void *data);
/**
* The function print the table (the format is in the exe definition)
*/
void printTable(Table *table);
/**
* This function creates an object and return the pointer to it or NULL if there is some error.
*/
Object *createObject(void *data);
/**
* This function frees an object, the data of the object should also be freed.
*/
void freeObject(Object *obj, int type);
/**
* check the equality of the data of two objects. The implementation is different depending the type of the data.
* the function returns 0 if they are equal or some other value if they are not equal.
*/
int isEqual(int type, void *data1, void *data2);
/**
* returns the hash value of an integer, which is key mod origSize
*/
int intHashFun(int *key, int origSize);
/**
* returns the hash value of an string, which is m mod origSize, where m is the sum of the ascii value of all the
* character in key.
*/
int strHashFun(char *key, int origSize);
/**
* /-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/
* /-/-/-/-/-/-/-/ functions added by me /-/-/-/-/-/-/-/
* /-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/-/
*/
// recursive function, free root from memory data & pointers.
void freeRoot(Object *obj);
// functio to get the actualy section in table that needed, send to specific hash func and multiplay by table ratio.
int physicalIndex(Table *table, void *data);
// insert new object to specific section, gets the enterance of the section, sectionSize to not deviation, depth is the linked list length.
int insertToSection(Object **enterance, Object *obj, int sectionSize, int depth);
// recursive function, try to insert an object to specific root (calls from insertToSection func);
int insertToRoot(Object *root, Object *obj, int depth);
// multiply table size by 2, updates the relevant values at table
void multiplyTable(Table *table);
// recursive function, print root from head to tail
void printRoot(Object *obj, int dataType);
// recursive function, search an object with an equal "data", if finds, return a pointer to obj, otherwise return null
Object *searchInRoot(Object **root, void *data, int type);
//recursive function, delete an object with equal "data", return 1 if found otherwise return 0
int removeFromRoot(Object **root, void *data, int type);