186d7f5d3SJohn Marino /* $NetBSD: bitset.h,v 1.1.1.1 2008/12/22 00:18:36 haad Exp $ */ 286d7f5d3SJohn Marino 386d7f5d3SJohn Marino /* 486d7f5d3SJohn Marino * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. 586d7f5d3SJohn Marino * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. 686d7f5d3SJohn Marino * 786d7f5d3SJohn Marino * This file is part of the device-mapper userspace tools. 886d7f5d3SJohn Marino * 986d7f5d3SJohn Marino * This copyrighted material is made available to anyone wishing to use, 1086d7f5d3SJohn Marino * modify, copy, or redistribute it subject to the terms and conditions 1186d7f5d3SJohn Marino * of the GNU Lesser General Public License v.2.1. 1286d7f5d3SJohn Marino * 1386d7f5d3SJohn Marino * You should have received a copy of the GNU Lesser General Public License 1486d7f5d3SJohn Marino * along with this program; if not, write to the Free Software Foundation, 1586d7f5d3SJohn Marino * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1686d7f5d3SJohn Marino */ 1786d7f5d3SJohn Marino 1886d7f5d3SJohn Marino #ifndef _DM_BITSET_H 1986d7f5d3SJohn Marino #define _DM_BITSET_H 2086d7f5d3SJohn Marino 2186d7f5d3SJohn Marino #include "pool.h" 2286d7f5d3SJohn Marino 2386d7f5d3SJohn Marino #include <limits.h> 2486d7f5d3SJohn Marino 2586d7f5d3SJohn Marino typedef uint32_t *bitset_t; 2686d7f5d3SJohn Marino 2786d7f5d3SJohn Marino bitset_t bitset_create(struct pool *mem, unsigned num_bits); 2886d7f5d3SJohn Marino void bitset_destroy(bitset_t bs); 2986d7f5d3SJohn Marino 3086d7f5d3SJohn Marino void bit_union(bitset_t out, bitset_t in1, bitset_t in2); 3186d7f5d3SJohn Marino int bit_get_first(bitset_t bs); 3286d7f5d3SJohn Marino int bit_get_next(bitset_t bs, int last_bit); 3386d7f5d3SJohn Marino 3486d7f5d3SJohn Marino #define BITS_PER_INT (sizeof(int) * CHAR_BIT) 3586d7f5d3SJohn Marino 3686d7f5d3SJohn Marino #define bit(bs, i) \ 3786d7f5d3SJohn Marino (bs[(i / BITS_PER_INT) + 1] & (0x1 << (i & (BITS_PER_INT - 1)))) 3886d7f5d3SJohn Marino 3986d7f5d3SJohn Marino #define bit_set(bs, i) \ 4086d7f5d3SJohn Marino (bs[(i / BITS_PER_INT) + 1] |= (0x1 << (i & (BITS_PER_INT - 1)))) 4186d7f5d3SJohn Marino 4286d7f5d3SJohn Marino #define bit_clear(bs, i) \ 4386d7f5d3SJohn Marino (bs[(i / BITS_PER_INT) + 1] &= ~(0x1 << (i & (BITS_PER_INT - 1)))) 4486d7f5d3SJohn Marino 4586d7f5d3SJohn Marino #define bit_set_all(bs) \ 4686d7f5d3SJohn Marino memset(bs + 1, -1, ((*bs / BITS_PER_INT) + 1) * sizeof(int)) 4786d7f5d3SJohn Marino 4886d7f5d3SJohn Marino #define bit_clear_all(bs) \ 4986d7f5d3SJohn Marino memset(bs + 1, 0, ((*bs / BITS_PER_INT) + 1) * sizeof(int)) 5086d7f5d3SJohn Marino 5186d7f5d3SJohn Marino #define bit_copy(bs1, bs2) \ 5286d7f5d3SJohn Marino memcpy(bs1 + 1, bs2 + 1, ((*bs1 / BITS_PER_INT) + 1) * sizeof(int)) 5386d7f5d3SJohn Marino 5486d7f5d3SJohn Marino #endif 55