File: bitset.h

package info (click to toggle)
graywolf 0.1.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 6,424 kB
  • sloc: ansic: 84,358; sh: 216; awk: 36; makefile: 22
file content (42 lines) | stat: -rw-r--r-- 932 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef YBITSET_H
#define YBITSET_H

#define BITSET_GET( array, index )    (array[index>>5] & (1 <<(index & 0x1F)))
#define BITSET_SET( array, index )    (array[index>>5] |= (1 << (index & 0x1F)) )
#define BITSET_RESET( array, i )      (array[i>>5] &= (~(1 << (i & 0x1F))) )
#define BITSET_ALLOC( num )           ( YCALLOC( (num>>5) + 1, UNSIGNED_INT) )
#define BITSET_ARRYSIZE( num )        ( (num>>5) + 1 )

#ifdef TEST

main()
{

    unsigned int *array ;
    int i ;
    int max ;

    max = 32 ;

    array = BITSET_ALLOC( max ) ;

    for( i = 0 ; i <= max ; i++ ){
	if( i == 1 || i == 2 || i == 5 || i == 11 || i == 13 || i == 69 ){
	    BITSET_SET( array, i ) ;
	} else {
	    BITSET_RESET( array, i ) ;
	}
    }

    for( i = 0 ; i <= max ; i++ ){
	if( BITSET_GET( array, i ) ){
	    fprintf( stderr, "i:%d T\n", i ) ;
	} else {
	    fprintf( stderr, "i:%d F\n", i ) ;
	}
    }
}

#endif /* TEST */

#endif /* YBITSET_H */