1 | /* $Id: bit_array.h,v 1.1 1999-05-24 20:19:08 ktk Exp $ */
|
---|
2 |
|
---|
3 | /***************************************************************************
|
---|
4 | * Copyright 1995, Technion, Israel Institute of Technology
|
---|
5 | * Electrical Eng, Software Lab.
|
---|
6 | * Author: Michael Veksler.
|
---|
7 | ***************************************************************************
|
---|
8 | * File: bit_array.h
|
---|
9 | * Purpose : manipulate array of bits,
|
---|
10 | * Important: operations may be considered atomic.
|
---|
11 | *
|
---|
12 | ***************************************************************************
|
---|
13 | */
|
---|
14 | #ifndef __WINE_BIT_ARRAY_H
|
---|
15 | #define __WINE_BIT_ARRAY_H
|
---|
16 |
|
---|
17 |
|
---|
18 | #define BITS_PER_BYTE (8)
|
---|
19 | #define BITS_PER_INT (sizeof(int)*BITS_PER_BYTE) /* must be power of 2 */
|
---|
20 |
|
---|
21 | #define BYTE_LOG2 (3)
|
---|
22 | #if defined(INT_LOG2)
|
---|
23 | /* nothing to do, IN_LOG2 is ok */
|
---|
24 | #elif defined(__i386__)
|
---|
25 | # define INT_LOG2 (5)
|
---|
26 | #else
|
---|
27 | # error "Can't find log2 of BITS_PER_INT, please code it manualy"
|
---|
28 | #endif
|
---|
29 |
|
---|
30 |
|
---|
31 | typedef struct bit_array {
|
---|
32 | int bits; /* number of bits in the array */
|
---|
33 | unsigned int *array; /* Actual array data (Never NULL) */
|
---|
34 | } bit_array ;
|
---|
35 |
|
---|
36 | bit_array *AssembleArray(bit_array *new_array, unsigned int *buff, int bits);
|
---|
37 | int ResetArray(bit_array *bits);
|
---|
38 |
|
---|
39 | /* Return index of first free bit, or -1 on failure */
|
---|
40 | int VacantBit(bit_array *bits);
|
---|
41 |
|
---|
42 |
|
---|
43 | /* Return the value of bit 'i' */
|
---|
44 | int SampleBit(bit_array *bits, int i);
|
---|
45 |
|
---|
46 | /* Assign 'val' to a bit no. 'i'. Return: old bit's value */
|
---|
47 | int AssignBit(bit_array *bits, int i, int val);
|
---|
48 |
|
---|
49 | /*
|
---|
50 | ** Allocate a free bit (==0) and make it used (==1).
|
---|
51 | ** Return: allocated bit index, or -1 on failure.
|
---|
52 | */
|
---|
53 | int AllocateBit(bit_array *bits);
|
---|
54 |
|
---|
55 | #endif /* __WINE_BIT_ARRAY_H */
|
---|