diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-10-07 18:19:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-10-07 18:19:32 +0000 |
commit | a60b958f984d08525b636a2c7eae564ebec54ae6 (patch) | |
tree | 6dcbbf91d734834f804b2fd9ab790244e2d60e6c /src/util | |
parent | decf459805cdb3f6811f979df4831bc2ce9a2858 (diff) | |
download | gnunet-a60b958f984d08525b636a2c7eae564ebec54ae6.tar.gz gnunet-a60b958f984d08525b636a2c7eae564ebec54ae6.zip |
-chaning multihashmap API to allow option for avoiding key allocation
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/container_multihashmap.c | 12 | ||||
-rw-r--r-- | src/util/peer.c | 4 | ||||
-rw-r--r-- | src/util/test_container_multihashmap.c | 2 |
3 files changed, 14 insertions, 4 deletions
diff --git a/src/util/container_multihashmap.c b/src/util/container_multihashmap.c index ada98251c..4a41fd015 100644 --- a/src/util/container_multihashmap.c +++ b/src/util/container_multihashmap.c | |||
@@ -80,10 +80,20 @@ struct GNUNET_CONTAINER_MultiHashMap | |||
80 | * Create a multi hash map. | 80 | * Create a multi hash map. |
81 | * | 81 | * |
82 | * @param len initial size (map will grow as needed) | 82 | * @param len initial size (map will grow as needed) |
83 | * @param do_not_copy_keys GNUNET_NO is always safe and should be used by default; | ||
84 | * GNUNET_YES means that on 'put', the 'key' does not have | ||
85 | * to be copied as the destination of the pointer is | ||
86 | * guaranteed to be life as long as the value is stored in | ||
87 | * the hashmap. This can significantly reduce memory | ||
88 | * consumption, but of course is also a recipie for | ||
89 | * heap corruption if the assumption is not true. Only | ||
90 | * use this if (1) memory use is important in this case and | ||
91 | * (2) you have triple-checked that the invariant holds | ||
83 | * @return NULL on error | 92 | * @return NULL on error |
84 | */ | 93 | */ |
85 | struct GNUNET_CONTAINER_MultiHashMap * | 94 | struct GNUNET_CONTAINER_MultiHashMap * |
86 | GNUNET_CONTAINER_multihashmap_create (unsigned int len) | 95 | GNUNET_CONTAINER_multihashmap_create (unsigned int len, |
96 | int do_not_copy_keys) | ||
87 | { | 97 | { |
88 | struct GNUNET_CONTAINER_MultiHashMap *ret; | 98 | struct GNUNET_CONTAINER_MultiHashMap *ret; |
89 | 99 | ||
diff --git a/src/util/peer.c b/src/util/peer.c index 2444cb9f8..a0e965605 100644 --- a/src/util/peer.c +++ b/src/util/peer.c | |||
@@ -117,7 +117,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid) | |||
117 | if (pid == NULL) | 117 | if (pid == NULL) |
118 | return 0; | 118 | return 0; |
119 | if (NULL == map) | 119 | if (NULL == map) |
120 | map = GNUNET_CONTAINER_multihashmap_create (32); | 120 | map = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES); |
121 | off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); | 121 | off = (long) GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey); |
122 | e = (off == 0) ? NULL : &table[off]; | 122 | e = (off == 0) ? NULL : &table[off]; |
123 | if (e != NULL) | 123 | if (e != NULL) |
@@ -146,7 +146,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid) | |||
146 | table[ret].rc = 1; | 146 | table[ret].rc = 1; |
147 | table[ret].pid = ret; | 147 | table[ret].pid = ret; |
148 | GNUNET_break (GNUNET_OK == | 148 | GNUNET_break (GNUNET_OK == |
149 | GNUNET_CONTAINER_multihashmap_put (map, &pid->hashPubKey, | 149 | GNUNET_CONTAINER_multihashmap_put (map, &table[ret].id.hashPubKey, |
150 | (void *) (long) ret, | 150 | (void *) (long) ret, |
151 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 151 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
152 | return ret; | 152 | return ret; |
diff --git a/src/util/test_container_multihashmap.c b/src/util/test_container_multihashmap.c index befd0ce46..ff50df117 100644 --- a/src/util/test_container_multihashmap.c +++ b/src/util/test_container_multihashmap.c | |||
@@ -40,7 +40,7 @@ testMap (int i) | |||
40 | const char *ret; | 40 | const char *ret; |
41 | int j; | 41 | int j; |
42 | 42 | ||
43 | CHECK (NULL != (m = GNUNET_CONTAINER_multihashmap_create (i))); | 43 | CHECK (NULL != (m = GNUNET_CONTAINER_multihashmap_create (i, GNUNET_NO))); |
44 | memset (&k1, 0, sizeof (k1)); | 44 | memset (&k1, 0, sizeof (k1)); |
45 | memset (&k2, 1, sizeof (k2)); | 45 | memset (&k2, 1, sizeof (k2)); |
46 | CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (m, &k1)); | 46 | CHECK (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (m, &k1)); |