deque: Replace deque_init_null() by DEQUE_EMPTY_INITIALIZER.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 29 May 2023 20:21:07 +0000 (13:21 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 29 May 2023 20:23:18 +0000 (13:23 -0700)
src/data/casewindow.c
src/libpspp/deque.c
src/libpspp/deque.h
src/libpspp/model-checker.c
src/libpspp/model-checker.h

index 6277c4402da218d6fac2c6488ff98f890ef63dbe..763ceb2c41e9f1bfc5f0d7ad954b7617c93fee90 100644 (file)
@@ -226,7 +226,7 @@ casewindow_memory_create (struct taint *taint UNUSED,
                           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;
 }
 
index a511cf3ad0e2a10b860dfe65896dc03ef6ab7418..6c8e5193791de7701d246b747052c945f317c2a3 100644 (file)
 #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. */
@@ -40,7 +30,7 @@ void *
 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;
index 151308013cf560a72cd31f670f144d1a97f53297..d5c26e89140e9019d30e8b206b2fa0d9352abf39 100644 (file)
 
 /* 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:
@@ -75,8 +70,8 @@ struct deque
     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);
 
index ee13422a046cad95519c405042e63003065db716..801bfda769f9c456e68cb3d4b7ab771f254c687a 100644 (file)
@@ -1683,36 +1683,29 @@ init_mc (struct mc *mc, const struct mc_class *class,
     }
 
   /* 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);
 }
index be97d389bcc7219c8dd325e02900f829b2082077..b0edd147aa11034d7a5d18e8606208747eb983b7 100644 (file)
@@ -344,6 +344,7 @@ struct mc_path
     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 *);