1 /* Copyright (c) 2011 Nicira Networks
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
18 #include "vlan-bitmap.h"
20 /* Allocates and returns a new 4096-bit bitmap that has 1-bit in positions in
21 * the 'n_vlans' bits indicated in 'vlans' and 0-bits everywhere else. Returns
22 * a null pointer if there are no (valid) VLANs in 'vlans'. */
24 vlan_bitmap_from_array(const int64_t *vlans, size_t n_vlans)
33 b = bitmap_allocate(4096);
35 for (i = 0; i < n_vlans; i++) {
36 int64_t vlan = vlans[i];
38 if (vlan >= 0 && vlan < 4096) {
52 /* Returns true if 'a' and 'b' are the same: either both null or both the same
55 * (We assume that a nonnull bitmap is not all 0-bits.) */
57 vlan_bitmap_equal(const unsigned long *a, const unsigned long *b)
59 return (!a && !b) || (a && b && bitmap_equal(a, b, 4096));