File: bit_array.h

package info (click to toggle)
wine 0.0.980315-1
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 10,136 kB
  • ctags: 26,112
  • sloc: ansic: 156,310; makefile: 1,160; yacc: 807; perl: 655; lex: 555; sh: 304
file content (53 lines) | stat: -rw-r--r-- 1,563 bytes parent folder | download | duplicates (2)
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
43
44
45
46
47
48
49
50
51
52
53
/***************************************************************************
 * Copyright 1995, Technion, Israel Institute of Technology
 * Electrical Eng, Software Lab.
 * Author:    Michael Veksler.
 ***************************************************************************
 * File:      bit_array.h
 * Purpose :  manipulate array of bits,
 * Important: operations may be considered atomic.
 *
 ***************************************************************************
 */
#ifndef __WINE_BIT_ARRAY_H
#define __WINE_BIT_ARRAY_H


#define BITS_PER_BYTE (8)
#define BITS_PER_INT (sizeof(int)*BITS_PER_BYTE) /* must be power of 2 */

#define BYTE_LOG2 (3)
#if defined(INT_LOG2)
/* nothing to do, IN_LOG2 is ok */
#elif defined(__i386__)
#  define INT_LOG2 (5)
#else
#  error "Can't find log2 of BITS_PER_INT, please code it manualy"
#endif


typedef struct bit_array {
	int bits;		   /* number of bits in the array */
	unsigned int *array;	   /* Actual array data (Never NULL) */
} bit_array ;

bit_array *AssembleArray(bit_array *new_array, unsigned int *buff, int bits);
int ResetArray(bit_array *bits);

/* Return index of first free bit, or -1 on failure */
int VacantBit(bit_array *bits);


/* Return the value of bit 'i' */
int SampleBit(bit_array *bits, int i);

/* Assign 'val' to a bit no. 'i'.      Return: old bit's value */
int AssignBit(bit_array *bits, int i, int val);

/*
** Allocate a free bit (==0) and make it used (==1).
** Return: allocated bit index, or -1 on failure.
*/
int AllocateBit(bit_array *bits);

#endif /* __WINE_BIT_ARRAY_H */