<commit_before>/* -MODULE----------------------------------------------------------------------
Phorward Foundation Libraries :: Basis Library
Copyright (C) 2006-2010 by Phorward Software Technologies, <NAME>
http://www.phorward-software.com ++ contact<at>phorward<dash>software<dot>com
All rights reserved. See $PHOME/LICENSE for more information.

File:	bitset.c
Author:	<NAME>
Usage:	Bitset processing library
----------------------------------------------------------------------------- */

/*
 * Includes
 */
#include "pbasis.h"

/*
 * Global variables
 */


/*
 * Functions
 */

/* -FUNCTION--------------------------------------------------------------------
	Function:		bitset_create()
	
	Author:			<NAME>
	
	Usage:			Allocates a new set.
					
	Parameters:		int			size			Number of bits to be accessable
												within the created set.
	
	Returns:		bitset						Pointer to the allocated bitset
												with the given site of bits.
  
	~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Date:		Author:			Note:
----------------------------------------------------------------------------- */
bitset bitset_create( int size )
{
	if( size <= 0 )
		return (bitset)NULL;

	return (bitset)calloc( (size>>3) + (size % 8 ? 2 : 1), 1);
}

/* -FUNCTION--------------------------------------------------------------------
	Function:		bitset_set()
	
	Author:			<NAME>
	
	Usage:			Toggles a bit within a set to a desired state
					(ON or OFF).
					
	Parameters:		bitset		set				Pointer to the set containing
												the bit to be toggled.
					int			bit				The bit which should be switched.
					int			state			State - 0 or 1.
	
	Returns:		int							0 in case of an error, else 1.
  
	~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Date:		Author:			Note:
----------------------------------------------------------------------------- */
int bitset_set( bitset set, int bit, int state )
{
	int idx = ( ( bit>>3 ) );

	if( set == (bitset)NULL || bit < 0 )
		return 0;

	if( state )
		set[idx] |= ( 1 << ( bit % 8 ) );
	else
		set[idx] &= ( 0xFF ^ (1 << ( bit % 8 ) ) );

	return 1;
}

/* -FUNCTION--------------------------------------------------------------------
	Function:		bitset_get()
	
	Author:			<NAME>
	
	Usage:			Returns the state of a desired bit in a set.
					
	Parameters:		bitset		set			Pointer to the set containing
												the bit to be gotten.
					int			bit				The bit which should be checked.
	
	Returns:		int							0 = Bit is not set
												1 = Bit is set
  
	~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Date:		Author:			Note:
----------------------------------------------------------------------------- */
int bitset_get( bitset set, int bit )
{
	return (int)( set[(bit>>3)] & ( 1 << ( bit % 8 ) ) );
}

/* -FUNCTION--------------------------------------------------------------------
	Function:		bitset_copy()
	
	Author:			<NAME>
	
	Usage:			Copies a set.
					
	Parameters:		int			size			Size of the set
					bitset		source			Source set
	
	Returns:		bitset						Pointer to the copy of the set.
  
	~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Date:		Author:			Note:
----------------------------------------------------------------------------- */
bitset bitset_copy( int size, bitset source )
{
	bitset	dest;

	if( !( dest = bitset_create( size ) ) )
		return (bitset)NULL;

	memcpy( dest, source, (size>>3) + (size % 8 ? 2 : 1) );

	return dest;
}

<commit_msg>SCCS bitset.c 11/01/23 23:56:42: Updated Copyright<commit_after>/* -MODULE----------------------------------------------------------------------
Phorward Foundation Libraries :: Basis Library
Copyright (C) 2006-2011 by Phorward Software Technologies, <NAME>
http://www.phorward-software.com ++ contact<at>phorward<dash>software<dot>com
All rights reserved. See $PHOME/LICENSE for more information.

File:	bitset.c
Author:	<NAME>
Usage:	Bitset processing library
----------------------------------------------------------------------------- */

/*
 * Includes
 */
#include "pbasis.h"

/*
 * Global variables
 */


/*
 * Functions
 */

/* -FUNCTION--------------------------------------------------------------------
	Function:		bitset_create()
	
	Author:			<NAME>
	
	Usage:			Allocates a new set.
					
	Parameters:		int			size			Number of bits to be accessable
												within the created set.
	
	Returns:		bitset						Pointer to the allocated bitset
												with the given site of bits.
  
	~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Date:		Author:			Note:
----------------------------------------------------------------------------- */
bitset bitset_create( int size )
{
	if( size <= 0 )
		return (bitset)NULL;

	return (bitset)calloc( (size>>3) + (size % 8 ? 2 : 1), 1);
}

/* -FUNCTION--------------------------------------------------------------------
	Function:		bitset_set()
	
	Author:			<NAME>
	
	Usage:			Toggles a bit within a set to a desired state
					(ON or OFF).
					
	Parameters:		bitset		set				Pointer to the set containing
												the bit to be toggled.
					int			bit				The bit which should be switched.
					int			state			State - 0 or 1.
	
	Returns:		int							0 in case of an error, else 1.
  
	~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Date:		Author:			Note:
----------------------------------------------------------------------------- */
int bitset_set( bitset set, int bit, int state )
{
	int idx = ( ( bit>>3 ) );

	if( set == (bitset)NULL || bit < 0 )
		return 0;

	if( state )
		set[idx] |= ( 1 << ( bit % 8 ) );
	else
		set[idx] &= ( 0xFF ^ (1 << ( bit % 8 ) ) );

	return 1;
}

/* -FUNCTION--------------------------------------------------------------------
	Function:		bitset_get()
	
	Author:			<NAME>
	
	Usage:			Returns the state of a desired bit in a set.
					
	Parameters:		bitset		set			Pointer to the set containing
												the bit to be gotten.
					int			bit				The bit which should be checked.
	
	Returns:		int							0 = Bit is not set
												1 = Bit is set
  
	~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Date:		Author:			Note:
----------------------------------------------------------------------------- */
int bitset_get( bitset set, int bit )
{
	return (int)( set[(bit>>3)] & ( 1 << ( bit % 8 ) ) );
}

/* -FUNCTION--------------------------------------------------------------------
	Function:		bitset_copy()
	
	Author:			<NAME>
	
	Usage:			Copies a set.
					
	Parameters:		int			size			Size of the set
					bitset		source			Source set
	
	Returns:		bitset						Pointer to the copy of the set.
  
	~~~ CHANGES & NOTES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Date:		Author:			Note:
----------------------------------------------------------------------------- */
bitset bitset_copy( int size, bitset source )
{
	bitset	dest;

	if( !( dest = bitset_create( size ) ) )
		return (bitset)NULL;

	memcpy( dest, source, (size>>3) + (size % 8 ? 2 : 1) );

	return dest;
}


{'fraction_non_alphanumeric': 0.3539872971065632, 'fraction_numerical': 0.011856033874382499, 'mean_word_length': 1.3549351944167498, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4184720', 'n_tokens_mistral': 2409, 'n_tokens_neox': 1960, 'n_words': 631}