]> git.proxmox.com Git - mirror_ovs.git/blame - lib/bitmap.c
svec: New function svec_split().
[mirror_ovs.git] / lib / bitmap.c
CommitLineData
064af421
BP
1/*
2 * Copyright (c) 2008 Nicira Networks.
3 *
a14bc59f
BP
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
064af421 7 *
a14bc59f
BP
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
064af421
BP
15 */
16
17#include <config.h>
18#include "bitmap.h"
19#include <string.h>
20
21/* Sets 'count' consecutive bits in 'bitmap', starting at bit offset 'start',
22 * to 'value'. */
23void
24bitmap_set_multiple(unsigned long *bitmap, size_t start, size_t count,
25 bool value)
26{
27 for (; count && start % BITMAP_ULONG_BITS; count--) {
28 bitmap_set(bitmap, start++, value);
29 }
30 for (; count >= BITMAP_ULONG_BITS; count -= BITMAP_ULONG_BITS) {
31 *bitmap_unit__(bitmap, start) = -(unsigned long) value;
32 start += BITMAP_ULONG_BITS;
33 }
34 for (; count; count--) {
35 bitmap_set(bitmap, start++, value);
36 }
37}
38
39/* Compares the 'n' bits in bitmaps 'a' and 'b'. Returns true if all bits are
40 * equal, false otherwise. */
41bool
42bitmap_equal(const unsigned long *a, const unsigned long *b, size_t n)
43{
44 size_t i;
45
46 if (memcmp(a, b, n / BITMAP_ULONG_BITS * sizeof(unsigned long))) {
47 return false;
48 }
49 for (i = ROUND_DOWN(n, BITMAP_ULONG_BITS); i < n; i++) {
50 if (bitmap_is_set(a, i) != bitmap_is_set(b, i)) {
51 return false;
52 }
53 }
54 return true;
55}