Exemple #1
0
// NOTE:  this function could easily be rewritten using the general funtions
//{{{ void wah_leading_repair(uint32_t domain, 
void wah_leading_repair(uint32_t domain, 
                          struct bpt_node *a,
                          struct bpt_node *b)
{
#if DEBUG
    fprintf(stderr, "START leading_repair\n");
#endif

    if ( (BPT_IS_LEAF(a) == 1) && (BPT_IS_LEAF(b) == 1) ) {
        // make a new leading value for the new right node
        struct wah_bpt_leading_data *d = 
            (struct wah_bpt_leading_data *)
            malloc(sizeof(struct wah_bpt_leading_data));

        d->B = NULL;

        // if the left node had leading data, grab all of it
        if (BPT_LEADING(a) != 0) {
            // get it from cache
            struct wah_bpt_leading_data *l =  
                    cache.get(domain,
                              BPT_LEADING(a) - 1,
                              &wah_leading_cache_handler);
#if DEBUG
            uint32_t *R = NULL, R_size;
            uint32_t j;
            fprintf(stderr, "LEADING\t");
            if (l->B != NULL) {
                R_size = wah_get_ints(l->B, &R);
                fprintf(stderr, "R_size:%u\t", R_size);
                for (j = 0; j < R_size; ++j)
                    fprintf(stderr, "R[%u]:%u\t", j, R[j]);
                free(R);
                R = NULL;
            }
            fprintf(stderr, "\n");
#endif
            d->B = wah_copy(l->B);
        }

        uint32_t i;
        for (i = 0 ; i < BPT_NUM_KEYS(a); ++i) {
            struct wah_bpt_non_leading_data *nl = 
                    cache.get(domain,
                              BPT_POINTERS(a)[i] - 1,
                              &wah_non_leading_cache_handler);

#if DEBUG
            uint32_t *R = NULL, R_size;
            uint32_t j;

            fprintf(stderr, "%u\tSA\t",BPT_KEYS(a)[i]);
            if (nl->SA != NULL) {
                R_size = wah_get_ints(nl->SA, &R);
                fprintf(stderr, "R_size:%u\t", R_size);
                for (j = 0; j < R_size; ++j)
                    fprintf(stderr, "R[%u]:%u\t", j, R[j]);
                free(R);
                R = NULL;
            }
            fprintf(stderr, "\n");
            fprintf(stderr, "SE\t");
            if (nl->SE != NULL) {
                R_size = wah_get_ints(nl->SE, &R);
                fprintf(stderr, "R_size:%u\t", R_size);
                for (j = 0; j < R_size; ++j)
                    fprintf(stderr, "R[%u]:%u\t", j, R[j]);
                free(R);
                R = NULL;
            }
            fprintf(stderr, "\n");
#endif

            wah_non_leading_union_with_SA_subtract_SE(domain,
                                                        (void **)(&d->B),
                                                        nl);


        }

        if (d->B != NULL) {
            uint32_t v_id = cache.seen(domain) + 1;
            cache.add(domain, v_id - 1, d, &wah_leading_cache_handler);
            BPT_LEADING(b) = v_id;
        } else {
            free(d);
        }
    }

#if DEBUG
    fprintf(stderr, "END leading_repair\n");
#endif
}
Exemple #2
0
//{{{void leading_repair(struct bpt_node *a, struct bpt_node *b)
void uint32_t_ll_leading_repair(uint32_t domain, 
                                struct bpt_node *a,
                                struct bpt_node *b)
{
#if DEBUG
    fprintf(stderr, "leading_repair\n");
#endif

    if ( (BPT_IS_LEAF(a) == 1) && (BPT_IS_LEAF(b) == 1) ) {
        struct uint32_t_ll_bpt_leading_data *d = 
            (struct uint32_t_ll_bpt_leading_data *)
            malloc(sizeof(struct uint32_t_ll_bpt_leading_data));

        d->B = NULL;

        if (BPT_LEADING(a) != 0) {
            struct uint32_t_ll_bpt_leading_data *l =  
                    cache.get(domain,
                              BPT_LEADING(a) - 1,
                              &uint32_t_ll_leading_cache_handler);

            struct uint32_t_ll_node *curr = l->B->head;

            while (curr != NULL) {
#if DEBUG
                fprintf(stderr, "+ %u\n", curr->val);
#endif
                uint32_t_ll_uniq_append(&(d->B), curr->val);
                curr = curr->next;
            }
        }

        uint32_t i;
        for (i = 0 ; i < BPT_NUM_KEYS(a); ++i) {
            struct uint32_t_ll_bpt_non_leading_data *nl = 
                    cache.get(domain,
                              BPT_POINTERS(a)[i] - 1,
                              &uint32_t_ll_non_leading_cache_handler);

            if (nl->SA != NULL) {
                struct uint32_t_ll_node *curr = nl->SA->head;
                while (curr != NULL) {
                    uint32_t_ll_uniq_append(&(d->B), curr->val);
#if DEBUG
                    fprintf(stderr, "+ %u\n", curr->val);
#endif
                    curr = curr->next;
                }
            }

            if (nl->SE != NULL) {
                struct uint32_t_ll_node *curr = nl->SE->head;
                while (curr != NULL) {
                    uint32_t_ll_remove(&(d->B), curr->val);
#if DEBUG
                    fprintf(stderr, "- %u\n", curr->val);
#endif
                    curr = curr->next;
                }
            }
        }

        if (d->B != NULL) {
            uint32_t v_id = cache.seen(domain) + 1;
            cache.add(domain, v_id - 1, d, &uint32_t_ll_leading_cache_handler);

            BPT_LEADING(b) = v_id;
        } else {
            free(d);
        }
    }
}