3 #define HASH_TABLE_SIZE 11
5 struct hash_elt
*Table
[HASH_TABLE_SIZE
];
8 void free_elt(struct hash_elt
*elt
);
12 return (num
% HASH_TABLE_SIZE
);
15 void insert_song(int track_num
, char *title
, char *filename
)
18 struct hash_elt
*hash_list
;
19 struct hash_elt
*new_elt
;
22 new_elt
= (struct hash_elt
*) malloc(sizeof(struct hash_elt
));
25 new_elt
->track_num
= track_num
;
26 new_elt
->title
= (char *)strdup(title
);
27 new_elt
->filename
= (char *)strdup(filename
);
31 hash_value
= hash_fn(track_num
);
32 hash_list
= Table
[hash_value
];
33 if (hash_list
!= NULL
) {
34 while (hash_list
->next
!= NULL
) {
35 hash_list
= hash_list
->next
;
37 hash_list
->next
= new_elt
;
41 Table
[hash_value
] = new_elt
;
45 struct hash_elt
*get_song(int track_num
)
48 struct hash_elt
*hash_list
;
50 hash_value
= hash_fn(track_num
);
51 hash_list
= Table
[hash_value
];
53 while ((hash_list
->track_num
!= track_num
) &&
54 (hash_list
->next
!= NULL
)) {
55 hash_list
= hash_list
->next
;
57 if (hash_list
->track_num
== track_num
) {
69 void free_elt(struct hash_elt
*elt
)
73 if (elt
->next
!= NULL
) {
84 for (i
= 0; i
< HASH_TABLE_SIZE
; i
++) {
93 struct hash_elt
*hash_list
;
95 for (i
= 0; i
< HASH_TABLE_SIZE
; i
++) {
98 while (hash_list
!= NULL
) {
100 hash_list
->track_num
,
102 hash_list
= hash_list
->next
;