Skip to content

Commit 312d079

Browse files
committed
fix: use uint64_t for indices
1 parent b8d55e2 commit 312d079

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

program/c/src/oracle/model/price_model.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,29 @@ void heapsort(int64_t * a, uint64_t n) {
1414
/*
1515
* This is a bottom-up heapify which is linear in time.
1616
*/
17-
for (int i = n / 2 - 1; i >= 0; i--) {
17+
for (uint64_t i = n / 2 - 1;; --i) {
1818
int64_t root = a[i];
19-
int j = i * 2 + 1;
19+
uint64_t j = i * 2 + 1;
2020
while (j < n) {
21-
if (j + 1 < n && a[j] < a[j + 1]) j++;
21+
if (j + 1 < n && a[j] < a[j + 1]) ++j;
2222
if (root >= a[j]) break;
2323
a[(j - 1) / 2] = a[j];
2424
j = j * 2 + 1;
2525
}
2626
a[(j - 1) / 2] = root;
27+
28+
if (i == 0) break;
2729
}
2830

29-
for (int i = n - 1; i > 0; i--) {
31+
for (uint64_t i = n - 1; i > 0; --i) {
3032
int64_t tmp = a[0];
3133
a[0] = a[i];
3234
a[i] = tmp;
3335

3436
int64_t root = a[0];
35-
int j = 1;
37+
uint64_t j = 1;
3638
while (j < i) {
37-
if (j + 1 < i && a[j] < a[j + 1]) j++;
39+
if (j + 1 < i && a[j] < a[j + 1]) ++j;
3840
if (root >= a[j]) break;
3941
a[(j - 1) / 2] = a[j];
4042
j = j * 2 + 1;

0 commit comments

Comments
 (0)