MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / __pushdown

Function __pushdown

src/util/heap.c:78–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78static void __pushdown
79(
80 heap_t *hp,
81 unsigned int idx
82) {
83 while (1) {
84 unsigned int childl, childr, child;
85
86 // get left and right child indices
87 childl = __child_left(idx);
88 childr = __child_right(idx);
89
90 // see if right child index is within bounds
91 if(childr >= hp->count) {
92 // see if left child index is within bounds
93 if(childl >= hp->count) {
94 // we've reached a leaf node
95 // can't push down any further
96 return;
97 }
98
99 // only left child should be considered
100 child = childl;
101 }
102 // find smallest child
103 else if(hp->cmp(hp->array[childl], hp->array[childr], hp->udata) > 0) {
104 child = childl;
105 } else {
106 child = childr;
107 }
108
109 // idx is smaller than child
110 if(hp->cmp(hp->array[idx], hp->array[child], hp->udata) < 0) {
111 __swap(hp, idx, child);
112 idx = child;
113 } else {
114 // parent is smaller than its children we can stop
115 return;
116 }
117 }
118}
119
120// return item's index on the heap's array; otherwise -1
121static int __item_get_idx

Callers 2

Heap_pollFunction · 0.85
Heap_remove_itemFunction · 0.85

Calls 3

__child_leftFunction · 0.85
__child_rightFunction · 0.85
__swapFunction · 0.85

Tested by

no test coverage detected