[Nagios-checkins] SF.net SVN: nagios:[2090] nagioscore/trunk/lib

ageric at users.sourceforge.net ageric at users.sourceforge.net
Sun Aug 26 19:59:50 UTC 2012


Revision: 2090
          http://nagios.svn.sourceforge.net/nagios/?rev=2090&view=rev
Author:   ageric
Date:     2012-08-26 19:59:49 +0000 (Sun, 26 Aug 2012)
Log Message:
-----------
lib/bitmap: Add bitmap_unite()

This function takes the union of two bitmaps but returns the result
in the first bitmap passed. It's incredibly useful when doing dynamic
programming and adding whole sets at a time to the same existing set.

Signed-off-by: Andreas Ericsson <ae at op5.se>

Modified Paths:
--------------
    nagioscore/trunk/lib/bitmap.c
    nagioscore/trunk/lib/bitmap.h

Modified: nagioscore/trunk/lib/bitmap.c
===================================================================
--- nagioscore/trunk/lib/bitmap.c	2012-08-26 19:59:30 UTC (rev 2089)
+++ nagioscore/trunk/lib/bitmap.c	2012-08-26 19:59:49 UTC (rev 2090)
@@ -236,6 +236,20 @@
 	return bm;
 }
 
+bitmap *bitmap_unite(bitmap *res, const bitmap *addme)
+{
+	unsigned int i;
+
+	if (bitmap_size(addme) > bitmap_size(res)) {
+		bitmap_resize(res, bitmap_size(addme));
+	}
+
+	for (i = 0; i < addme->alloc; i++) {
+		res->vector[i] |= addme->vector[i];
+	}
+	return res;
+}
+
 /* 
  * Remove all elements from a that are also in b.
  */

Modified: nagioscore/trunk/lib/bitmap.h
===================================================================
--- nagioscore/trunk/lib/bitmap.h	2012-08-26 19:59:30 UTC (rev 2089)
+++ nagioscore/trunk/lib/bitmap.h	2012-08-26 19:59:49 UTC (rev 2090)
@@ -112,6 +112,14 @@
 extern bitmap *bitmap_union(const bitmap *a, const bitmap *b);
 
 /**
+ * Calculate union of two bitmaps and store result in one of them
+ * @param res The first bitmap
+ * @param addme The bitmap to unite to the first bitmap
+ * @return NULL on errors, res on success
+ */
+extern bitmap *bitmap_unite(bitmap *res, const bitmap *addme);
+
+/**
  * Calculate set difference between two bitmaps
  * The set difference of A / B is defined as all members of A
  * that isn't members of B. Note that parameter ordering matters

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.





More information about the Nagios-commits mailing list