ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
sort.h
Go to the documentation of this file.
1//===--- sort.h -------------------------------------------------------------===
2//
3// satoko: Satisfiability solver
4//
5// This file is distributed under the BSD 2-Clause License.
6// See LICENSE for details.
7//
8//===------------------------------------------------------------------------===
9#ifndef satoko__utils__sort_h
10#define satoko__utils__sort_h
11
14
15static inline void select_sort(void **data, unsigned size,
16 int (*comp_fn)(const void *, const void *))
17{
18 unsigned i, j, i_best;
19 void *temp;
20
21 for (i = 0; i < (size - 1); i++) {
22 i_best = i;
23 for (j = i + 1; j < size; j++) {
24 if (comp_fn(data[j], data[i_best]))
25 i_best = j;
26 }
27 temp = data[i];
28 data[i] = data[i_best];
29 data[i_best] = temp;
30 }
31}
32
33static void satoko_sort(void **data, unsigned size,
34 int (*comp_fn)(const void *, const void *))
35{
36 if (size <= 15)
37 select_sort(data, size, comp_fn);
38 else {
39 void *pivot = data[size / 2];
40 void *temp;
41 unsigned j = size;
42 int i = -1;
43
44 for (;;) {
45 do {
46 i++;
47 } while (comp_fn(data[i], pivot));
48 do {
49 j--;
50 } while (comp_fn(pivot, data[j]));
51
52 if ((unsigned) i >= j)
53 break;
54
55 temp = data[i];
56 data[i] = data[j];
57 data[j] = temp;
58 }
59 satoko_sort(data, (unsigned) i, comp_fn);
60 satoko_sort(data + i, (size - (unsigned) i), comp_fn);
61 }
62}
63
65#endif /* satoko__utils__sort_h */
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
unsigned long long size
Definition giaNewBdd.h:39