Open
Graph Drawing
Framework
v. 2023.09 (Elderberry)
Overview
Class Hierarchy
Class Index
Class List
Members
Namespaces
Source Files
Loading...
Searching...
No Matches
Sort.h
Go to the documentation of this file.
1
/******************************************************************************************[Sort.h]
2
Copyright (c) 2003-2007, Niklas Een, Niklas Sorensson
3
Copyright (c) 2007-2010, Niklas Sorensson
4
5
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
associated documentation files (the "Software"), to deal in the Software without restriction,
7
including without limitation the rights to use, copy, modify, merge, publish, distribute,
8
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9
furnished to do so, subject to the following conditions:
10
11
The above copyright notice and this permission notice shall be included in all copies or
12
substantial portions of the Software.
13
14
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
18
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
**************************************************************************************************/
20
21
#pragma once
22
23
#include <
ogdf/lib/minisat/mtl/Vec.h
>
24
25
//=================================================================================================
26
// Some sorting algorithms for vec's
27
28
29
#pragma GCC visibility push(default)
30
namespace
Minisat
{
31
namespace
Internal {
32
33
template
<
class
T>
34
struct
LessThan_default
{
35
bool
operator ()
(T x, T y) {
return
x < y; }
36
};
37
38
39
template
<
class
T,
class
LessThan>
40
void
selectionSort
(T* array,
int
size, LessThan lt)
41
{
42
int
i, j;
43
T tmp;
44
45
for
(i = 0; i < size-1; i++){
46
int
best_i = i;
47
for
(j = i+1; j < size; j++){
48
if
(lt(array[j], array[best_i]))
49
best_i = j;
50
}
51
tmp = array[i]; array[i] = array[best_i]; array[best_i] = tmp;
52
}
53
}
54
template
<
class
T>
static
inline
void
selectionSort
(T* array,
int
size) {
55
selectionSort
(array, size,
LessThan_default<T>
()); }
56
57
template
<
class
T,
class
LessThan>
58
void
sort
(T* array,
int
size, LessThan lt)
59
{
60
if
(size <= 15)
61
selectionSort
(array, size, lt);
62
63
else
{
64
T pivot = array[size / 2];
65
T tmp;
66
int
i = -1;
67
int
j = size;
68
69
for
(;;){
70
do
i++;
while
(lt(array[i], pivot));
71
do
j--;
while
(lt(pivot, array[j]));
72
73
if
(i >= j)
break
;
74
75
tmp = array[i]; array[i] = array[j]; array[j] = tmp;
76
}
77
78
sort
(array , i , lt);
79
sort
(&array[i], size-i, lt);
80
}
81
}
82
template
<
class
T>
static
inline
void
sort
(T* array,
int
size) {
83
sort
(array, size,
LessThan_default<T>
()); }
84
85
86
//=================================================================================================
87
// For 'vec's:
88
89
90
template
<
class
T,
class
LessThan>
void
sort
(
vec<T>
& v, LessThan lt) {
91
sort
(
static_cast<
T*
>
(v), v.
size
(), lt); }
92
template
<
class
T>
void
sort
(
vec<T>
& v) {
93
sort
(v,
LessThan_default<T>
()); }
94
95
96
//=================================================================================================
97
}
// namespace Internal
98
}
// namespace Minisat
99
#pragma GCC visibility pop
Vec.h
Minisat::Internal::vec
Definition
Vec.h:39
Minisat::Internal::vec::size
int size(void) const
Definition
Vec.h:64
Minisat::Internal::sort
void sort(T *array, int size, LessThan lt)
Definition
Sort.h:58
Minisat::Internal::selectionSort
void selectionSort(T *array, int size, LessThan lt)
Definition
Sort.h:40
Minisat
Definition
Minisat.h:55
Minisat::Internal::LessThan_default
Definition
Sort.h:34
Minisat::Internal::LessThan_default::operator()
bool operator()(T x, T y)
Definition
Sort.h:35
include
ogdf
lib
minisat
mtl
Sort.h
This site is powered by Netlify.
© 1999–2025
The OGDF Team