Index: client/attribute.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/attribute.c,v retrieving revision 1.11 diff -u -r1.11 attribute.c --- client/attribute.c 2002/05/25 17:44:05 1.11 +++ client/attribute.c 2002/06/07 13:26:36 @@ -11,7 +11,7 @@ #include "attribute.h" -#define ATTRIBUTE_LOG_LEVEL LOG_DEBUG +#define ATTRIBUTE_LOG_LEVEL LOG_NORMAL static struct hash_table *attribute_hash = NULL; @@ -25,9 +25,7 @@ static unsigned int attr_hash_val_fn(const void *key, unsigned int num_buckets) { - const struct attr_key *pkey = (const struct attr_key *) key; - - return (pkey->id ^ pkey->x ^ pkey->y ^ pkey->key) % num_buckets; + return 0; } /**************************************************************************** @@ -35,9 +33,28 @@ *****************************************************************************/ static int attr_hash_cmp_fn(const void *key1, const void *key2) { - return memcmp(key1, key2, sizeof(struct attr_key)); + int t; + const struct attr_key *pkey1 = (const struct attr_key *) key1; + const struct attr_key *pkey2 = (const struct attr_key *) key2; + + t = pkey1->key - pkey2->key; + if (t != 0) { + return t; + } + t = pkey1->id - pkey2->id; + if (t != 0) { + return t; + } + t = pkey1->x - pkey2->x; + if (t != 0) { + return t; + } + t = pkey1->y - pkey2->y; + if (t != 0) { + return t; + } + return 0; } - /**************************************************************************** ... *****************************************************************************/ @@ -259,7 +276,7 @@ if (data_length != 0) { pvalue = fc_malloc(data_length + sizeof(int)); ((int *) pvalue)[0] = data_length; - memcpy((char *)pvalue + sizeof(int), data, data_length); + memcpy(ADD_TO_POINTER(pvalue, sizeof(int)), data, data_length); } if (hash_key_exists(attribute_hash, pkey)) { @@ -301,6 +318,21 @@ if (!pvalue) { freelog(ATTRIBUTE_LOG_LEVEL, " not found"); + { + int i; + + for (i = 0; i < hash_num_entries(attribute_hash); i++) { + const struct attr_key *pkey = hash_key_by_number(attribute_hash, i); + + pvalue = hash_lookup_data(attribute_hash, pkey); + assert(pvalue != NULL); + length = ((int *) pvalue)[0]; + + freelog(LOG_NORMAL, + " [%d], key=(key=%d, id=%d, x=%d, y=%d) value_len=%d", i, + pkey->key, pkey->id, pkey->x, pkey->y, length); + } + } return 0; } @@ -320,7 +352,7 @@ exit(EXIT_FAILURE); } - memcpy(data, (char *)pvalue + sizeof(int), length); + memcpy(data, ADD_TO_POINTER(pvalue, sizeof(int)), length); freelog(ATTRIBUTE_LOG_LEVEL, " found length=%d", length); return length;