Blame Esm/ib/include/cs_bitset.h

Packit 857059
/* BEGIN_ICS_COPYRIGHT2 ****************************************
Packit 857059
Packit 857059
Copyright (c) 2015-2017, Intel Corporation
Packit 857059
Packit 857059
Redistribution and use in source and binary forms, with or without
Packit 857059
modification, are permitted provided that the following conditions are met:
Packit 857059
Packit 857059
    * Redistributions of source code must retain the above copyright notice,
Packit 857059
      this list of conditions and the following disclaimer.
Packit 857059
    * Redistributions in binary form must reproduce the above copyright
Packit 857059
      notice, this list of conditions and the following disclaimer in the
Packit 857059
      documentation and/or other materials provided with the distribution.
Packit 857059
    * Neither the name of Intel Corporation nor the names of its contributors
Packit 857059
      may be used to endorse or promote products derived from this software
Packit 857059
      without specific prior written permission.
Packit 857059
Packit 857059
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit 857059
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit 857059
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Packit 857059
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
Packit 857059
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit 857059
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Packit 857059
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Packit 857059
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Packit 857059
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit 857059
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit 857059
Packit 857059
 * ** END_ICS_COPYRIGHT2   ****************************************/
Packit 857059
Packit 857059
//===========================================================================//
Packit 857059
//
Packit 857059
// FILE NAME							
Packit 857059
//    cs_bitset.h					
Packit 857059
//
Packit 857059
// DESCRIPTION					
Packit 857059
//    Implement a generic bitset structure.
Packit 857059
//				
Packit 857059
// DATA STRUCTURES
Packit 857059
//    None
Packit 857059
//
Packit 857059
// FUNCTIONS
Packit 857059
//    None
Packit 857059
//
Packit 857059
// DEPENDENCIES
Packit 857059
//    None
Packit 857059
//
Packit 857059
//									  
Packit 857059
//===========================================================================//
Packit 857059
Packit 857059
#ifndef	_CS_BITSET_H_
Packit 857059
#define	_CS_BITSET_H_
Packit 857059
Packit 857059
#include <stdio.h>
Packit 857059
#include <signal.h>
Packit 857059
#include "vs_g.h"
Packit 857059
#include "ib_const.h"
Packit 857059
#include "ib_types.h"
Packit 857059
Packit 857059
typedef struct {
Packit 857059
	size_t nwords_m;
Packit 857059
	size_t nbits_m;
Packit 857059
	uint32_t *bits_m;
Packit 857059
	size_t nset_m;
Packit 857059
	Pool_t* pool_m;
Packit 857059
} bitset_t;
Packit 857059
Packit 857059
/* Initialize a bitset struct large enough to hold nbits. */
Packit 857059
int bitset_init(Pool_t *, bitset_t *, size_t nbits);
Packit 857059
Packit 857059
/* Like bitset_init() only the bitset_t is assumed to be valid when
Packit 857059
   called, so the existing memory used by the bitset if freed after
Packit 857059
   the bitset is resized */
Packit 857059
int bitset_resize(bitset_t *, size_t nbits);
Packit 857059
Packit 857059
/* Destroy a bitset. */
Packit 857059
void bitset_free(bitset_t *);
Packit 857059
Packit 857059
/* Clear all bits (default) */
Packit 857059
void bitset_clear_all(bitset_t *);
Packit 857059
Packit 857059
/* Set all bits */
Packit 857059
void bitset_set_all(bitset_t *);
Packit 857059
Packit 857059
/* Copy one bitset to the other */
Packit 857059
void bitset_copy(bitset_t *, bitset_t *);
Packit 857059
Packit 857059
/* Clear a specific bit (0..nbits-1). Returns -1 on error */
Packit 857059
int bitset_clear(bitset_t *, unsigned bit);
Packit 857059
Packit 857059
/* Set a specific bit, Returns -1 on error */
Packit 857059
int bitset_set(bitset_t *, unsigned bit);
Packit 857059
Packit 857059
/* Test a specific bit. Result is undefined if bit >= nbits() */
Packit 857059
int bitset_equal(bitset_t*, bitset_t*);
Packit 857059
Packit 857059
/* Test a specific bit. Result is undefined if bit >= nbits() */
Packit 857059
int bitset_test(bitset_t *, unsigned bit);
Packit 857059
Packit 857059
/* Find the first one bit. Returns -1 if not found */
Packit 857059
int bitset_find_first_one(bitset_t *);
Packit 857059
Packit 857059
/* Find the next one bit. */
Packit 857059
int bitset_find_next_one(bitset_t *, unsigned bit);
Packit 857059
Packit 857059
/* Find the last one bit. */
Packit 857059
int bitset_find_last_one(bitset_t *);
Packit 857059
Packit 857059
/* Find the first zero bit. Returns -1 if not found */
Packit 857059
int bitset_find_first_zero(bitset_t *);
Packit 857059
Packit 857059
/* Find the next zero bit past the given bit */
Packit 857059
int bitset_find_next_zero(bitset_t *, unsigned bit);
Packit 857059
Packit 857059
/* Returns -1 if not found */
Packit 857059
int bitset_find_last_zero(bitset_t *);
Packit 857059
Packit 857059
/* Return the number of bits in the bitset */
Packit 857059
size_t bitset_nbits(bitset_t *);
Packit 857059
Packit 857059
/* Return the number of one bits in the bitset. */
Packit 857059
size_t bitset_nset(bitset_t *); 
Packit 857059
Packit 857059
/* Returns 1 if logical and of the bitsets has at least one bit set,
Packit 857059
 * returns 0 if bitsets are different sizes or logical and is 0 */
Packit 857059
int bitset_test_intersection(bitset_t * a, bitset_t * b);
Packit 857059
Packit 857059
/* Sets result to the bitwise and of bitsets a and b
Packit 857059
 * Returns the number of bits set in the result
Packit 857059
 * or -1 if the bitsets aren't allocated or differ in size */
Packit 857059
int bitset_set_intersection(bitset_t * a, bitset_t * b, bitset_t * result);
Packit 857059
Packit 857059
/* Display a human readable representation of the bitset.
Packit 857059
   This uses log level INFINI_INFO and should probably only
Packit 857059
   be called under debug mode. */
Packit 857059
void bitset_info_log(bitset_t*, char* prelude);
Packit 857059
Packit 857059
#endif	// _CS_BITSET_H_
Packit 857059
Packit 857059