1 #ifndef CGPERF_BOOL_ARRAY_C
2 #define CGPERF_BOOL_ARRAY_C
9 #include "bool-array.h"
10 /*------------------------------------------------------------------------------------------------*/
11 #include "namespace/globals.h"
12 #include "namespace/options.h"
13 #include "namespace/bool-array.h"
14 /*------------------------------------------------------------------------------------------------*/
16 static struct Bool_Array
*ba_new(u32 size
)
20 t
= calloc(1, sizeof(*t
));
22 t
->iteration_number
= 1;
23 t
->storage_array
= calloc(size
, sizeof(*(t
->storage_array
)));
25 fprintf (stderr
, "\nbool array size = %d, total bytes = %d\n", t
->size
, (u32
)(t
->size
* sizeof(t
->storage_array
[0])));
29 static void ba_del(struct Bool_Array
*t
)
32 fprintf(stderr
, "\ndumping boolean array information\nsize = %d\niteration number = %d\nend of array dump\n", t
->size
, t
->iteration_number
);
33 free(t
->storage_array
);
37 /* resets all bits to zero */
38 static void ba_clear(struct Bool_Array
*t
)
41 * If we wrap around it's time to zero things out again! However, this only occurs once
42 * about every 2^32 iterations, so it will not happen more frequently than once per second.
44 ++(t
->iteration_number
);
45 if (t
->iteration_number
== 0) {
46 t
->iteration_number
= 1;
47 memset(t
->storage_array
, 0, t
->size
* sizeof(*(t
->storage_array
)));
49 fprintf(stderr
, "(re-initialized bool_array)\n");
56 * Sets the specified bit to true.
57 * Returns its previous value (false or true).
59 static bool ba_set_bit(struct Bool_Array
*t
, u32 index
)
61 if (t
->storage_array
[index
] == t
->iteration_number
)
62 /* the bit was set since the last clear() call */
65 /* the last operation on this bit was clear(). Set it now. */
66 t
->storage_array
[index
] = t
->iteration_number
;
70 /*------------------------------------------------------------------------------------------------*/
72 #include "namespace/globals.h"
73 #include "namespace/options.h"
74 #include "namespace/bool-array.h"
76 /*------------------------------------------------------------------------------------------------*/