From: Florian Forster Date: Wed, 7 May 2008 15:01:16 +0000 (+0200) Subject: src/sn_population.[ch]: Add `sn_population_best_rating'. X-Git-Tag: v1.0.0~108 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8111ff97a31415c6ceaa49f2290e2da345ad276c;p=sort-networks.git src/sn_population.[ch]: Add `sn_population_best_rating'. --- diff --git a/src/sn_population.c b/src/sn_population.c index 1147f06..11063e0 100644 --- a/src/sn_population.c +++ b/src/sn_population.c @@ -201,4 +201,26 @@ sn_network_t *sn_population_best (sn_population_t *p) return (n_copy); } /* sn_network_t *sn_population_best */ +int sn_population_best_rating (sn_population_t *p) +{ + uint32_t i; + int rating = -1; + + pthread_mutex_lock (&p->lock); + + if (p->networks_num <= 0) + { + pthread_mutex_unlock (&p->lock); + return (-1); + } + + for (i = 0; i < p->networks_num; i++) + if ((p->ratings[i] < rating) || (rating < 0)) + rating = p->ratings[i]; + + pthread_mutex_unlock (&p->lock); + + return (rating); +} /* int sn_population_best_rating */ + /* vim: set shiftwidth=2 softtabstop=2 : */ diff --git a/src/sn_population.h b/src/sn_population.h index b444e55..e7279da 100644 --- a/src/sn_population.h +++ b/src/sn_population.h @@ -35,5 +35,6 @@ int sn_population_push (sn_population_t *p, sn_network_t *n); sn_network_t *sn_population_pop (sn_population_t *p); sn_network_t *sn_population_best (sn_population_t *p); +int sn_population_best_rating (sn_population_t *p); #endif /* SN_POPULATION_H */