예제 #1
0
static inline void
heapify_large_node(mm_handle *mm, idx_t idx)
{
    idx_t idx2;
    mm_node *node;
    mm_node *node2;
    mm_node **s_heap;
    mm_node **l_heap;
    idx_t n_s, n_l;
    ai_t ai;

    s_heap = mm->s_heap;
    l_heap = mm->l_heap;
    node = l_heap[idx];
    n_s = mm->n_s;
    n_l = mm->n_l;
    ai = node->ai;

    // Internal or leaf node.
    if (idx > 0) {
        idx2 = P_IDX(idx);
        node2 = l_heap[idx2];

        // Move down.
        if (ai < node2->ai) {
            mm_move_down_large(l_heap, idx, node, idx2, node2);

            // Maybe swap between heaps.
            node2 = s_heap[0];
            if (ai < node2->ai) {
                mm_swap_heap_heads(s_heap, n_s, l_heap, n_l, node2, node);
            }
        }

        // Move up.
        else if (idx < mm->l_first_leaf) {
            mm_move_up_large(l_heap, n_l, idx, node);
        }
    }

    // Head node.
    else {
        node2 = s_heap[0];
        if (n_s > 0 && ai < node2->ai) {
            mm_swap_heap_heads(s_heap, n_s, l_heap, n_l, node2, node);
        } else {
            mm_move_up_large(l_heap, n_l, idx, node);
        }
    }

}
예제 #2
0
static inline void
heapify_small_node(mm_handle *mm, idx_t idx)
{
    idx_t idx2;
    mm_node *node;
    mm_node *node2;
    mm_node **s_heap;
    mm_node **l_heap;
    idx_t n_s, n_l;
    ai_t ai;

    s_heap = mm->s_heap;
    l_heap = mm->l_heap;
    node = s_heap[idx];
    n_s = mm->n_s;
    n_l = mm->n_l;
    ai = node->ai;

    /* Internal or leaf node */
    if (idx > 0) {
        idx2 = P_IDX(idx);
        node2 = s_heap[idx2];

        /* Move up */
        if (ai > node2->ai) {
            mm_move_up_small(s_heap, idx, node, idx2, node2);

            /* Maybe swap between heaps */
            node2 = l_heap[0];
            if (ai > node2->ai) {
                mm_swap_heap_heads(s_heap, n_s, l_heap, n_l, node, node2);
            }
        }

        /* Move down */
        else if (idx < mm->s_first_leaf) {
            mm_move_down_small(s_heap, n_s, idx, node);
        }
    }

    /* Head node */
    else {
        node2 = l_heap[0];
        if (n_l > 0 && ai > node2->ai) {
            mm_swap_heap_heads(s_heap, n_s, l_heap, n_l, node, node2);
        } else {
            mm_move_down_small(s_heap, n_s, idx, node);
        }
    }
}