src/sn_{comparator,stage}.h: Add initial Doxygen stuff.
[sort-networks.git] / src / sn_stage.h
1 /**
2  * \file sn_stage.h
3  * \brief The sn_stage_t class and associated methods.
4  *
5  * \verbatim
6  * libsortnetwork - src/sn_stage.h
7  * Copyright (C) 2008-2010  Florian octo Forster
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by the
11  * Free Software Foundation; only version 2 of the License is applicable.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21  *
22  * Authors:
23  *   Florian octo Forster <ff at octo.it>
24  * \endverbatim
25  **/
26
27 #ifndef SN_STAGE_H
28 #define SN_STAGE_H 1
29
30 #include <stdio.h>
31
32 #include "sn_comparator.h"
33
34 struct sn_stage_s
35 {
36   int depth;
37   sn_comparator_t *comparators;
38   int comparators_num;
39 };
40 typedef struct sn_stage_s sn_stage_t;
41
42 enum sn_network_cut_dir_e
43 {
44   DIR_MIN,
45   DIR_MAX
46 };
47
48 #define SN_STAGE_DEPTH(s) (s)->depth
49 #define SN_STAGE_COMP_NUM(s) (s)->comparators_num
50 #define SN_STAGE_COMP_GET(s,n) ((s)->comparators + (n))
51
52 sn_stage_t *sn_stage_create (int depth);
53
54 /**
55  * Clones an existing stage.
56  *
57  * \param s Stage to clone.
58  * \return Copied stage or NULL on error. The returned stage must be freed
59  *   using sn_stage_destroy().
60  */
61 sn_stage_t *sn_stage_clone (const sn_stage_t *s);
62 void sn_stage_destroy (sn_stage_t *s);
63
64 int sn_stage_sort (sn_stage_t *s, int *values);
65
66 int sn_stage_comparator_add (sn_stage_t *s, const sn_comparator_t *c);
67 int sn_stage_comparator_remove (sn_stage_t *s, int c_num);
68 int sn_stage_comparator_check_conflict (sn_stage_t *s, const sn_comparator_t *c);
69
70 int sn_stage_show (sn_stage_t *s);
71 int sn_stage_invert (sn_stage_t *s);
72 int sn_stage_shift (sn_stage_t *s, int sw, int inputs_num);
73 int sn_stage_swap (sn_stage_t *s, int con0, int con1);
74 int sn_stage_cut_at (sn_stage_t *s, int input, enum sn_network_cut_dir_e dir);
75 int sn_stage_remove_input (sn_stage_t *s, int input);
76
77 sn_stage_t *sn_stage_read (FILE *fh);
78 int sn_stage_write (sn_stage_t *s, FILE *fh);
79
80 int sn_stage_serialize (sn_stage_t *s,
81     char **ret_buffer, size_t *ret_buffer_size);
82 sn_stage_t *sn_stage_unserialize (char **buffer, size_t *buffer_size);
83
84 #endif /* SN_STAGE_H */
85
86 /* vim: set shiftwidth=2 softtabstop=2 : */