5 #define HASH_TABLE_SIZE 11
7 struct hash_elt
*Table
[HASH_TABLE_SIZE
];
10 void free_elt(struct hash_elt
*elt
);
14 return (num
% HASH_TABLE_SIZE
);
17 void insert_song(int track_num
, char *title
, char *filename
)
20 struct hash_elt
*hash_list
;
21 struct hash_elt
*new_elt
;
24 new_elt
= (struct hash_elt
*) malloc(sizeof(struct hash_elt
));
27 new_elt
->track_num
= track_num
;
28 new_elt
->title
= (char *)strdup(title
);
29 new_elt
->filename
= (char *)strdup(filename
);
33 hash_value
= hash_fn(track_num
);
34 hash_list
= Table
[hash_value
];
35 if (hash_list
!= NULL
) {
36 while (hash_list
->next
!= NULL
) {
37 hash_list
= hash_list
->next
;
39 hash_list
->next
= new_elt
;
43 Table
[hash_value
] = new_elt
;
47 struct hash_elt
*get_song(int track_num
)
50 struct hash_elt
*hash_list
;
52 hash_value
= hash_fn(track_num
);
53 hash_list
= Table
[hash_value
];
55 while ((hash_list
->track_num
!= track_num
) &&
56 (hash_list
->next
!= NULL
)) {
57 hash_list
= hash_list
->next
;
59 if (hash_list
->track_num
== track_num
) {
71 void free_elt(struct hash_elt
*elt
)
75 if (elt
->next
!= NULL
) {
86 for (i
= 0; i
< HASH_TABLE_SIZE
; i
++) {
95 struct hash_elt
*hash_list
;
97 for (i
= 0; i
< HASH_TABLE_SIZE
; i
++) {
100 while (hash_list
!= NULL
) {
102 hash_list
->track_num
,
104 hash_list
= hash_list
->next
;