Merge branch 'ff/libpopulation'
[sort-networks.git] / src / sn_network.h
1 /**
2  * collectd - src/sn_network.h
3  * Copyright (C) 2008  Florian octo Forster
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  *
18  * Authors:
19  *   Florian octo Forster <octo at verplant.org>
20  **/
21
22 #ifndef SN_NETWORK_H
23 #define SN_NETWORK_H 1
24
25 #include <stdio.h>
26
27 #include "sn_comparator.h"
28 #include "sn_stage.h"
29
30 struct sn_network_s
31 {
32   int inputs_num;
33   sn_stage_t **stages;
34   int stages_num;
35 };
36 typedef struct sn_network_s sn_network_t;
37
38 #define SN_NETWORK_STAGE_NUM(n) (n)->stages_num
39 #define SN_NETWORK_STAGE_GET(n,i) ((n)->stages[i])
40 #define SN_NETWORK_INPUT_NUM(n) (n)->inputs_num
41
42 sn_network_t *sn_network_create (int inputs_num);
43 sn_network_t *sn_network_clone (const sn_network_t *n);
44 void sn_network_destroy (sn_network_t *n);
45
46 int sn_network_stage_add (sn_network_t *n, sn_stage_t *s);
47 int sn_network_stage_remove (sn_network_t *n, int s_num);
48
49 int sn_network_sort (sn_network_t *n, int *values);
50 int sn_network_brute_force_check (sn_network_t *n);
51
52 int sn_network_show (sn_network_t *n);
53 int sn_network_invert (sn_network_t *n);
54 int sn_network_compress (sn_network_t *n);
55 int sn_network_normalize (sn_network_t *n);
56
57 int sn_network_cut_at (sn_network_t *n, int input, enum sn_network_cut_dir_e dir);
58 sn_network_t *sn_network_combine (sn_network_t *n0, sn_network_t *n1);
59
60 sn_network_t *sn_network_read (FILE *fh);
61 sn_network_t *sn_network_read_file (const char *file);
62 int sn_network_write (sn_network_t *n, FILE *fh);
63 int sn_network_write_file (sn_network_t *n, const char *file);
64
65 int sn_network_serialize (sn_network_t *n, char **ret_buffer,
66     size_t *ret_buffer_size);
67 sn_network_t *sn_network_unserialize (char *buffer, size_t buffer_size);
68 #endif /* SN_NETWORK_H */
69
70 /* vim: set shiftwidth=2 softtabstop=2 : */