-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdslib.h
176 lines (142 loc) · 2.41 KB
/
dslib.h
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#ifndef dslib_h
#define dslib_h
#include <stdio.h>
#include <string.h>
// to support types with a * or a space
typedef char* charp ;
typedef int* intp;
typedef double* doublep;
typedef float* floatp;
typedef long* longp;
typedef long long long_long;
typedef long double long_double;
typedef short int short_int;
// comparators
int cmp_int(int a, int b)
{
if(a==b)
return 0;
else
return 1;
}
int cmp_short_int(short int a, short int b)
{
if(a==b)
return 0;
else
return 1;
}
int cmp_long(long a, long b)
{
if(a==b)
return 0;
else
return 1;
}
int cmp_long_long(long long a, long long b)
{
if(a==b)
return 0;
else
return 1;
}
int cmp_double(double a, double b)
{
if(a==b)
return 0;
else
return 1;
}
int cmp_long_double(long double a, long double b)
{
if(a==b)
return 0;
else
return 1;
}
int cmp_float(float a, float b)
{
if(a==b)
return 0;
else
return 1;
}
int cmp_char(char a, char b)
{
if(a==b)
return 0;
else
return 1;
}
int cmp_charp(char* a, char* b)
{
if(strcmp(a,b)==0)
return 0;
else
return 1;
}
/*
hash functions:
- can be modified to use efficient hashing algorithms
- new hash function must be created to allow different key types
*/
long hash_int(int key, long size)
{
return key%size;
}
long hash_short_int(short int key, long size)
{
return key%size;
}
long hash_double(double key, long size)
{
return ((long)key)%size;
}
long hash_long_double(long double key, long size)
{
return ((long)key)%size;
}
long hash_long(long key, long size)
{
return key%size;
}
long hash_long_long(long long key, long size)
{
return key%size;
}
long hash_float(float key, long size)
{
return ((long)key)%size;
}
long hash_char(char key, long size)
{
return ((int)key)%size;
}
long hash_charp(char* key, long size)
{
long res = 0;
long l = strlen(key);
long i;
for(i=0;i<l;i++)
{
res += (int)key[i];
}
return res%size;
}
#define Hash(type,key,size) \
hash_##type(key,size);
/* Common Functions , calls required function */
#define add(x,...) \
(x->dslib_insert)(x,__VA_ARGS__)
#define remove(x,y) \
(x->dslib_remove)(x,y)
#define getSize(x) \
(x->num_elements)
#define find(x,key) \
(x->dslib_search)(x,key)
#define free_ds(x) \
(x->dslib_free_ds)(x)
#include "dictionary.h"
#include "set.h"
#include "list.h"
#endif