X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/73d53de1c9a9a2b536522d0d2e04031276941caf..149933f19168c87b400c0e0e5583fbcef0859ce8:/src/xbt/dict_multi.c diff --git a/src/xbt/dict_multi.c b/src/xbt/dict_multi.c index b9a9d26faa..6db40206ca 100644 --- a/src/xbt/dict_multi.c +++ b/src/xbt/dict_multi.c @@ -2,247 +2,238 @@ /* dict_multi - dictionnaries of dictionnaries of ... of data */ -/* Authors: Martin Quinson */ -/* Copyright (C) 2003,2004 Martin Quinson. */ +/* Copyright (c) 2003-2005 Martin Quinson. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it - under the terms of the license (GNU LGPL) which comes with this package. */ + * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "gras_private.h" +#include "dict_private.h" -#include /* malloc() */ -#include /* strlen() */ +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(dict_multi,dict, "Dictionaries of multiple keys"); -/*####[ Multi dict functions ]##############################################*/ -/*###############################"##########################################*/ -/** - * gras_mutidict_set: +static void _free_dict(void*d) { + VERB1("free dict %p",d); + xbt_dict_free((xbt_dict_t*)&d); +} + +/** \brief Insert \e data under all the keys contained in \e keys, providing their sizes in \e lens. * - * @head: the head of dict - * @keycount: the number of the key - * @key: the key - * @data: the data to set - * @Returns: gras_error_t + * \arg mdict: the multi-dict + * \arg keys: dynar of (char *) containing all the keys + * \arg lens: length of each element of \e keys + * \arg data: what to store in the structure + * \arg free_ctn: function to use to free the pushed content on need * - * set the data in the structure under the @keycount @key. + * Dynars are not modified during the operation. */ -gras_error_t -gras_multidict_set_ext(gras_dict_t **pp_head, - int keycount, - char **key, - int *key_len, - void *data, - void_f_pvoid_t *free_ctn) { - gras_error_t errcode = no_error; - gras_dictelm_t *p_elm = NULL; - gras_dictelm_t *p_subdict = NULL; - int i = 0; - - CDEBUG2(dict_multi, "fast_multidict_set(%p,%d). Keys:", *pp_head, keycount); - - /* - for (i = 0; i < keycount; i++) { - CDEBUG1(dict_multi, "\"%s\"", key[i]); - } - */ - - gras_assert0(keycount >= 1, "Can't set less than one key in a multidict"); - - if (keycount == 1) - return gras_dict_set_ext(pp_head, key[0], key_len[0], data, free_ctn); - - if (!*pp_head) { - TRY(_gras_dict_alloc(NULL, 0, 0, NULL, NULL, pp_head)); - } - - p_elm = *pp_head; - - for (i = 0; i < keycount-1; i++) { +void +xbt_multidict_set_ext(xbt_dict_t mdict, + xbt_dynar_t keys, xbt_dynar_t lens, + void *data, void_f_pvoid_t *free_ctn) { + + xbt_ex_t e; + xbt_dict_t thislevel,nextlevel=NULL; + int i; + + unsigned long int thislen; + char *thiskey; + int keys_len=xbt_dynar_length(keys); + + xbt_assert(xbt_dynar_length(keys) == xbt_dynar_length(lens)); + xbt_assert0(keys_len, "Can't set a zero-long key set in a multidict"); + + DEBUG2("xbt_multidict_set(%p,%d)", mdict, keys_len); + + for (i=0 , thislevel = mdict ; + i= 1, "Can't get a zero-long key set in a multidict"); + + DEBUG2("xbt_multidict_get(%p, %ld)", mdict, xbt_dynar_length(keys)); + + for (i=0 , thislevel=mdict ; + i