64b3d8f7f6d59de76a10f832b68ff57936d97949
[libpopulation.git] / src / population.h
1 #ifndef POPULATION_H
2 #define POPULATION_H 1
3
4 #include <stdint.h>
5 #include <sys/types.h>
6
7 /*
8  * Callback function types
9  * (pi == population individual)
10  */
11 typedef int   (*pi_rate_f) (const void *);
12 typedef void *(*pi_copy_f) (const void *);
13 typedef void  (*pi_free_f) (void *);
14
15 typedef int   (*pi_serialize_f) (void *, char **, size_t *);
16 typedef void *(*pi_unserialize_f) (char *, size_t);
17
18 /*
19  * (Opaque) data types
20  */
21 struct population_s;
22 typedef struct population_s population_t;
23
24 /*
25  * Constructor and destructor
26  */
27 population_t *population_create (pi_rate_f rate, pi_copy_f copy, pi_free_f f);
28 void population_destroy (population_t *p);
29
30 /*
31  * Object configuration
32  */
33 int population_set_size (population_t *p, size_t population_size);
34 int population_set_serialization (population_t *p,
35     pi_serialize_f serialize, pi_unserialize_f unserialize);
36
37 #define POPULATION_DEFAULT_PORT "46835"
38 int population_add_peer (population_t *p, const char *node, const char *port);
39
40 /*
41  * Methods
42  */
43 /* iterations == 0  =>  infinite */
44 void *population_get_random (population_t *p);
45 void *population_get_fittest (population_t *p);
46
47 int population_insert (population_t *p, void *pi);
48
49 /* vim: set sw=2 sts=2 et : */
50 #endif /* POPULATION_H */