Path: blob/21.2-virgl/src/gallium/auxiliary/util/u_bitmask.h
4561 views
/**************************************************************************1*2* Copyright 2009 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627/**28* @file29* Generic bitmask.30*31* @author Jose Fonseca <[email protected]>32*/3334#ifndef U_HANDLE_BITMASK_H_35#define U_HANDLE_BITMASK_H_363738#include "pipe/p_compiler.h"394041#ifdef __cplusplus42extern "C" {43#endif444546#define UTIL_BITMASK_INVALID_INDEX (~0U)474849/**50* Abstract data type to represent arbitrary set of bits.51*/52struct util_bitmask;535455struct util_bitmask *56util_bitmask_create(void);575859/**60* Search a cleared bit and set it.61*62* It searches for the first cleared bit.63*64* Returns the bit index on success, or UTIL_BITMASK_INVALID_INDEX on out of65* memory growing the bitmask.66*/67unsigned68util_bitmask_add(struct util_bitmask *bm);6970/**71* Set a bit.72*73* Returns the input index on success, or UTIL_BITMASK_INVALID_INDEX on out of74* memory growing the bitmask.75*/76unsigned77util_bitmask_set(struct util_bitmask *bm,78unsigned index);7980void81util_bitmask_clear(struct util_bitmask *bm,82unsigned index);8384boolean85util_bitmask_get(struct util_bitmask *bm,86unsigned index);878889void90util_bitmask_destroy(struct util_bitmask *bm);919293/**94* Search for the first set bit.95*96* Returns UTIL_BITMASK_INVALID_INDEX if a set bit cannot be found.97*/98unsigned99util_bitmask_get_first_index(struct util_bitmask *bm);100101102/**103* Search for the first set bit, starting from the giving index.104*105* Returns UTIL_BITMASK_INVALID_INDEX if a set bit cannot be found.106*/107unsigned108util_bitmask_get_next_index(struct util_bitmask *bm,109unsigned index);110111112#ifdef __cplusplus113}114#endif115116#endif /* U_HANDLE_BITMASK_H_ */117118119