2 Copyright 2020 Google LLC
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file or at
6 https://developers.google.com/open-source/licenses/bsd
12 #include "constants.h"
15 #include "reftable-tests.h"
16 #include "test_framework.h"
18 void merged_iter_pqueue_check(struct merged_iter_pqueue pq
)
21 for (i
= 1; i
< pq
.len
; i
++) {
22 int parent
= (i
- 1) / 2;
24 EXPECT(pq_less(&pq
.heap
[parent
], &pq
.heap
[i
]));
28 static void test_pq(void)
30 struct merged_iter_pqueue pq
= { NULL
};
31 struct reftable_record recs
[54];
32 int N
= ARRAY_SIZE(recs
) - 1, i
;
35 for (i
= 0; i
< N
; i
++) {
36 struct strbuf refname
= STRBUF_INIT
;
37 strbuf_addf(&refname
, "%02d", i
);
39 reftable_record_init(&recs
[i
], BLOCK_TYPE_REF
);
40 recs
[i
].u
.ref
.refname
= strbuf_detach(&refname
, NULL
);
49 merged_iter_pqueue_add(&pq
, &e
);
50 merged_iter_pqueue_check(pq
);
55 while (!merged_iter_pqueue_is_empty(pq
)) {
56 struct pq_entry e
= merged_iter_pqueue_remove(&pq
);
57 merged_iter_pqueue_check(pq
);
59 EXPECT(reftable_record_type(e
.rec
) == BLOCK_TYPE_REF
);
61 EXPECT(strcmp(last
, e
.rec
->u
.ref
.refname
) < 0);
62 last
= e
.rec
->u
.ref
.refname
;
65 for (i
= 0; i
< N
; i
++)
66 reftable_record_release(&recs
[i
]);
67 merged_iter_pqueue_release(&pq
);
70 int pq_test_main(int argc
, const char *argv
[])