git://git.onelab.eu
/
sliver-openvswitch.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
025e874
)
vlan-bitmap: New function vlan_bitmap_from_array__().
author
Ben Pfaff
<blp@nicira.com>
Thu, 10 Nov 2011 00:17:19 +0000
(16:17 -0800)
committer
Ben Pfaff
<blp@nicira.com>
Wed, 23 Nov 2011 23:32:37 +0000
(15:32 -0800)
lib/vlan-bitmap.c
patch
|
blob
|
history
lib/vlan-bitmap.h
patch
|
blob
|
history
diff --git
a/lib/vlan-bitmap.c
b/lib/vlan-bitmap.c
index
94059c7
..
4c5c1eb
100644
(file)
--- a/
lib/vlan-bitmap.c
+++ b/
lib/vlan-bitmap.c
@@
-24,29
+24,39
@@
unsigned long *
vlan_bitmap_from_array(const int64_t *vlans, size_t n_vlans)
{
unsigned long *b;
vlan_bitmap_from_array(const int64_t *vlans, size_t n_vlans)
{
unsigned long *b;
- size_t i, n;
if (!n_vlans) {
return NULL;
}
b = bitmap_allocate(4096);
if (!n_vlans) {
return NULL;
}
b = bitmap_allocate(4096);
+ if (!vlan_bitmap_from_array__(vlans, n_vlans, b)) {
+ free(b);
+ return NULL;
+ }
+ return b;
+}
+
+/* Adds to 4096-bit VLAN bitmap 'b' a 1-bit in each position in the 'n_vlans'
+ * bits indicated in 'vlans'. Returns the number of 1-bits added to 'b'. */
+int
+vlan_bitmap_from_array__(const int64_t *vlans, size_t n_vlans,
+ unsigned long int *b)
+{
+ size_t i;
+ int n;
+
n = 0;
for (i = 0; i < n_vlans; i++) {
int64_t vlan = vlans[i];
n = 0;
for (i = 0; i < n_vlans; i++) {
int64_t vlan = vlans[i];
- if (vlan >= 0 && vlan < 4096) {
+ if (vlan >= 0 && vlan < 4096
&& !bitmap_is_set(b, vlan)
) {
bitmap_set1(b, vlan);
n++;
}
}
bitmap_set1(b, vlan);
n++;
}
}
- if (!n) {
- free(b);
- return NULL;
- }
-
- return b;
+ return n;
}
/* Returns true if 'a' and 'b' are the same: either both null or both the same
}
/* Returns true if 'a' and 'b' are the same: either both null or both the same
diff --git
a/lib/vlan-bitmap.h
b/lib/vlan-bitmap.h
index
092c2ca
..
fed0ba1
100644
(file)
--- a/
lib/vlan-bitmap.h
+++ b/
lib/vlan-bitmap.h
@@
-28,6
+28,9
@@
* This is empirically a useful data structure. */
unsigned long *vlan_bitmap_from_array(const int64_t *vlans, size_t n_vlans);
* This is empirically a useful data structure. */
unsigned long *vlan_bitmap_from_array(const int64_t *vlans, size_t n_vlans);
+int vlan_bitmap_from_array__(const int64_t *vlans, size_t n_vlans,
+ unsigned long int *b);
+
bool vlan_bitmap_equal(const unsigned long *a, const unsigned long *b);
/* Returns a new copy of 'vlans'. */
bool vlan_bitmap_equal(const unsigned long *a, const unsigned long *b);
/* Returns a new copy of 'vlans'. */