diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-02-20 13:05:01 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-02-20 13:05:01 +0100 |
commit | 88a9a5beab50429901faf8f196e785f39f4da8d7 (patch) | |
tree | 96d601d1b573d3165ff5de96e96b919b879967f8 /src/util/container_multipeermap.c | |
parent | 2f685ab91bd689f835c97a265a978d2d45eab509 (diff) | |
download | gnunet-88a9a5beab50429901faf8f196e785f39f4da8d7.tar.gz gnunet-88a9a5beab50429901faf8f196e785f39f4da8d7.zip |
port hashmap fixes to other maps, investigated #4905, clearly no longer possible, closing that one
Diffstat (limited to 'src/util/container_multipeermap.c')
-rw-r--r-- | src/util/container_multipeermap.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/util/container_multipeermap.c b/src/util/container_multipeermap.c index 8fa23df72..613efc0a9 100644 --- a/src/util/container_multipeermap.c +++ b/src/util/container_multipeermap.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -200,8 +200,13 @@ GNUNET_CONTAINER_multipeermap_create (unsigned int len, | |||
200 | 200 | ||
201 | GNUNET_assert (len > 0); | 201 | GNUNET_assert (len > 0); |
202 | map = GNUNET_new (struct GNUNET_CONTAINER_MultiPeerMap); | 202 | map = GNUNET_new (struct GNUNET_CONTAINER_MultiPeerMap); |
203 | map->map = GNUNET_new_array (len, | 203 | map->map = GNUNET_malloc_large (len * |
204 | union MapEntry); | 204 | sizeof (union MapEntry)); |
205 | if (NULL == map->map) | ||
206 | { | ||
207 | GNUNET_free (map); | ||
208 | return NULL; | ||
209 | } | ||
205 | map->map_length = len; | 210 | map->map_length = len; |
206 | map->use_small_entries = do_not_copy_keys; | 211 | map->use_small_entries = do_not_copy_keys; |
207 | return map; | 212 | return map; |
@@ -493,7 +498,7 @@ GNUNET_CONTAINER_multipeermap_remove (struct GNUNET_CONTAINER_MultiPeerMap *map, | |||
493 | if (NULL == p) | 498 | if (NULL == p) |
494 | map->map[i].bme = bme->next; | 499 | map->map[i].bme = bme->next; |
495 | else | 500 | else |
496 | p->next = bme->next; | 501 | p->next = bme->next; |
497 | update_next_cache_bme (map, | 502 | update_next_cache_bme (map, |
498 | bme); | 503 | bme); |
499 | GNUNET_free (bme); | 504 | GNUNET_free (bme); |
@@ -685,18 +690,23 @@ grow (struct GNUNET_CONTAINER_MultiPeerMap *map) | |||
685 | unsigned int old_len; | 690 | unsigned int old_len; |
686 | unsigned int new_len; | 691 | unsigned int new_len; |
687 | unsigned int idx; | 692 | unsigned int idx; |
688 | unsigned int i; | ||
689 | |||
690 | map->modification_counter++; | ||
691 | 693 | ||
692 | old_map = map->map; | 694 | old_map = map->map; |
693 | old_len = map->map_length; | 695 | old_len = map->map_length; |
696 | GNUNET_assert (0 != old_len); | ||
694 | new_len = old_len * 2; | 697 | new_len = old_len * 2; |
695 | new_map = GNUNET_new_array (new_len, | 698 | if (0 == new_len) /* 2^31 * 2 == 0 */ |
696 | union MapEntry); | 699 | new_len = old_len; /* never use 0 */ |
700 | if (new_len == old_len) | ||
701 | return; /* nothing changed */ | ||
702 | new_map = GNUNET_malloc_large (new_len * | ||
703 | sizeof (union MapEntry)); | ||
704 | if (NULL == new_map) | ||
705 | return; /* grow not possible */ | ||
706 | map->modification_counter++; | ||
697 | map->map_length = new_len; | 707 | map->map_length = new_len; |
698 | map->map = new_map; | 708 | map->map = new_map; |
699 | for (i = 0; i < old_len; i++) | 709 | for (unsigned int i = 0; i < old_len; i++) |
700 | { | 710 | { |
701 | if (map->use_small_entries) | 711 | if (map->use_small_entries) |
702 | { | 712 | { |
@@ -829,7 +839,7 @@ GNUNET_CONTAINER_multipeermap_get_multiple (struct GNUNET_CONTAINER_MultiPeerMap | |||
829 | int count; | 839 | int count; |
830 | union MapEntry me; | 840 | union MapEntry me; |
831 | union MapEntry *ce; | 841 | union MapEntry *ce; |
832 | 842 | ||
833 | ce = &map->next_cache[map->next_cache_off]; | 843 | ce = &map->next_cache[map->next_cache_off]; |
834 | GNUNET_assert (++map->next_cache_off < NEXT_CACHE_SIZE); | 844 | GNUNET_assert (++map->next_cache_off < NEXT_CACHE_SIZE); |
835 | count = 0; | 845 | count = 0; |
@@ -903,7 +913,7 @@ GNUNET_CONTAINER_multipeermap_get_random (const struct GNUNET_CONTAINER_MultiPee | |||
903 | { | 913 | { |
904 | unsigned int off; | 914 | unsigned int off; |
905 | union MapEntry me; | 915 | union MapEntry me; |
906 | 916 | ||
907 | if (0 == map->size) | 917 | if (0 == map->size) |
908 | return 0; | 918 | return 0; |
909 | if (NULL == it) | 919 | if (NULL == it) |