X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fvalue.h;h=f9782e2d867d47028f134c4b406dbfd53313d68c;hb=8f04b0ced35a66cfdebefbcb53c81979add36ca3;hp=8f1746337ea37ceaefa3523fa73ff0c2666b63f8;hpb=5c3291dc396b795696e94f47780308fd7ace6fc4;p=pspp-builds.git diff --git a/src/data/value.h b/src/data/value.h index 8f174633..f9782e2d 100644 --- a/src/data/value.h +++ b/src/data/value.h @@ -20,11 +20,16 @@ #include #include #include +#include #include #include "xalloc.h" +/* Maximum length of a "short" string, that is represented in + "union value" without a separate pointer. + + This is an implementation detail of the "union value" code. + There is little reason for client code to use it. */ #define MAX_SHORT_STRING 8 -#define MIN_LONG_STRING (MAX_SHORT_STRING + 1) /* A numeric or string value. @@ -41,8 +46,8 @@ union value { double f; - char short_string[MAX_SHORT_STRING]; - char *long_string; + uint8_t short_string[MAX_SHORT_STRING]; + uint8_t *long_string; }; static inline void value_init (union value *, int width); @@ -51,29 +56,28 @@ static inline bool value_try_init (union value *, int width); static inline void value_destroy (union value *, int width); static inline double value_num (const union value *); -static inline const char *value_str (const union value *, int width); -static inline char *value_str_rw (union value *, int width); - -int compare_values (const void *, const void *, const void *var); -unsigned hash_value (const void *, const void *var); +static inline const uint8_t *value_str (const union value *, int width); +static inline uint8_t *value_str_rw (union value *, int width); static inline void value_copy (union value *, const union value *, int width); void value_copy_rpad (union value *, int dst_width, const union value *, int src_width, char pad); -void value_copy_str_rpad (union value *, int dst_width, const char *, +void value_copy_str_rpad (union value *, int dst_width, const uint8_t *, char pad); void value_copy_buf_rpad (union value *dst, int dst_width, - const char *src, size_t src_len, char pad); + const uint8_t *src, size_t src_len, char pad); void value_set_missing (union value *, int width); int value_compare_3way (const union value *, const union value *, int width); bool value_equal (const union value *, const union value *, int width); -size_t value_hash (const union value *, int width, unsigned int basis); +unsigned int value_hash (const union value *, int width, unsigned int basis); bool value_is_resizable (const union value *, int old_width, int new_width); bool value_needs_resize (int old_width, int new_width); void value_resize (union value *, int old_width, int new_width); +static inline void value_swap (union value *, union value *); + struct pool; void value_init_pool (struct pool *, union value *, int width); void value_resize_pool (struct pool *, union value *, @@ -144,11 +148,11 @@ value_num (const union value *v) It is important that WIDTH be the actual value that was passed to value_init. Passing, e.g., a smaller value because only that number of bytes will be accessed will not always work. */ -static inline const char * +static inline const uint8_t * value_str (const union value *v, int width) { assert (width > 0); - return (width >= MIN_LONG_STRING ? v->long_string : v->short_string); + return (width > MAX_SHORT_STRING ? v->long_string : v->short_string); } /* Returns the string value in V, which must have width WIDTH. @@ -158,11 +162,11 @@ value_str (const union value *v, int width) It is important that WIDTH be the actual value that was passed to value_init. Passing, e.g., a smaller value because only that number of bytes will be accessed will not always work. */ -static inline char * +static inline uint8_t * value_str_rw (union value *v, int width) { assert (width > 0); - return (width >= MIN_LONG_STRING ? v->long_string : v->short_string); + return (width > MAX_SHORT_STRING ? v->long_string : v->short_string); } /* Copies SRC to DST, given that they both contain data of the @@ -176,4 +180,13 @@ value_copy (union value *dst, const union value *src, int width) memcpy (dst->long_string, src->long_string, width); } +/* Exchanges the contents of A and B. */ +static inline void +value_swap (union value *a, union value *b) +{ + union value tmp = *a; + *a = *b; + *b = tmp; +} + #endif /* data/value.h */