Update copyright date and email address.
[sort-networks.git] / src / sn_network.h
1 /**
2  * collectd - src/sn_network.h
3  * Copyright (C) 2008-2010  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 <ff at octo.it>
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 sn_network_t *sn_network_create_odd_even_mergesort (int inputs_num);
47
48 int sn_network_stage_add (sn_network_t *n, sn_stage_t *s);
49 int sn_network_stage_remove (sn_network_t *n, int s_num);
50
51 int sn_network_comparator_add (sn_network_t *n, const sn_comparator_t *c);
52
53 int sn_network_get_comparator_num (const sn_network_t *n);
54
55 int sn_network_sort (sn_network_t *n, int *values);
56 int sn_network_brute_force_check (sn_network_t *n);
57
58 int sn_network_show (sn_network_t *n);
59 int sn_network_invert (sn_network_t *n);
60 int sn_network_shift (sn_network_t *n, int s);
61 int sn_network_compress (sn_network_t *n);
62 int sn_network_normalize (sn_network_t *n);
63
64 int sn_network_cut_at (sn_network_t *n, int input, enum sn_network_cut_dir_e dir);
65 sn_network_t *sn_network_combine (sn_network_t *n0, sn_network_t *n1,
66     int is_power_of_two);
67 sn_network_t *sn_network_combine_bitonic (sn_network_t *n0, sn_network_t *n1);
68 sn_network_t *sn_network_combine_odd_even_merge (sn_network_t *n0, sn_network_t *n1);
69
70 sn_network_t *sn_network_read (FILE *fh);
71 sn_network_t *sn_network_read_file (const char *file);
72 int sn_network_write (sn_network_t *n, FILE *fh);
73 int sn_network_write_file (sn_network_t *n, const char *file);
74
75 int sn_network_serialize (sn_network_t *n, char **ret_buffer,
76     size_t *ret_buffer_size);
77 sn_network_t *sn_network_unserialize (char *buffer, size_t buffer_size);
78 #endif /* SN_NETWORK_H */
79
80 /* vim: set shiftwidth=2 softtabstop=2 : */