Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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 
42 namespace ogdf {
43 
44 class HierarchyLevels;
45 template<class E1, class E2>
46 class Tuple2;
47 template<class E>
48 class SListPure;
49 
50 template<class T = double>
53 
54 public:
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 
66 class OGDF_EXPORT Level : public LevelBase {
67  friend class HierarchyLevels;
68  friend class HierarchyLayoutModule;
69  friend class LayerBasedUPRLayout;
70 
73  int m_index;
74 
75 public:
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 
119  void sortByWeightOnly(NodeArray<double>& weight);
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 
135 private:
136  void getIsolatedNodes(SListPure<Tuple2<node, int>>& isolated) const;
137  void setIsolatedNodes(SListPure<Tuple2<node, int>>& isolated);
138 
140 };
141 
142 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::Level::operator[]
node & operator[](int i) override
Returns the node at position i.
Definition: Level.h:92
Graph.h
Includes declaration of graph class.
ogdf::Level::operator<<
friend std::ostream & operator<<(std::ostream &os, const Level &L)
Definition: Level.h:130
ogdf::WeightComparer::WeightComparer
WeightComparer(const NodeArray< T > *pWeight)
Definition: Level.h:55
ogdf::Level::m_index
int m_index
The index of this level.
Definition: Level.h:73
ogdf::Tuple2
Tuples of two elements (2-tuples).
Definition: tuples.h:49
ogdf::HierarchyLayoutModule
Interface of hierarchy layout algorithms.
Definition: HierarchyLayoutModule.h:52
ogdf::Level::high
int high() const override
Returns the maximal array index (= size()-1).
Definition: Level.h:98
ogdf::Array::high
INDEX high() const
Returns the maximal array index.
Definition: Array.h:299
ogdf::Level::~Level
~Level()
Definition: Level.h:86
ogdf::Level::operator[]
const node & operator[](int i) const override
Returns the node at position i.
Definition: Level.h:89
ogdf::Level::sortOrder
void sortOrder(C &orderComparer)
Sorts the nodes according to orderComparer.
Definition: Level.h:123
ogdf::WeightComparer
Definition: Level.h:51
ogdf::Level::Level
Level(HierarchyLevels *pLevels, int index, int num)
Creates a level with index index in hierarchy pLevels.
Definition: Level.h:82
Minisat::Internal::sort
void sort(T *array, int size, LessThan lt)
Definition: Sort.h:57
ogdf::LayerBasedUPRLayout
Definition: LayerBasedUPRLayout.h:109
ogdf::Level::size
int size() const override
Returns the number of nodes on this level.
Definition: Level.h:95
OGDF_MALLOC_NEW_DELETE
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition: memory.h:92
ogdf::Level::m_nodes
Array< node > m_nodes
The nodes on this level.
Definition: Level.h:71
ogdf::Array< node >
ogdf::SListPure
Singly linked lists.
Definition: SList.h:52
ogdf::WeightComparer::less
bool less(node v, node w) const
Definition: Level.h:57
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::Level::levels
const HierarchyLevels & levels() const
Returns the hierarchy to which this level belongs.
Definition: Level.h:107
CrossingMinInterfaces.h
Declaration of interfaces used in Sugiyama framework.
ogdf::Level::index
int index() const
Returns the array index of this level in the hierarchy.
Definition: Level.h:101
ogdf::Level::m_pLevels
HierarchyLevels * m_pLevels
The hierarchy to which this level belongs.
Definition: Level.h:72
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
Array.h
Declaration and implementation of Array class and Array algorithms.
ogdf::Array::quicksort
void quicksort()
Sorts array using Quicksort.
Definition: Array.h:639
ogdf::Array::size
INDEX size() const
Returns the size (number of elements) of the array.
Definition: Array.h:302
ogdf::Level
Representation of levels in hierarchies.
Definition: Level.h:66
ogdf::LevelBase
Representation of levels in hierarchies.
Definition: CrossingMinInterfaces.h:45
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
memory.h
Declaration of memory manager for allocating small pieces of memory.
ogdf::WeightComparer::m_pWeight
const NodeArray< T > * m_pWeight
Definition: Level.h:52
ogdf::WeightComparer::operator()
bool operator()(node v, node w) const
Definition: Level.h:59
ogdf::HierarchyLevels
Representation of proper hierarchies used by Sugiyama-layout.
Definition: HierarchyLevels.h:51