debuggers.hg

view tools/blktap2/drivers/hashtable_utility.c @ 22848:6341fe0f4e5a

Added tag 4.1.0-rc2 for changeset 9dca60d88c63
author Keir Fraser <keir@xen.org>
date Tue Jan 25 14:06:55 2011 +0000 (2011-01-25)
parents 9479190566fd
children
line source
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
12 *
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.
16 *
17 * */
18 int
19 hashtable_change(struct hashtable *h, void *k, void *v)
20 {
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)
27 {
28 /* Check hash value to short circuit heavier comparison */
29 if ((hashvalue == e->h) && (h->eqfn(k, e->k)))
30 {
31 free(e->v);
32 e->v = v;
33 return -1;
34 }
35 e = e->next;
36 }
37 return 0;
38 }
40 /*
41 * Copyright (c) 2002, Christopher Clark
42 * All rights reserved.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 *
48 * * Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 *
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.
54 *
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.
58 *
59 *
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.
71 */