00001 /* Copyright (C) 2002 Christopher Clark <firstname.lastname@cl.cam.ac.uk> */ 00002 00003 #include "hashtable.h" 00004 #include "hashtable_private.h" 00005 #include "hashtable_utility.h" 00006 #include <stdlib.h> 00007 #include <stdio.h> 00008 #include <string.h> 00009 #include "../MALLOC/includes/MALLOC.h" 00010 00011 /*****************************************************************************/ 00012 /* hashtable_change 00013 * 00014 * function to change the value associated with a key, where there already 00015 * exists a value bound to the key in the hashtable. 00016 * Source due to Holger Schemel. 00017 * 00018 * */ 00019 int 00020 hashtable_change(struct hashtable *h, void *k, void *v) 00021 { 00022 struct entry *e; 00023 unsigned int hashvalue, index_; 00024 hashvalue = hash(h,k); 00025 index_ = indexFor(h->tablelength,hashvalue); 00026 e = h->table[index_]; 00027 while (NULL != e) 00028 { 00029 /* Check hash value to short circuit heavier comparison */ 00030 if ((hashvalue == e->h) && (h->eqfn(k, e->k))) 00031 { 00032 FREE(e->v); 00033 e->v = v; 00034 return -1; 00035 } 00036 e = e->next; 00037 } 00038 return 0; 00039 } 00040 00041 /* 00042 * Copyright (c) 2002, Christopher Clark 00043 * All rights reserved. 00044 * 00045 * Redistribution and use in source and binary forms, with or without 00046 * modification, are permitted provided that the following conditions 00047 * are met: 00048 * 00049 * * Redistributions of source code must retain the above copyright 00050 * notice, this list of conditions and the following disclaimer. 00051 * 00052 * * Redistributions in binary form must reproduce the above copyright 00053 * notice, this list of conditions and the following disclaimer in the 00054 * documentation and/or other materials provided with the distribution. 00055 * 00056 * * Neither the name of the original author; nor the names of any contributors 00057 * may be used to endorse or promote products derived from this software 00058 * without specific prior written permission. 00059 * 00060 * 00061 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00062 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00063 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00064 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00065 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00066 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00067 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00068 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00069 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00070 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00071 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00072 */
1.5.5