aboutsummaryrefslogtreecommitdiff
path: root/lib/vlan-bitmap.h
diff options
context:
space:
mode:
authorBen Pfaff <blp@nicira.com>2011-04-08 13:19:33 -0700
committerBen Pfaff <blp@nicira.com>2011-04-25 17:11:29 -0700
commit0fb7b9156ac7d319a51890630857698ad1877335 (patch)
tree2354a9b660f00b6728b91e40e35a2e9bcb7dc3aa /lib/vlan-bitmap.h
parent08fd19f01b22226e25a5112b13eb951190ea8d00 (diff)
vlan-bitmap: New data structure.
Diffstat (limited to 'lib/vlan-bitmap.h')
-rw-r--r--lib/vlan-bitmap.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/vlan-bitmap.h b/lib/vlan-bitmap.h
new file mode 100644
index 00000000..eca42fea
--- /dev/null
+++ b/lib/vlan-bitmap.h
@@ -0,0 +1,40 @@
+/* Copyright (c) 2011 Nicira Networks
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef VLAN_BITMAP_H
+#define VLAN_BITMAP_H 1
+
+#include <stdbool.h>
+#include <stdint.h>
+#include "bitmap.h"
+
+/* A "VLAN bitmap" is a 4096-bit bitmap that represents a set. A 1-bit
+ * indicates that the respective VLAN is a member of the set, a 0-bit indicates
+ * that it is not. There is one wrinkle: NULL indicates that every VLAN is a
+ * member of the set.
+ *
+ * This is empirically a useful data structure. */
+
+unsigned long *vlan_bitmap_from_array(const int64_t *vlans, size_t n_vlans);
+bool vlan_bitmap_equal(const unsigned long *a, const unsigned long *b);
+
+/* Returns true if 'vid', in the range [0,4095], is a member of 'vlans'. */
+static inline bool
+vlan_bitmap_contains(const unsigned long *vlans, uint16_t vid)
+{
+ return !vlans || bitmap_is_set(vlans, vid);
+}
+
+#endif /* lib/vlan-bitmap.h */