1 /*
2  * %CopyrightBegin%
3  *
4  * Copyright Ericsson AB 1998-2016. All Rights Reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * %CopyrightEnd%
19  *
20 
21  */
22 #include <stdlib.h>
23 #include "hash.h"
24 
25 /* remove all the key-values from a table. The
26  * values are removed with
27  * the user-provided function f.
28  */
ei_hash_freetab(ei_hash * tab,void (* f)(void *))29 int ei_hash_freetab(ei_hash *tab, void (*f)(void *))
30 {
31   ei_bucket *b, *next;
32   int i;
33 
34   for (i=0; i<tab->size; i++) {
35     b=tab->tab[i];
36     while (b) {
37       next = b->next;
38 
39       if (f) f((void *)b->value);
40 
41       /* no point in saving these buckets on freelist */
42       free(b);
43       b = next;
44     }
45   }
46 
47   /* remove the freelist */
48   b = tab->freelist;
49   while (b) {
50     next = b->next;
51     free(b);
52     b = next;
53   }
54 
55   /* remove the table */
56   free(tab);
57 
58   return 0;
59 }
60