MCPcopy Create free account
hub / github.com/ERGO-Code/HiGHS / addToDecreasingHeap

Function addToDecreasingHeap

highs/util/HighsSort.cpp:17–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15using std::vector;
16
17void addToDecreasingHeap(HighsInt& n, HighsInt mx_n, vector<double>& heap_v,
18 vector<HighsInt>& heap_ix, const double v,
19 const HighsInt ix) {
20 HighsInt cd_p, pa_p;
21 if (n < mx_n) {
22 // The heap is not full so put the new value at the bottom of the
23 // heap and let it rise up to its correct level.
24 n++;
25 cd_p = n;
26 pa_p = cd_p / 2;
27 for (;;) {
28 if (pa_p > 0) {
29 if (v < heap_v[pa_p]) {
30 heap_v[cd_p] = heap_v[pa_p];
31 heap_ix[cd_p] = heap_ix[pa_p];
32 cd_p = pa_p;
33 pa_p = pa_p / 2;
34 continue;
35 }
36 }
37 break;
38 }
39 heap_v[cd_p] = v;
40 heap_ix[cd_p] = ix;
41 } else if (v > heap_v[1]) {
42 // The heap is full so replace the least value with the new value
43 // and let it sink down to its correct level.
44 pa_p = 1;
45 cd_p = pa_p + pa_p;
46 for (;;) {
47 if (cd_p <= n) {
48 if (cd_p < n) {
49 if (heap_v[cd_p] > heap_v[cd_p + 1]) cd_p++;
50 }
51 if (v > heap_v[cd_p]) {
52 heap_v[pa_p] = heap_v[cd_p];
53 heap_ix[pa_p] = heap_ix[cd_p];
54 pa_p = cd_p;
55 cd_p = cd_p + cd_p;
56 continue;
57 }
58 }
59 break;
60 }
61 heap_v[pa_p] = v;
62 heap_ix[pa_p] = ix;
63 }
64 // Set heap_ix[0]=1 to indicate that the values form a heap.
65 heap_ix[0] = 1;
66 return;
67}
68
69void sortDecreasingHeap(const HighsInt n, vector<double>& heap_v,
70 vector<HighsInt>& heap_ix) {

Callers 2

chooseColumnMethod · 0.85
doAddSortFunction · 0.85

Calls

no outgoing calls

Tested by 1

doAddSortFunction · 0.68