1fb2f18f8Sesaxe /* 2fb2f18f8Sesaxe * CDDL HEADER START 3fb2f18f8Sesaxe * 4fb2f18f8Sesaxe * The contents of this file are subject to the terms of the 5fb2f18f8Sesaxe * Common Development and Distribution License (the "License"). 6fb2f18f8Sesaxe * You may not use this file except in compliance with the License. 7fb2f18f8Sesaxe * 8fb2f18f8Sesaxe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9fb2f18f8Sesaxe * or http://www.opensolaris.org/os/licensing. 10fb2f18f8Sesaxe * See the License for the specific language governing permissions 11fb2f18f8Sesaxe * and limitations under the License. 12fb2f18f8Sesaxe * 13fb2f18f8Sesaxe * When distributing Covered Code, include this CDDL HEADER in each 14fb2f18f8Sesaxe * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15fb2f18f8Sesaxe * If applicable, add the following below this CDDL HEADER, with the 16fb2f18f8Sesaxe * fields enclosed by brackets "[]" replaced with your own identifying 17fb2f18f8Sesaxe * information: Portions Copyright [yyyy] [name of copyright owner] 18fb2f18f8Sesaxe * 19fb2f18f8Sesaxe * CDDL HEADER END 20fb2f18f8Sesaxe */ 21fb2f18f8Sesaxe /* 22*0542eecfSRafael Vanoni * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. 23fb2f18f8Sesaxe */ 24fb2f18f8Sesaxe 25fb2f18f8Sesaxe #ifndef _BITSET_H 26fb2f18f8Sesaxe #define _BITSET_H 27fb2f18f8Sesaxe 28fb2f18f8Sesaxe #ifdef __cplusplus 29fb2f18f8Sesaxe extern "C" { 30fb2f18f8Sesaxe #endif 31fb2f18f8Sesaxe 32fb2f18f8Sesaxe #if (defined(_KERNEL) || defined(_KMEMUSER)) 33fb2f18f8Sesaxe #include <sys/bitmap.h> 34fb2f18f8Sesaxe #include <sys/types.h> 35fb2f18f8Sesaxe 36fb2f18f8Sesaxe typedef struct bitset { 37fb2f18f8Sesaxe ulong_t *bs_set; 38fb2f18f8Sesaxe uint_t bs_words; 39*0542eecfSRafael Vanoni uint_t bs_fanout; 40fb2f18f8Sesaxe } bitset_t; 41fb2f18f8Sesaxe 42fb2f18f8Sesaxe /* 43fb2f18f8Sesaxe * Bitset initialiation / teardown 44fb2f18f8Sesaxe */ 45fb2f18f8Sesaxe void bitset_init(bitset_t *); 46*0542eecfSRafael Vanoni void bitset_init_fanout(bitset_t *, uint_t); 47fb2f18f8Sesaxe void bitset_fini(bitset_t *); 48fb2f18f8Sesaxe 49fb2f18f8Sesaxe /* 50fb2f18f8Sesaxe * Resize / query a bitset's holding capacity 51fb2f18f8Sesaxe */ 52fb2f18f8Sesaxe void bitset_resize(bitset_t *, uint_t); 53fb2f18f8Sesaxe uint_t bitset_capacity(bitset_t *); 54fb2f18f8Sesaxe 55fb2f18f8Sesaxe /* 56fb2f18f8Sesaxe * Set / clear a bit in the set 57fb2f18f8Sesaxe */ 58fb2f18f8Sesaxe void bitset_add(bitset_t *, uint_t); 59fb2f18f8Sesaxe void bitset_del(bitset_t *, uint_t); 60fb2f18f8Sesaxe 61fb2f18f8Sesaxe /* 626890d023SEric Saxe * Atomic operations 636890d023SEric Saxe */ 646890d023SEric Saxe void bitset_atomic_add(bitset_t *, uint_t); 656890d023SEric Saxe void bitset_atomic_del(bitset_t *, uint_t); 666890d023SEric Saxe int bitset_atomic_test_and_add(bitset_t *, uint_t); 676890d023SEric Saxe int bitset_atomic_test_and_del(bitset_t *, uint_t); 686890d023SEric Saxe 696890d023SEric Saxe /* 70fb2f18f8Sesaxe * Bitset queries 71fb2f18f8Sesaxe */ 72fb2f18f8Sesaxe int bitset_in_set(bitset_t *, uint_t); 73fb2f18f8Sesaxe int bitset_is_null(bitset_t *); 74fb2f18f8Sesaxe uint_t bitset_find(bitset_t *); 75fb2f18f8Sesaxe 764c06356bSdh142964 /* 774c06356bSdh142964 * Bitset computations 784c06356bSdh142964 */ 794c06356bSdh142964 int bitset_and(bitset_t *, bitset_t *, bitset_t *); 804c06356bSdh142964 int bitset_or(bitset_t *, bitset_t *, bitset_t *); 814c06356bSdh142964 int bitset_xor(bitset_t *, bitset_t *, bitset_t *); 824c06356bSdh142964 834c06356bSdh142964 /* 844c06356bSdh142964 * Miscellaneous bitset operations 854c06356bSdh142964 */ 864c06356bSdh142964 void bitset_zero(bitset_t *); 874c06356bSdh142964 void bitset_copy(bitset_t *, bitset_t *); 884c06356bSdh142964 int bitset_match(bitset_t *, bitset_t *); 894c06356bSdh142964 90fb2f18f8Sesaxe #endif /* !_KERNEL && !_KMEMUSER */ 91fb2f18f8Sesaxe 92fb2f18f8Sesaxe #ifdef __cplusplus 93fb2f18f8Sesaxe } 94fb2f18f8Sesaxe #endif 95fb2f18f8Sesaxe 96fb2f18f8Sesaxe #endif /* _BITSET_H */ 97