09c2b571cb024770b3a893e6f435700e48556d3a
[sort-networks.git] / src / sn_comparator.h
1 /**
2  * \file sn_comparator.h
3  * \brief The sn_comparator_t class and associated methods.
4  *
5  * \verbatim
6  * libsortnetwork - src/sn_comparator.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_COMPARATOR_H
28 #define SN_COMPARATOR_H 1
29
30 struct sn_comparator_s
31 {
32   int min;
33   int max;
34 };
35 typedef struct sn_comparator_s sn_comparator_t;
36
37 #define SN_COMP_LEFT(c)  (((c)->min < (c)->max) ? (c)->min : (c)->max)
38 #define SN_COMP_RIGHT(c) (((c)->min > (c)->max) ? (c)->min : (c)->max)
39 #define SN_COMP_MIN(c) (c)->min
40 #define SN_COMP_MAX(c) (c)->max
41
42 sn_comparator_t *sn_comparator_create (int min, int max);
43 void sn_comparator_destroy (sn_comparator_t *c);
44 void sn_comparator_invert (sn_comparator_t *c);
45 void sn_comparator_shift (sn_comparator_t *c, int sw, int inputs_num);
46 void sn_comparator_swap (sn_comparator_t *c, int con0, int con1);
47
48 int sn_comparator_compare (const void *, const void *);
49
50 #endif /* SN_COMPARATOR_H */
51
52 /* vim: set shiftwidth=2 softtabstop=2 : */