6 * $Date: 2012-07-06 15:04:28 +0200 (Fr, 06. Jul 2012) $
7 ***************************************************************/
10 * \brief Declaration of class WSPD (well-separated pair decomposition).
12 * \author Martin Gronemann
15 * This file is part of the Open Graph Drawing Framework (OGDF).
19 * See README.txt in the root directory of the OGDF installation for details.
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * Version 2 or 3 as published by the Free Software Foundation;
25 * see the file LICENSE.txt included in the packaging of this file
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public
36 * License along with this program; if not, write to the Free
37 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
38 * Boston, MA 02110-1301, USA.
40 * \see http://www.gnu.org/copyleft/gpl.html
41 ***************************************************************/
46 #include "LinearQuadtree.h"
50 //! class for storing per node information
53 __uint32 numWSNodes
; // total count of pairs where is either the first or second node
54 __uint32 firstEntry
; // the first pair in the nodes chain
55 __uint32 lastEntry
; // the last pair in the nodes chain
59 //! class for storing per pair information
62 __uint32 a
; // first node of the pair
63 __uint32 b
; // second node of the pair
64 __uint32 a_next
;// next pair in the chain of the first node
65 __uint32 b_next
;// next pair in the chain of the second node
69 //! class for the Well-Separated-Pairs-Decomposition (WSPD)
73 typedef LinearQuadtree::NodeID NodeID
;
75 //! the constructor. allocates the mem
76 WSPD(__uint32 maxNumNodes
);
81 //! returns the max number of nodes. (Equals the max number of nodes in the lin quadtree)
82 inline __uint32
maxNumNodes() const
87 //! returns the number of well separated nodes for node a
88 inline __uint32
numWSNodes(NodeID a
) const
90 return m_nodeInfo
[a
].numWSNodes
;
93 //! returns the total number of pairs
94 inline __uint32
numPairs() const
99 //! returns the maximum number of pairs
100 inline __uint32
maxNumPairs() const
102 return m_maxNumPairs
;
108 //! add a well separated pair (a, b)
109 void addWSP(NodeID a
, NodeID b
)
111 // get the index of a free element
112 __uint32 e_index
= m_numPairs
++;
114 // get the pair entry
115 WSPDPairInfo
& e
= pairInfo(e_index
);
117 // (a,b) is the pair we are adding
122 WSPDNodeInfo
& aInfo
= nodeInfo(a
);
123 WSPDNodeInfo
& bInfo
= nodeInfo(b
);
125 // if a is part of at least one pair
126 if (aInfo
.numWSNodes
)
129 WSPDPairInfo
& a_e
= pairInfo(aInfo
.lastEntry
);
130 // check which one is a
132 a_e
.a_next
= e_index
;
134 a_e
.b_next
= e_index
;
137 // this pair is the first for a => set the firstEntry link
138 aInfo
.firstEntry
= e_index
;
141 // same for b: if a is part of at least one pair
142 if (bInfo
.numWSNodes
)
145 WSPDPairInfo
& b_e
= pairInfo(bInfo
.lastEntry
);
146 // check which one is b
148 b_e
.a_next
= e_index
;
150 b_e
.b_next
= e_index
;
153 // this pair is the first for b => set the firstEntry link
154 bInfo
.firstEntry
= e_index
;
156 // and the lastEntry link
157 aInfo
.lastEntry
= e_index
;
158 bInfo
.lastEntry
= e_index
;
159 // one more pair for each node
164 //! returns the PairInfo by index
165 inline WSPDPairInfo
& pairInfo(__uint32 pairIndex
) const
167 return m_pairs
[pairIndex
];
170 //! returns the NodeInfo by index
171 inline WSPDNodeInfo
& nodeInfo(NodeID node
) const
173 return m_nodeInfo
[node
];
176 //! returns the index of the next pair of curr for node a
177 inline __uint32
nextPair(__uint32 currPairIndex
, NodeID a
) const
179 const WSPDPairInfo
& currInfo
= pairInfo(currPairIndex
);
181 return currInfo
.a_next
;
182 return currInfo
.b_next
;
185 //! returns the other node a is paired with in pair with the given index
186 inline __uint32
wsNodeOfPair(__uint32 currPairIndex
, NodeID a
) const
188 const WSPDPairInfo
& currInfo
= pairInfo(currPairIndex
);
194 //! returns the index of the first pair of node node
195 inline __uint32
firstPairEntry(NodeID node
) const
197 return m_nodeInfo
[node
].firstEntry
;
200 // returns the size excluding small member vars (for profiling only)
201 unsigned long sizeInBytes() const;
204 //! allocates all memory
207 //! releases all memory
210 //! the max number of nodes. (Equals the max number of nodes in the lin quadtree)
211 __uint32 m_maxNumNodes
;
213 //! the array which holds the wspd information for one quadtree node
214 WSPDNodeInfo
* m_nodeInfo
;
216 //! the array containing all pairs
217 WSPDPairInfo
* m_pairs
;
219 //! the total number of pairs
222 //! the upper bound for the number of pairs
223 __uint32 m_maxNumPairs
;
226 } // end of namespace ogdf