From: Linda <lindaj@jma3.com>
To: xen-devel@lists.xen.org, Wei Liu <wei.liu2@citrix.com>,
Julien Grall <julien.grall@citrix.com>
Subject: source code
Date: Wed, 01 Apr 2015 10:24:05 -0600 [thread overview]
Message-ID: <551C1BA5.3010104@jma3.com> (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;
}
next reply other threads:[~2015-04-01 16:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-01 16:24 Linda [this message]
2015-04-01 16:30 ` source code Julien Grall
-- strict thread matches above, loose matches on Subject: below --
2017-11-06 13:13 SOURCE CODE Ronak Shah
2017-11-06 23:07 ` carl hansen
2011-10-04 18:11 Source code Sankar
2011-10-04 19:47 ` Gustavo Padovan
2010-09-07 14:27 Source Code Kishore kumar
2010-09-07 14:51 ` Pasi Kärkkäinen
2005-05-19 6:25 Source code ivo
2005-05-19 6:25 ` Sebastian Henschel
2005-05-19 6:25 ` ivo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=551C1BA5.3010104@jma3.com \
--to=lindaj@jma3.com \
--cc=julien.grall@citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.