From: Bart Polot Date: Fri, 10 May 2013 17:20:46 +0000 (+0000) Subject: - Change hash to speed up 16/32 bit lookups X-Git-Tag: initial-import-from-subversion-38251~9083 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=018cab1259cd62ef3377203520e777fbdfdab646;p=oweals%2Fgnunet.git - Change hash to speed up 16/32 bit lookups --- diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c index df078b542..8c98d4a34 100644 --- a/src/mesh/gnunet-service-mesh-new.c +++ b/src/mesh/gnunet-service-mesh-new.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2001-2012 Christian Grothoff (and other contributing authors) + (C) 2001-2013 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -511,7 +511,8 @@ struct MeshClient struct GNUNET_SERVER_Client *handle; /** - * Messages that this client has declared interest in + * Messages that this client has declared interest in. + * Indexed by a GMC_hash32 (type), contains *Client. */ struct GNUNET_CONTAINER_MultiHashMap *types; @@ -1005,10 +1006,9 @@ client_get (struct GNUNET_SERVER_Client *client) * * @return GNUNET_YES or GNUNET_NO, depending on subscription status * - * FIXME: use of crypto_hash slows it down - * The hash function alone takes 8-10us out of the ~55us for the whole + * A real hash function alone takes 8-10us out of the ~55us for the whole * process of retransmitting the message from one local client to another. - * Find faster implementation! + * GMC_hash32 aim to imporve this speed. */ static int client_is_subscribed (uint16_t message_type, struct MeshClient *c) @@ -1018,7 +1018,7 @@ client_is_subscribed (uint16_t message_type, struct MeshClient *c) if (NULL == c->types) return GNUNET_NO; - GNUNET_CRYPTO_hash (&message_type, sizeof (uint16_t), &hc); + GMC_hash32 ((uint32_t) message_type, &hc); return GNUNET_CONTAINER_multihashmap_contains (c->types, &hc); } @@ -4654,7 +4654,7 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, { u16 = ntohs (t[i]); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " msg type: %u\n", u16); - GNUNET_CRYPTO_hash (&u16, sizeof (u16), &hc); // FIXME pseudo hash + GMC_hash32 ((uint32_t) u16, &hc); /* store in clients hashmap */ GNUNET_CONTAINER_multihashmap_put (c->types, &hc, c, diff --git a/src/mesh/mesh2.h b/src/mesh/mesh2.h index eaf386fd8..4b55c3c4e 100644 --- a/src/mesh/mesh2.h +++ b/src/mesh/mesh2.h @@ -318,6 +318,18 @@ uint32_t GMC_min_pid (uint32_t a, uint32_t b); +/** + * Expand a 32 bit value (message type) into a hash for a MultiHashMap (fast). + * WARNING: do not use for anything other than MultiHashMap! + * does not alter anything other than bits used by idx_of ! + * + * @param i 32 bit integer value. + * @param h Hash code to fill. + */ +void +GMC_hash32 (uint32_t i, struct GNUNET_HashCode *h); + + /** * Convert a message type into a string to help debug * Generated with: diff --git a/src/mesh/mesh_common.c b/src/mesh/mesh_common.c index c9af35c22..b4fc40672 100644 --- a/src/mesh/mesh_common.c +++ b/src/mesh/mesh_common.c @@ -27,14 +27,6 @@ #include "mesh.h" -/** - * Check if one pid is bigger than other, accounting for overflow. - * - * @param bigger Argument that should be bigger. - * @param smaller Argument that should be smaller. - * - * @return True if bigger (arg1) has a higher value than smaller (arg 2). - */ int GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller) { @@ -42,14 +34,7 @@ GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller) (bigger > smaller && GNUNET_NO == PID_OVERFLOW(bigger, smaller))); } -/** - * Get the higher ACK value out of two values, taking in account overflow. - * - * @param a First ACK value. - * @param b Second ACK value. - * - * @return Highest ACK value from the two. - */ + uint32_t GMC_max_pid (uint32_t a, uint32_t b) { @@ -59,14 +44,6 @@ GMC_max_pid (uint32_t a, uint32_t b) } -/** - * Get the lower ACK value out of two values, taking in account overflow. - * - * @param a First ACK value. - * @param b Second ACK value. - * - * @return Lowest ACK value from the two. - */ uint32_t GMC_min_pid (uint32_t a, uint32_t b) { @@ -75,6 +52,12 @@ GMC_min_pid (uint32_t a, uint32_t b) return a; } +void +GMC_hash32 (uint32_t i, struct GNUNET_HashCode *h) +{ + *(unsigned int *) h = i; +} + #if !defined(GNUNET_CULL_LOGGING) const char *