8dc7c730c04625451ce4e881d729bc5029d4a70a
[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,
28     pi_copy_f copy, pi_free_f f);
29 void population_destroy (population_t *p);
30
31 /*
32  * Object configuration
33  */
34 int population_set_size (population_t *p, size_t population_size);
35 int population_set_serialization (population_t *p,
36     pi_serialize_f serialize, pi_unserialize_f unserialize);
37
38 #define POPULATION_DEFAULT_PORT "46835"
39 int population_add_peer (population_t *p, const char *node, const char *port);
40 int population_start_listen_thread (population_t *p,
41     const char *node, const char *port);
42
43 /*
44  * Methods
45  */
46 /* iterations == 0  =>  infinite */
47 void *population_get_random (population_t *p);
48 void *population_get_fittest (population_t *p);
49
50 int population_insert (population_t *p, void *pi);
51
52 /* vim: set sw=2 sts=2 et : */
53 #endif /* POPULATION_H */