- Change hash to speed up 16/32 bit lookups
authorBart Polot <bart@net.in.tum.de>
Fri, 10 May 2013 17:20:46 +0000 (17:20 +0000)
committerBart Polot <bart@net.in.tum.de>
Fri, 10 May 2013 17:20:46 +0000 (17:20 +0000)
src/mesh/gnunet-service-mesh-new.c
src/mesh/mesh2.h
src/mesh/mesh_common.c

index df078b542abff31d64c9fad59cdb91846688f07c..8c98d4a34ae2dc086e18f624fd5365b2ca1018b1 100644 (file)
@@ -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,
index eaf386fd8d792ed4ce81d03173758896d3c1308b..4b55c3c4e8fc882b51e6a8baa70c88871fd87a15 100644 (file)
@@ -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:
index c9af35c2258d9a29bc2ee1827e873632d52088b3..b4fc406720a5508c2e7567a615068402c2d838e1 100644 (file)
 #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 *