From 4bad1ea4a92d330db5ce5e563315de398a63ea21 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 3 Oct 2009 23:13:32 +0000 Subject: replace TAILQ with SLIST --- weasel.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/weasel.c b/weasel.c index f6b38ff..ef86a16 100644 --- a/weasel.c +++ b/weasel.c @@ -45,13 +45,13 @@ const char alphabet[] = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEEFGHIJKLMNOPQRST const char *aim; -TAILQ_HEAD(creatures, creature) generation; +SLIST_HEAD(creatures, creature) generation; struct creature { char *genom; int length; float fitness; int locked; - TAILQ_ENTRY(creature) link; + SLIST_ENTRY(creature) link; } *cp; char @@ -78,7 +78,7 @@ initpopulation(int length, int number) { int i; - TAILQ_INIT(&generation); + SLIST_INIT(&generation); while (number-- > 0) { cp = malloc(sizeof(struct creature)); @@ -91,7 +91,7 @@ initpopulation(int length, int number) cp->length = length; cp->fitness = calculatefitness(cp->genom, cp->length); cp->locked = 0; - TAILQ_INSERT_HEAD(&generation, cp, link); + SLIST_INSERT_HEAD(&generation, cp, link); } } @@ -105,7 +105,7 @@ void printpopulation(int maximal) { printw("%1.3f\t%s\n\n", 1.0, aim); - TAILQ_FOREACH(cp, &generation, link) { + SLIST_FOREACH(cp, &generation, link) { printcreature(cp); if (maximal-- <= 0) break; @@ -118,9 +118,9 @@ pickrandom(int population) { int n = arc4random() % population; - cp = TAILQ_FIRST(&generation); + cp = SLIST_FIRST(&generation); while (n-- > 0 && cp) - cp = TAILQ_NEXT(cp, link); + cp = SLIST_NEXT(cp, link); if (cp->locked) cp = pickrandom(population); @@ -173,7 +173,7 @@ success() float fittest = 0; /* find best */ - TAILQ_FOREACH(cp, &generation, link) + SLIST_FOREACH(cp, &generation, link) if (cp->fitness > fittest) { fittest = cp->fitness; best = cp; -- cgit v1.2.3