Skip to contentSkip to conversation

source code

DISCUSSION Linda 2 participants 2 messages Apr 1, 2015

lore
Share & tools
lore

Linda

author
#0 lore raw

Hi all,

The following functions should compute the union, intersection and
difference of two bitmaps.
Please review the code. Thank you.

Sincerely,

Linda Jacobson

int libxl_bitmap_union(libxl_ctx *ctx, libxl_bitmap *union_bitmap, libxl_bitmap *bitmap1, libxl_bitmap *bitmap2)

{
    int size;
    int rc;

    GC_INIT(ctx);

// if bitmaps aren't the same size, union should be size of larger bit map

    size = (bitmap1->size > bitmap2->size) ? bitmap1->size : bitmap2->size;

    libxl_bitmap_init(union_bitmap);
    rc = libxl_bitmap_alloc(ctx, union_bitmap, size);
    if (rc)
    {
        // I'm following the coding standards here.  First goto I've 
written in decades.
        goto out;
    }

    for (int bit = 0; bit < (size * 8); bit++)
    {
        // libxl_bitmap_test returns 0 if past end of bitmap
        // if the bit is set in either bitmap, set it in their union
        if (libxl_bitmap_test(bitmap1, bit))
        {
            libxl_bitmap_set(union_bitmap, bit);
        }
        else if (libxl_bitmap_test(bitmap2, bit))
        {
            libxl_bitmap_set(union_bitmap, bit);
        }
    }

out:

    GC_FREE;
    return rc;
}

int libxl_bitmap_intersection (libxl_ctx *ctx, libxl_bitmap *union_bitmap, libxl_bitmap *bitmap1, libxl_bitmap *bitmap2)

{
    int size;
    int rc;

    GC_INIT(ctx);

// if bitmaps aren't the same size, intersection should be size of smaller bit map

    size = (bitmap1->size > bitmap2->size) ? bitmap2->size : bitmap1->size;

    libxl_bitmap_init(union_bitmap);
    rc = libxl_bitmap_alloc(ctx, union_bitmap, size);
    if (rc)
    {
        goto out;
    }

    for (int bit = 0; bit < (size * 8); bit++)
    {
        // libxl_bitmap_test returns 0 if past end of bitmap
        // if the bit is set in both bitmaps, set it in their intersection
        if (libxl_bitmap_test (bitmap1, bit) && libxl_bitmap_test 
(bitmap2, bit) )
        {
            libxl_bitmap_set (intersection_bitmap, bit);
        }
    }

out:

    GC_FREE;
    return rc;
}
int libxl_bitmap_difference(libxl_ctx *ctx, libxl_bitmap *union_bitmap, libxl_bitmap *bitmap1, libxl_bitmap *bitmap2)
{
    int size;
    int rc;

    GC_INIT(ctx);

// if bitmaps aren't the same size, difference should be size of larger bit map

    size = (bitmap1->size > bitmap2->size) ? bitmap1->size : bitmap2->size;

    libxl_bitmap_init(union_bitmap);
    rc = libxl_bitmap_alloc(ctx, union_bitmap, size);
    if (rc)
    {
        goto out;
    }

    for (int bit = 0; bit < (size * 8); bit++)
    {
        /* libxl_bitmap_test returns 0 if past end of bitmap
         if the bit is set in one bitmap and not the other, set it in 
their difference
        NOTE:  if one bit map is larger, this will result in all bits 
being set past the size of the smaller bitmap;  if this is not
        the desired behavior, please let me know
        */

        if (libxl_bitmap_test (bitmap1, bit) && (!libxl_bitmap_test 
(bitmap2, bit)) )
        {
            libxl_bitmap_set (difference_bitmap, bit);
        }
    }

out:

    GC_FREE;
    return rc;
}
#1 lore raw
Quoted 1 line · Linda

Hi all,

Hello Linda,

Quoted 3 lines

The following functions should compute the union, intersection and
difference of two bitmaps.
Please review the code. Thank you.

There is a specific process in order to create/send the patch. You can read it on the wiki:

http://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches

Please resend the patch.

Quoted 1 line

Sincerely,

Regards,

Signature · 1 line
Julien Grall