1 /**CHeaderFile*****************************************************************
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
21 Author [Fabio Somenzi]
23 Copyright [Copyright (c) 1995-2004, Regents of the University of Colorado
27 Redistribution and use in source and binary forms, with or without
28 modification, are permitted provided that the following conditions
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 ******************************************************************************/
62 /*---------------------------------------------------------------------------*/
64 /*---------------------------------------------------------------------------*/
70 /*---------------------------------------------------------------------------*/
71 /* Constant declarations */
72 /*---------------------------------------------------------------------------*/
75 #define SIZEOF_VOID_P 4
82 #if defined(__STDC__) || defined(__cplusplus)
84 #else /* !(__STDC__ || __cplusplus) */
86 #endif /* !(__STDC__ || __cplusplus) */
89 #define MTR_INLINE __inline__
90 # if (__GNUC__ >2 || __GNUC_MINOR__ >=7)
91 # define MTR_UNUSED __attribute__ ((unused))
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
111 #if SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
112 #define MTR_MAXHIGH (((MtrHalfWord) ~0) >> 1)
114 #define MTR_MAXHIGH ((MtrHalfWord) ~0)
118 /*---------------------------------------------------------------------------*/
119 /* Stucture declarations */
120 /*---------------------------------------------------------------------------*/
123 /*---------------------------------------------------------------------------*/
124 /* Type declarations */
125 /*---------------------------------------------------------------------------*/
127 #if SIZEOF_VOID_P == 8 && SIZEOF_INT == 4
128 typedef unsigned int MtrHalfWord
;
130 typedef unsigned short MtrHalfWord
;
133 typedef struct MtrNode
{
138 struct MtrNode
*parent
;
139 struct MtrNode
*child
;
140 struct MtrNode
*elder
;
141 struct MtrNode
*younger
;
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***************************************************************/