const struct caseproto *proto UNUSED)
{
struct casewindow_memory *cwm = xmalloc (sizeof *cwm);
- cwm->cases = deque_init (&cwm->deque, 4, sizeof *cwm->cases);
+ *cwm = (struct casewindow_memory) { .deque = DEQUE_EMPTY_INITIALIZER };
return cwm;
}
#include "gl/minmax.h"
#include "gl/xalloc.h"
-/* Initializes DEQUE as an empty deque with an initial capacity
- of zero. */
-void
-deque_init_null (struct deque *deque)
-{
- deque->capacity = 0;
- deque->front = 0;
- deque->back = 0;
-}
-
/* Initializes DEQUE as an empty deque of elements ELEM_SIZE
bytes in size, with an initial capacity of at least
CAPACITY. Returns the initial deque data array. */
deque_init (struct deque *deque, size_t capacity, size_t elem_size)
{
void *data = NULL;
- deque_init_null (deque);
+ *deque = (struct deque) DEQUE_EMPTY_INITIALIZER;
if (capacity > 0)
{
deque->capacity = 1;
/* Deque data structure.
- This code slightly simplifies the implementation of a deque as
- a circular queue. To use it, declare a "struct deque" and a
- pointer to the element type. For example, for a deque of
- "int"s:
+ This code slightly simplifies the implementation of a deque as a circular
+ queue. To use it, declare a "struct deque" and a pointer to the element
+ type. For example, for deque of "int"s with an initial capacity of 0:
- struct deque deque;
- int *data;
-
- To initialize the deque with a initial capacity of 0:
-
- deque_init_null (&deque);
- data = NULL;
+ struct deque deque = DEQUE_EMPTY_INITIALIZER;
+ int *data = NULL;
Alternatively, to initialize the deque with an initial minimum
capacity of, e.g., 4:
- data = deque_init (&deque, 4, sizeof *data);
+ struct deque deque;
+ int *data = deque_init (&deque, 4, sizeof *data);
Functions that access elements in the deque return array
indexes. This is fairly convenient:
size_t front; /* One past the front of the queue. */
size_t back; /* The back of the queue. */
};
+#define DEQUE_EMPTY_INITIALIZER { .capacity = 0 }
-void deque_init_null (struct deque *);
void *deque_init (struct deque *, size_t capacity, size_t elem_size);
void *deque_expand (struct deque *, void *, size_t elem_size);
}
/* Initialize MC. */
- mc->class = class;
- mc->options = options;
- mc->results = mc_results_create ();
-
- mc->hash = (mc->options->hash_bits > 0
- ? bitvector_allocate (1 << mc->options->hash_bits)
- : NULL);
-
- mc->queue = NULL;
- deque_init_null (&mc->queue_deque);
-
- mc_path_init (&mc->path);
- mc_path_push (&mc->path, 0);
- ds_init_empty (&mc->path_string);
- mc->state_named = false;
- mc->state_error = false;
-
- mc->progress = 0;
- mc->next_progress = mc->options->progress_usec != 0 ? 100 : UINT_MAX;
- mc->prev_progress = 0;
- mc->prev_progress_time = mc->results->start;
+ struct mc_results *results = mc_results_create ();
+ *mc = (struct mc) {
+ .class = class,
+ .options = options,
+ .results = results,
+ .hash = (options->hash_bits > 0
+ ? bitvector_allocate (1 << options->hash_bits)
+ : NULL),
+ .queue_deque = DEQUE_EMPTY_INITIALIZER,
+ .path = MC_PATH_EMPTY_INITIALIZER,
+ .path_string = DS_EMPTY_INITIALIZER,
+ .next_progress = options->progress_usec != 0 ? 100 : UINT_MAX,
+ .prev_progress_time = results->start,
+ .saved_interrupted_ptr = interrupted_ptr,
+ .saved_sigint = signal (SIGINT, sigint_handler),
+ };
- if (mc->options->strategy == MC_RANDOM
+ interrupted_ptr = &mc->interrupted;
+ if (options->strategy == MC_RANDOM
|| options->queue_limit_strategy == MC_DROP_RANDOM)
- srand (mc->options->seed);
+ srand (options->seed);
- mc->interrupted = false;
- mc->saved_interrupted_ptr = interrupted_ptr;
- interrupted_ptr = &mc->interrupted;
- mc->saved_sigint = signal (SIGINT, sigint_handler);
+ mc_path_push (&mc->path, 0);
class->init (mc);
}
size_t length; /* Number of operations. */
size_t capacity; /* Number of operations for which room is allocated. */
};
+#define MC_PATH_EMPTY_INITIALIZER { .ops = NULL }
void mc_path_init (struct mc_path *);
void mc_path_copy (struct mc_path *, const struct mc_path *);