X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c882e24932c718fad85c22cb546f30e158f1b31d..4a6b0a991a67e6f2f67c03fed43529e078da7115:/examples/msg/chainsend/iterator.c?ds=sidebyside diff --git a/examples/msg/chainsend/iterator.c b/examples/msg/chainsend/iterator.c index 47dfe04fc4..2d0eccc271 100644 --- a/examples/msg/chainsend/iterator.c +++ b/examples/msg/chainsend/iterator.c @@ -1,27 +1,12 @@ -#include "iterator.h" - -/* http://stackoverflow.com/a/3348142 */ -static int rand_int(int n) -{ - int limit = RAND_MAX - RAND_MAX % n; - int rnd; +/* Copyright (c) 2012, 2014. The SimGrid Team. + * All rights reserved. */ - do { - rnd = rand(); - } while (rnd >= limit); - - return rnd % n; -} +/* 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. */ -void xbt_dynar_shuffle_in_place(xbt_dynar_t indices_list) -{ - int i, j; +#include "iterator.h" - for (i = xbt_dynar_length(indices_list) - 1; i > 0; i--) { - j = rand_int(i + 1); - xbt_dynar_swap_elements(indices_list, int, i, j); - } -} +/* http://stackoverflow.com/a/3348142 */ /**************************************/ /* Allocates and initializes a new xbt_dynar iterator for list, using criteria_fn as iteration criteria @@ -39,18 +24,6 @@ xbt_dynar_iterator_t xbt_dynar_iterator_new(xbt_dynar_t list, xbt_dynar_t (*crit return it; } -void xbt_dynar_iterator_reset(xbt_dynar_iterator_t it) -{ - xbt_dynar_free_container(&(it->indices_list)); - it->indices_list = it->criteria_fn(it->length); - it->current = 0; -} - -void xbt_dynar_iterator_seek(xbt_dynar_iterator_t it, int pos) -{ - it->current = pos; -} - /* Returns the next element iterated by iterator it, NULL if there are no more elements */ void *xbt_dynar_iterator_next(xbt_dynar_iterator_t it) { @@ -78,19 +51,3 @@ xbt_dynar_t forward_indices_list(int size) xbt_dynar_push_as(indices_list, int, i); return indices_list; } - -xbt_dynar_t reverse_indices_list(int size) -{ - xbt_dynar_t indices_list = xbt_dynar_new(sizeof(int), NULL); - int i; - for (i = size-1; i >= 0; i--) - xbt_dynar_push_as(indices_list, int, i); - return indices_list; -} - -xbt_dynar_t random_indices_list(int size) -{ - xbt_dynar_t indices_list = forward_indices_list(size); - xbt_dynar_shuffle_in_place(indices_list); - return indices_list; -}