Repositories » libk0
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

freehash() for cleanup (not battle-tested).

Changeset 50f1d454b20b

Parent f0804ee3b290

by Rup Palchowdhury

Changes to 3 files · Browse files at 50f1d454b20b Showing diff from parent f0804ee3b290 Diff from another changeset...

Change 1 of 1 Show Entire File khash.c Stacked
 
17
18
19
 
 
 
 
 
 
 
20
21
22
 
17
18
19
20
21
22
23
24
25
26
27
28
29
@@ -17,6 +17,13 @@
  return h;  }   +void freehash(Hash *h, void (*freedata)(void*)) +{ + for (int i = 0; i < h->n; i++) + freelist(h->tab[i], freedata); + free(h); +} +  /* default hash function, assumes data to be char buffer */  unsigned hash(void *data, unsigned size)  {
Change 1 of 1 Show Entire File khash.h Stacked
 
8
9
10
 
11
12
13
 
8
9
10
11
12
13
14
@@ -8,6 +8,7 @@
 };    Hash *newhash(unsigned, fn_cmp, fn_hash); +void freehash(Hash*, void (*freedata)(void*));  Node *hlookup(Hash*, Node*, int);  unsigned hash(void*, unsigned);  void hstats(Hash*, unsigned);
Change 1 of 2 Show Entire File test.c Stacked
 
1
 
2
3
4
 
49
50
51
 
52
53
54
 
1
2
3
4
5
 
50
51
52
53
54
55
56
@@ -1,4 +1,5 @@
 #include <stdio.h> +#include <stdlib.h>  #include "kcommon.h"  #include "ktree.h"  #include "klist.h" @@ -49,6 +50,7 @@
  else   printf("Not found\n");   + freehash(h, free);     /* tree test */   /*