X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Fcategoricals.c;h=d8606031c943b0925a1edc953e454693a9d8de8c;hb=1cf8b236bb43257161f2c014b2384aa4709315c9;hp=2ec1dc19100a5caa7219ecdfe4e333e4536e9c00;hpb=6dffb017e700eda7cd5111509042dc8964fff29f;p=pspp-builds.git diff --git a/src/math/categoricals.c b/src/math/categoricals.c index 2ec1dc19..d8606031 100644 --- a/src/math/categoricals.c +++ b/src/math/categoricals.c @@ -440,7 +440,8 @@ categoricals_df (const struct categoricals *cat, size_t n) size_t categoricals_n_total (const struct categoricals *cat) { - assert (cat->reverse_variable_map_long); + if (!categoricals_is_complete (cat)) + return 0; return cat->n_cats_total; } @@ -451,9 +452,16 @@ categoricals_df_total (const struct categoricals *cat) return cat->df_sum; } +bool +categoricals_is_complete (const struct categoricals *cat) +{ + return (NULL != cat->reverse_variable_map_short); +} + + /* This function must be called *before* any call to categoricals_get_*_by subscript and *after* all calls to categoricals_update */ -void +bool categoricals_done (const struct categoricals *cat_) { /* Implementation Note: Whilst this function is O(n) in cat->n_cats_total, in most @@ -486,6 +494,9 @@ 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->iap[i].df_prod[v] = df * (hmap_count (&vn->valmap) - 1); df = cat->iap[i].df_prod[v]; @@ -566,6 +577,8 @@ categoricals_done (const struct categoricals *cat_) } } } + + return true; }