Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Level.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Array.h>
35#include <ogdf/basic/Graph.h>
36#include <ogdf/basic/basic.h>
37#include <ogdf/basic/memory.h>
39
40#include <iosfwd>
41
42namespace ogdf {
43
44class HierarchyLevels;
45template<class E1, class E2>
46class Tuple2;
47template<class E>
48class SListPure;
49
50template<class T = double>
53
54public:
55 explicit WeightComparer(const NodeArray<T>* pWeight) : m_pWeight(pWeight) { }
56
57 bool less(node v, node w) const { return (*m_pWeight)[v] < (*m_pWeight)[w]; }
58
59 bool operator()(node v, node w) const { return (*m_pWeight)[v] < (*m_pWeight)[w]; }
60};
61
63
66class OGDF_EXPORT Level : public LevelBase {
67 friend class HierarchyLevels;
69 friend class LayerBasedUPRLayout;
70
73 int m_index;
74
75public:
77
82 Level(HierarchyLevels* pLevels, int index, int num)
83 : m_nodes(num), m_pLevels(pLevels), m_index(index) { }
84
85 // destruction
86 ~Level() { }
87
89 const node& operator[](int i) const override { return m_nodes[i]; }
90
92 node& operator[](int i) override { return m_nodes[i]; }
93
95 int size() const override { return m_nodes.size(); }
96
98 int high() const override { return m_nodes.high(); }
99
101 int index() const { return m_index; }
102
104 const Array<node>& adjNodes(node v) const;
105
107 const HierarchyLevels& levels() const { return *m_pLevels; }
108
110 void swap(int i, int j);
111
113 void sort(NodeArray<double>& weight);
114
116 void sort(NodeArray<int>& weight, int minBucket, int maxBucket);
117
120
122 template<class C>
123 void sortOrder(C& orderComparer) {
124 m_nodes.quicksort(orderComparer);
125 recalcPos();
126 }
127
128 void recalcPos();
129
130 friend std::ostream& operator<<(std::ostream& os, const Level& L) {
131 os << L.m_nodes;
132 return os;
133 }
134
135private:
138
140};
141
142}
Declaration and implementation of Array class and Array algorithms.
Declaration of interfaces used in Sugiyama framework.
Includes declaration of graph class.
Basic declarations, included by all source files.
The parameterized class Array implements dynamic arrays of type E.
Definition Array.h:219
INDEX high() const
Returns the maximal array index.
Definition Array.h:299
void quicksort()
Sorts array using Quicksort.
Definition Array.h:639
INDEX size() const
Returns the size (number of elements) of the array.
Definition Array.h:302
Interface of hierarchy layout algorithms.
Representation of proper hierarchies used by Sugiyama-layout.
Representation of levels in hierarchies.
Representation of levels in hierarchies.
Definition Level.h:66
const HierarchyLevels & levels() const
Returns the hierarchy to which this level belongs.
Definition Level.h:107
void getIsolatedNodes(SListPure< Tuple2< node, int > > &isolated) const
int m_index
The index of this level.
Definition Level.h:73
void setIsolatedNodes(SListPure< Tuple2< node, int > > &isolated)
void recalcPos()
void sortByWeightOnly(NodeArray< double > &weight)
Sorts the nodes according to weight (without special placement for "isolated" nodes).
void swap(int i, int j)
Exchanges nodes at position i and j.
node & operator[](int i) override
Returns the node at position i.
Definition Level.h:92
void sort(NodeArray< double > &weight)
Sorts the nodes according to weight using quicksort.
void sort(NodeArray< int > &weight, int minBucket, int maxBucket)
Sorts the nodes according to weight using bucket sort.
int index() const
Returns the array index of this level in the hierarchy.
Definition Level.h:101
void sortOrder(C &orderComparer)
Sorts the nodes according to orderComparer.
Definition Level.h:123
friend std::ostream & operator<<(std::ostream &os, const Level &L)
Definition Level.h:130
const node & operator[](int i) const override
Returns the node at position i.
Definition Level.h:89
const Array< node > & adjNodes(node v) const
Returns the (sorted) array of adjacent nodes of v (according to direction()).
Level(HierarchyLevels *pLevels, int index, int num)
Creates a level with index index in hierarchy pLevels.
Definition Level.h:82
int high() const override
Returns the maximal array index (= size()-1).
Definition Level.h:98
HierarchyLevels * m_pLevels
The hierarchy to which this level belongs.
Definition Level.h:72
int size() const override
Returns the number of nodes on this level.
Definition Level.h:95
Array< node > m_nodes
The nodes on this level.
Definition Level.h:71
Class for the representation of nodes.
Definition Graph_d.h:241
Singly linked lists.
Definition SList.h:191
Tuples of two elements (2-tuples).
Definition tuples.h:49
const NodeArray< T > * m_pWeight
Definition Level.h:52
bool less(node v, node w) const
Definition Level.h:57
WeightComparer(const NodeArray< T > *pWeight)
Definition Level.h:55
bool operator()(node v, node w) const
Definition Level.h:59
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition memory.h:92
Declaration of memory manager for allocating small pieces of memory.
The namespace for all OGDF objects.