5 #define SIZE (8*sizeof(int)*3)
7 static bit_array array
;
8 static int simple_array
[SIZE
];
14 for (i
=0 ; i
< SIZE
; i
++)
15 if (SampleBit(&array
,i
) != simple_array
[i
]){
16 printf("failed bit %d (packed=%d, simple=%d)\n", i
,
17 SampleBit(&array
,i
), simple_array
[i
]);
26 for (vacant
=0 ; simple_array
[vacant
]!=0 ; vacant
++)
27 if ( vacant
>= SIZE
) {
33 if ( VacantBit(&array
) == vacant
)
38 void assign_both(int bit_nr
, int bit_val
)
40 int old_bit
= simple_array
[bit_nr
];
42 simple_array
[bit_nr
]= bit_val
;
44 bits
+=bit_val
- old_bit
;
46 assert(AssignBit(&array
, bit_nr
, bit_val
) == old_bit
);
48 assert(is_same_vacant());
54 unsigned int integers
[SIZE
>> 5];
57 assert( AssembleArray(&array
, integers
, SIZE
)
60 for (i
=0 ; i
<SIZE
; i
++)
64 printf("\rleft %d\r",j
);
66 for (i
=0 ; VacantBit(&array
) != -1 ; i
++ ) {
69 printf("%3d up \r", bits
);
72 assign_both(rand() % SIZE
,
73 (rand()% SIZE
> bits
) ? 0 : 1 );
76 assign_both(rand() % SIZE
, 1);
78 for (i
=0 ; bits
; i
++ ) {
81 printf("%3d down\r", bits
);
84 assign_both(rand() % SIZE
,
85 (rand()% SIZE
<= (SIZE
-bits
) ) ? 0 : 1 );
88 assign_both(rand() % SIZE
, 0);