src/sn_population.[ch]: Add `sn_population_best_rating'.
authorFlorian Forster <octo@leeloo.home.verplant.org>
Wed, 7 May 2008 15:01:16 +0000 (17:01 +0200)
committerFlorian Forster <octo@leeloo.home.verplant.org>
Wed, 7 May 2008 15:01:16 +0000 (17:01 +0200)
src/sn_population.c
src/sn_population.h

index 1147f06..11063e0 100644 (file)
@@ -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 : */
index b444e55..e7279da 100644 (file)
@@ -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 */