emergency commit
[cl-cudd.git] / distr / mtr / mtr.h
blobd8f2f9250207eb71efcfd73ba59670b2fad3026a
1 /**CHeaderFile*****************************************************************
3 FileName [mtr.h]
5 PackageName [mtr]
7 Synopsis [Multiway-branch tree manipulation]
9 Description [This package provides two layers of functions. Functions
10 of the lower level manipulate multiway-branch trees, implemented
11 according to the classical scheme whereby each node points to its
12 first child and its previous and next siblings. These functions are
13 collected in mtrBasic.c.<p>
14 Functions of the upper layer deal with group trees, that is the trees
15 used by group sifting to represent the grouping of variables. These
16 functions are collected in mtrGroup.c.]
18 SeeAlso [The CUDD package documentation; specifically on group
19 sifting.]
21 Author [Fabio Somenzi]
23 Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado
25 All rights reserved.
27 Redistribution and use in source and binary forms, with or without
28 modification, are permitted provided that the following conditions
29 are met:
31 Redistributions of source code must retain the above copyright
32 notice, this list of conditions and the following disclaimer.
34 Redistributions in binary form must reproduce the above copyright
35 notice, this list of conditions and the following disclaimer in the
36 documentation and/or other materials provided with the distribution.
38 Neither the name of the University of Colorado nor the names of its
39 contributors may be used to endorse or promote products derived from
40 this software without specific prior written permission.
42 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
45 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
46 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
47 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
48 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
50 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
52 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
53 POSSIBILITY OF SUCH DAMAGE.]
55 Revision [$Id: mtr.h,v 1.14 2009/02/20 02:03:47 fabio Exp $]
57 ******************************************************************************/
59 #ifndef __MTR
60 #define __MTR
62 /*---------------------------------------------------------------------------*/
63 /* Nested includes */
64 /*---------------------------------------------------------------------------*/
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
70 /*---------------------------------------------------------------------------*/
71 /* Constant declarations */
72 /*---------------------------------------------------------------------------*/
74 #ifndef SIZEOF_VOID_P
75 #define SIZEOF_VOID_P 4
76 #endif
77 #ifndef SIZEOF_INT
78 #define SIZEOF_INT 4
79 #endif
81 #undef CONST
82 #if defined(__STDC__) || defined(__cplusplus)
83 #define CONST const
84 #else /* !(__STDC__ || __cplusplus) */
85 #define CONST
86 #endif /* !(__STDC__ || __cplusplus) */
88 #if defined(__GNUC__)
89 #define MTR_INLINE __inline__
90 # if (__GNUC__ >2 || __GNUC_MINOR__ >=7)
91 # define MTR_UNUSED __attribute__ ((unused))
92 # else
93 # define MTR_UNUSED
94 # endif
95 #else
96 #define MTR_INLINE
97 #define MTR_UNUSED
98 #endif
100 /* Flag definitions */
101 #define MTR_DEFAULT 0x00000000
102 #define MTR_TERMINAL 0x00000001
103 #define MTR_SOFT 0x00000002
104 #define MTR_FIXED 0x00000004
105 #define MTR_NEWNODE 0x00000008
107 /* MTR_MAXHIGH is defined in such a way that on 32-bit and 64-bit
108 ** machines one can cast a value to (int) without generating a negative
109 ** number.
111 #if SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
112 #define MTR_MAXHIGH (((MtrHalfWord) ~0) >> 1)
113 #else
114 #define MTR_MAXHIGH ((MtrHalfWord) ~0)
115 #endif
118 /*---------------------------------------------------------------------------*/
119 /* Stucture declarations */
120 /*---------------------------------------------------------------------------*/
123 /*---------------------------------------------------------------------------*/
124 /* Type declarations */
125 /*---------------------------------------------------------------------------*/
127 #if SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
128 typedef unsigned int MtrHalfWord;
129 #else
130 typedef unsigned short MtrHalfWord;
131 #endif
133 typedef struct MtrNode {
134 MtrHalfWord flags;
135 MtrHalfWord low;
136 MtrHalfWord size;
137 MtrHalfWord index;
138 struct MtrNode *parent;
139 struct MtrNode *child;
140 struct MtrNode *elder;
141 struct MtrNode *younger;
142 } MtrNode;
145 /*---------------------------------------------------------------------------*/
146 /* Variable declarations */
147 /*---------------------------------------------------------------------------*/
150 /*---------------------------------------------------------------------------*/
151 /* Macro declarations */
152 /*---------------------------------------------------------------------------*/
154 /* Flag manipulation macros */
155 #define MTR_SET(node, flag) (node->flags |= (flag))
156 #define MTR_RESET(node, flag) (node->flags &= ~ (flag))
157 #define MTR_TEST(node, flag) (node->flags & (flag))
160 /**AutomaticStart*************************************************************/
162 /*---------------------------------------------------------------------------*/
163 /* Function prototypes */
164 /*---------------------------------------------------------------------------*/
166 extern MtrNode * Mtr_AllocNode (void);
167 extern void Mtr_DeallocNode (MtrNode *node);
168 extern MtrNode * Mtr_InitTree (void);
169 extern void Mtr_FreeTree (MtrNode *node);
170 extern MtrNode * Mtr_CopyTree (MtrNode *node, int expansion);
171 extern void Mtr_MakeFirstChild (MtrNode *parent, MtrNode *child);
172 extern void Mtr_MakeLastChild (MtrNode *parent, MtrNode *child);
173 extern MtrNode * Mtr_CreateFirstChild (MtrNode *parent);
174 extern MtrNode * Mtr_CreateLastChild (MtrNode *parent);
175 extern void Mtr_MakeNextSibling (MtrNode *first, MtrNode *second);
176 extern void Mtr_PrintTree (MtrNode *node);
177 extern MtrNode * Mtr_InitGroupTree (int lower, int size);
178 extern MtrNode * Mtr_MakeGroup (MtrNode *root, unsigned int low, unsigned int high, unsigned int flags);
179 extern MtrNode * Mtr_DissolveGroup (MtrNode *group);
180 extern MtrNode * Mtr_FindGroup (MtrNode *root, unsigned int low, unsigned int high);
181 extern int Mtr_SwapGroups (MtrNode *first, MtrNode *second);
182 extern void Mtr_PrintGroups (MtrNode *root, int silent);
183 extern MtrNode * Mtr_ReadGroups (FILE *fp, int nleaves);
185 /**AutomaticEnd***************************************************************/
187 #ifdef __cplusplus
189 #endif
191 #endif /* __MTR */