Merge branch 'merges'
[sxemacs] / modules / ase / ase-permutation.h
1 /*** ase-permutation.h -- Permutations
2  *
3  * Copyright (C) 2006 - 2008 Sebastian Freundt
4  *
5  * Author:  Sebastian Freundt <hroptatyr@sxemacs.org>
6  *
7  * This file is part of SXEmacs.
8  * 
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * 3. Neither the name of the author nor the names of any contributors
21  *    may be used to endorse or promote products derived from this
22  *    software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  ***/
37
38 /* Synched up with: Not in FSF. */
39
40 #ifndef INCLUDED_ase_permutation_h_
41 #define INCLUDED_ase_permutation_h_ 1
42
43 #include "ase.h"
44
45 typedef struct ase_permutation_s *ase_permutation_t;
46
47 #define EMOD_ASE_DEBUG_PERM(args...)    EMOD_ASE_DEBUG("[PERM]: " args)
48
49 extern Lisp_Object Qase_permutation, Qase_permutationp;
50 extern Lisp_Object Qase_identity_permutation;
51 extern Lisp_Object Qpermutation_error, Qoverlap_error;
52
53 extern void LTX_PUBINIT(ase_permutation)(void);
54 extern void LTX_PUBREINIT(ase_permutation)(void);
55 extern void LTX_PUBDEINIT(ase_permutation)(void);
56
57 \f
58 struct ase_permutation_s {
59         size_t degree;
60         unsigned long *perm;
61 };
62
63 \f
64 #define ASE_PERMUTATIONP(_i)                                            \
65         (DYNACATP(_i) && EQ(XDYNACAT(_i)->type, Qase_permutation))
66 #define CHECK_ASE_PERMUTATION(x)                                        \
67         do {                                                            \
68                 if (!ASE_PERMUTATIONP(x))                               \
69                         dead_wrong_type_argument(Qase_permutationp, x); \
70         } while (0)
71 #define CONCHECK_ASE_PERMUTATION(x)                                     \
72         do {                                                            \
73                 if (!ASE_PERMUTATIONP(x))                               \
74                         x = wrong_type_argument(Qase_permutationp, x); \
75         } while (0)
76 extern Lisp_Object _ase_wrap_permutation(ase_permutation_t);
77 #define XSETASE_PERMUTATION(_res, _int) \
78         (_res) = _ase_wrap_permutation((_int))
79 #define XASE_PERMUTATION(_x)                    \
80         ((ase_permutation_t)get_dynacat(_x))
81
82 #define ase_permutation_degree(_p)      ((_p)->degree)
83 #define ase_permutation_perm(_p)        ((_p)->perm)
84 #define XASE_PERMUTATION_DEGREE(_p)             \
85         ase_permutation_degree(XASE_PERMUTATION(_p))
86 #define XASE_PERMUTATION_PERM(_p)               \
87         ase_permutation_perm(XASE_PERMUTATION(_p))
88
89 #define ase_permutation_refcnt(_a)      (&((_a)->refcnt))
90 #define ase_permutation_init_refcnt(_a) \
91         (sxe_refcounter_init(ase_permutation_refcnt(_a)))
92 #define ase_permutation_fini_refcnt(_a) \
93         (sxe_refcounter_finish(ase_permutation_refcnt(_a)))
94 #define ase_permutation_refval(_a)              \
95         (sxe_refcounter_value(ase_permutation_refcnt(_a)))
96 #define ase_permutation_incref(_a)              \
97         (sxe_refcounter_incref(ase_permutation_refcnt(_a)))
98 #define ase_permutation_decref(_a)              \
99         (sxe_refcounter_decref(ase_permutation_refcnt(_a)))
100 #define XASE_PERMUTATION_REFVAL(_a)                     \
101         (ase_permutation_refval(XASE_PERMUTATION(_a)))
102 #define XASE_PERMUTATION_INCREF(_a)                     \
103         (ase_permutation_incref(XASE_PERMUTATION(_a)))
104 #define XASE_PERMUTATION_DECREF(_a)                     \
105         (ase_permutation_decref(XASE_PERMUTATION(_a)))
106
107 \f
108 /* constructors */
109 extern Lisp_Object
110 ase_make_permutation(Lisp_Object vector);
111 extern Lisp_Object ase_copy_permutation(Lisp_Object perm);
112
113 /* predicates */
114
115 #endif