From 8111ff97a31415c6ceaa49f2290e2da345ad276c Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 7 May 2008 17:01:16 +0200 Subject: [PATCH] src/sn_population.[ch]: Add `sn_population_best_rating'. --- src/sn_population.c | 22 ++++++++++++++++++++++ src/sn_population.h | 1 + 2 files changed, 23 insertions(+) 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 */ -- 2.11.0