type: improve handling of type promotion on binary operations
[smatch.git] / cwchash / hashtable_utility.c
blobc3176709775cedbd552e7c9c7e280ab0e184c012
1 /* Copyright (C) 2002 Christopher Clark <firstname.lastname@cl.cam.ac.uk> */
3 #include "hashtable.h"
4 #include "hashtable_private.h"
5 #include "hashtable_utility.h"
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h>
10 /*****************************************************************************/
11 /* hashtable_change
13 * function to change the value associated with a key, where there already
14 * exists a value bound to the key in the hashtable.
15 * Source due to Holger Schemel.
17 * */
18 int
19 hashtable_change(struct hashtable *h, void *k, void *v)
21 struct entry *e;
22 unsigned int hashvalue, index;
23 hashvalue = hash(h,k);
24 index = indexFor(h->tablelength,hashvalue);
25 e = h->table[index];
26 while (NULL != e)
28 /* Check hash value to short circuit heavier comparison */
29 if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
31 free(e->v);
32 e->v = v;
33 return -1;
35 e = e->next;
37 return 0;
41 * Copyright (c) 2002, Christopher Clark
42 * All rights reserved.
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
48 * * Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
51 * * Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
55 * * Neither the name of the original author; nor the names of any contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
60 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
61 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
62 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
63 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
64 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
65 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
66 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
67 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
68 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
69 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
70 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.