-
Notifications
You must be signed in to change notification settings - Fork 0
/
hash.c
43 lines (39 loc) · 782 Bytes
/
hash.c
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
#include "hash.h"
#include <stdint.h>
#include <string.h>
#include <malloc.h>
void
hash_append( struct hash** hashHead,
struct hash* elem ) {
struct hash* cur = *hashHead ;
if( NULL == elem || NULL == hashHead ) {
return ;
}
//
if( NULL == cur ) { // Create new hash
*hashHead = elem ;
} else { // Append to end of existing hash
while( NULL != cur->next ) {
cur = cur->next ;
}
//
cur->next = elem ;
}
}
struct hash*
hash_find_by_key( struct hash* hashHead, uint32_t key ) {
struct hash* cur = hashHead ;
if( NULL == hashHead ) {
return NULL ;
}
//
while( NULL != cur ) {
if( key == cur->key ) {
return cur ;
}
//
cur = cur->next ;
}
//
return NULL ;
}