X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fcaseproto.h;h=e6921888f58baf7e12332810f241f2ac0cc60b42;hb=refs%2Fheads%2Fctables7;hp=b0f45c418c47aae8017b0469a5307cff6b9cd7f6;hpb=cb586666724d5fcbdb658ce471b85484f0a7babe;p=pspp diff --git a/src/data/caseproto.h b/src/data/caseproto.h index b0f45c418c..e6921888f5 100644 --- a/src/data/caseproto.h +++ b/src/data/caseproto.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2009 Free Software Foundation, Inc. + Copyright (C) 2009, 2011 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,9 +21,10 @@ #include #include #include -#include -#include -#include + +#include "data/value.h" +#include "libpspp/cast.h" +#include "libpspp/compiler.h" /* Case prototype. @@ -63,11 +64,10 @@ struct caseproto { size_t ref_cnt; /* Reference count. */ - /* Tracking of long string widths. Lazily maintained: when - 'long_strings' is null and 'n_long_strings' is nonzero, - the former must be regenerated. */ - size_t *long_strings; /* Array of indexes of long string widths. */ - size_t n_long_strings; /* Number of long string widths. */ + /* Tracking of string widths. Lazily maintained: when 'strings' is null + and 'n_strings' is nonzero, the former must be regenerated. */ + size_t *strings; /* Array of indexes of string widths. */ + size_t n_strings; /* Number of string widths. */ /* Widths. */ size_t n_widths; /* Number of widths. */ @@ -79,8 +79,8 @@ struct pool; /* Creation and destruction. */ struct caseproto *caseproto_create (void) MALLOC_LIKE; -static inline struct caseproto *caseproto_ref (const struct caseproto *); -struct caseproto *caseproto_ref_pool (const struct caseproto *, struct pool *); +static inline struct caseproto *caseproto_ref (const struct caseproto *) WARN_UNUSED_RESULT; +struct caseproto *caseproto_ref_pool (const struct caseproto *, struct pool *) WARN_UNUSED_RESULT; static inline void caseproto_unref (struct caseproto *); /* Inspecting stored widths. */ @@ -99,11 +99,11 @@ struct caseproto *caseproto_insert_width (struct caseproto *, size_t before, int width) WARN_UNUSED_RESULT; struct caseproto *caseproto_remove_widths (struct caseproto *, - size_t idx, size_t cnt) + size_t idx, size_t n) WARN_UNUSED_RESULT; struct caseproto *caseproto_move_widths (struct caseproto *, size_t old_start, size_t new_start, - size_t cnt) + size_t n) WARN_UNUSED_RESULT; /* Working with "union value" arrays. */ @@ -117,14 +117,13 @@ void caseproto_destroy_values (const struct caseproto *, union value[]); void caseproto_copy (const struct caseproto *, size_t idx, size_t count, union value *dst, const union value *src); -/* Inspecting the cache of long string widths. +/* Inspecting the cache of string widths. - (These functions are useful for allocating cases, which - requires allocating a block memory for each long string value - in the case.) */ -static inline size_t caseproto_get_n_long_strings (const struct caseproto *); -static inline size_t caseproto_get_long_string_idx (const struct caseproto *, - size_t idx1); + (These functions are useful for allocating cases, which requires allocating + a block of memory for each string value in the case.) */ +static inline size_t caseproto_get_n_strings (const struct caseproto *); +static inline size_t caseproto_get_string_idx (const struct caseproto *, + size_t idx1); /* For use in assertions. */ bool caseproto_range_is_valid (const struct caseproto *, @@ -157,7 +156,7 @@ caseproto_ref (const struct caseproto *proto_) static inline void caseproto_unref (struct caseproto *proto) { - if (proto != NULL && !--proto->ref_cnt) + if (proto != NULL && --proto->ref_cnt == 0) caseproto_free__ (proto); } @@ -181,30 +180,27 @@ caseproto_get_n_widths (const struct caseproto *proto) /* Inspecting the cache of long string widths. */ -void caseproto_refresh_long_string_cache__ (const struct caseproto *); +void caseproto_refresh_string_cache__ (const struct caseproto *); -/* Returns the number of long string widths in PROTO; that is, - the number of widths in PROTO that are greater than to - MAX_SHORT_STRING. */ +/* Returns the number of strings in PROTO. */ static inline size_t -caseproto_get_n_long_strings (const struct caseproto *proto) +caseproto_get_n_strings (const struct caseproto *proto) { - return proto->n_long_strings; + return proto->n_strings; } -/* Given long string width IDX1, returns a value IDX2 for which - caseproto_get_width(PROTO, IDX2) will return a value greater - than MAX_SHORT_STRING. IDX1 must be less than - caseproto_get_n_long_strings(PROTO), and IDX2 will be less - than caseproto_get_n_widths(PROTO). */ +/* Given string width IDX1, returns a value IDX2 for which + caseproto_get_width(PROTO, IDX2) will return a value greater than 0. IDX1 + must be less than caseproto_get_n_strings(PROTO), and IDX2 will be less than + caseproto_get_n_widths(PROTO). */ static inline size_t -caseproto_get_long_string_idx (const struct caseproto *proto, size_t idx1) +caseproto_get_string_idx (const struct caseproto *proto, size_t idx1) { - if (proto->long_strings == NULL) - caseproto_refresh_long_string_cache__ (proto); + if (proto->strings == NULL) + caseproto_refresh_string_cache__ (proto); - assert (idx1 < proto->n_long_strings); - return proto->long_strings[idx1]; + assert (idx1 < proto->n_strings); + return proto->strings[idx1]; } #endif /* data/caseproto.h */