pspp-sheet-view-column: Be consistent about use of !! for booleans.
[pspp] / src / math / categoricals.c
index a7cf3a114624d4de3a9ea5d184a516b85a1700fa..b9748c759ed8f114969728743c84d3880ce033df 100644 (file)
@@ -99,7 +99,7 @@ struct interact_params
   /* A map indexed by a interaction_value */
   struct hmap ivmap;
 
-  const struct interaction *iact;
+  struct interaction *iact;
 
   int base_subscript_short;
   int base_subscript_long;
@@ -174,6 +174,8 @@ struct categoricals
   const void *aux1;
   void *aux2;
 
+  bool sane;
+
   const struct payload *payload;
 };
 
@@ -251,16 +253,15 @@ categoricals_destroy (struct categoricals *cat)
       /* Interate over each interaction value, and unref any cases that we reffed */
       HMAP_FOR_EACH (iv, struct interaction_value, node, &cat->iap[i].ivmap)
        {
-#if 0
-         if (cat->payload)
-           cat->payload->destroy (cat->aux1, iv->user_data);
-#endif
+         if (cat->payload && cat->payload->destroy)
+           cat->payload->destroy (cat->aux1, cat->aux2, iv->user_data);
          case_unref (iv->ccase);
        }
 
       free (cat->iap[i].enc_sum);
       free (cat->iap[i].df_prod);
       hmap_destroy (&cat->iap[i].ivmap);
+      interaction_destroy (cat->iap[i].iact);
     }
 
   /* Interate over each variable and delete its value map */
@@ -295,6 +296,11 @@ lookup_case (const struct hmap *map, const struct interaction *iact, const struc
   return iv;
 }
 
+bool 
+categoricals_sane (const struct categoricals *cat)
+{
+  return cat->sane;
+}
 
 struct categoricals *
 categoricals_create (struct interaction *const*inter, size_t n_inter,
@@ -314,6 +320,7 @@ categoricals_create (struct interaction *const*inter, size_t n_inter,
   cat->fctr_excl = fctr_excl;
   cat->payload = NULL;
   cat->aux2 = NULL;
+  cat->sane = false;
 
   cat->iap = pool_calloc (cat->pool, cat->n_iap, sizeof *cat->iap);
 
@@ -458,7 +465,7 @@ categoricals_is_complete (const struct categoricals *cat)
 
 /* This function must be called *before* any call to categoricals_get_*_by subscript and
  *after* all calls to categoricals_update */
-bool
+void
 categoricals_done (const struct categoricals *cat_)
 {
   /* Implementation Note: Whilst this function is O(n) in cat->n_cats_total, in most
@@ -492,7 +499,10 @@ categoricals_done (const struct categoricals *cat_)
          struct variable_node *vn = lookup_variable (&cat->varmap, var, hash_pointer (var, 0));
 
          if  (hmap_count (&vn->valmap) == 0)
-           return false;
+           {
+             cat->sane = false;
+             return;
+           }
 
          cat->iap[i].df_prod[v] = df * (hmap_count (&vn->valmap) - 1);
          df = cat->iap[i].df_prod[v];
@@ -579,12 +589,12 @@ categoricals_done (const struct categoricals *cat_)
              const double bin = categoricals_get_code_for_case (cat, x, iv->ccase); \
              iap->enc_sum [x - iap->base_subscript_short] += bin * iv->cc;
            }
-         if (cat->payload && cat->payload->destroy)
-           cat->payload->destroy (cat->aux1, cat->aux2, iv->user_data);
+         if (cat->payload && cat->payload->calculate)
+           cat->payload->calculate (cat->aux1, cat->aux2, iv->user_data);
        }
     }
 
-  return true;
+  cat->sane = true;
 }