[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[patch 5/5] Slightly generalize the case_to_values and case_from_values
From: |
blp |
Subject: |
[patch 5/5] Slightly generalize the case_to_values and case_from_values functions. |
Date: |
Sun, 03 Jun 2007 15:47:16 -0700 |
User-agent: |
quilt/0.45-1 |
The generalized forms are used a bit in later patches. The fastfile
code uses the previous versions of these functions, so we update it;
however, fastfile is deleted in later patches anyhow.
Index: merge/src/data/case.c
===================================================================
--- merge.orig/src/data/case.c 2007-06-03 15:38:01.000000000 -0700
+++ merge/src/data/case.c 2007-06-03 15:42:37.000000000 -0700
@@ -210,35 +210,33 @@
}
}
-/* Copies case C to OUTPUT.
- OUTPUT_SIZE is the number of `union values' in OUTPUT,
- which must match the number of `union values' in C. */
+/* Copies VALUE_CNT values out of case C to VALUES, starting at
+ the given START_IDX. */
void
-case_to_values (const struct ccase *c, union value *output,
- size_t output_size UNUSED)
+case_copy_out (const struct ccase *c,
+ size_t start_idx, union value *values, size_t value_cnt)
{
assert (c->case_data->ref_cnt > 0);
- assert (output_size == c->case_data->value_cnt);
- assert (output != NULL || output_size == 0);
+ assert (value_cnt <= c->case_data->value_cnt);
+ assert (start_idx + value_cnt <= c->case_data->value_cnt);
- memcpy (output, c->case_data->values,
- c->case_data->value_cnt * sizeof *output);
+ memcpy (values, c->case_data->values + start_idx,
+ value_cnt * sizeof *values);
}
-/* Copies INPUT into case C.
- INPUT_SIZE is the number of `union values' in INPUT,
- which must match the number of `union values' in C. */
+/* Copies VALUE_CNT values from VALUES into case C, staring at
+ the given START_IDX. */
void
-case_from_values (struct ccase *c, const union value *input,
- size_t input_size UNUSED)
+case_copy_in (struct ccase *c,
+ size_t start_idx, const union value *values, size_t value_cnt)
{
assert (c->case_data->ref_cnt > 0);
- assert (input_size == c->case_data->value_cnt);
- assert (input != NULL || input_size == 0);
+ assert (value_cnt <= c->case_data->value_cnt);
+ assert (start_idx + value_cnt <= c->case_data->value_cnt);
case_unshare (c);
- memcpy (c->case_data->values, input,
- c->case_data->value_cnt * sizeof *input);
+ memcpy (c->case_data->values + start_idx, values,
+ value_cnt * sizeof *values);
}
/* Returns a pointer to the `union value' used for the
Index: merge/src/data/case.h
===================================================================
--- merge.orig/src/data/case.h 2007-06-03 15:38:01.000000000 -0700
+++ merge/src/data/case.h 2007-06-03 15:41:16.000000000 -0700
@@ -51,12 +51,13 @@
bool case_try_clone (struct ccase *, const struct ccase *);
void case_copy (struct ccase *dst, size_t dst_idx,
- const struct ccase *src, size_t src_idx,
- size_t cnt);
+ const struct ccase *src, size_t src_idx,
+ size_t cnt);
-void case_to_values (const struct ccase *, union value *, size_t);
-void case_from_values (struct ccase *,
- const union value *, size_t);
+void case_copy_out (const struct ccase *,
+ size_t start_idx, union value *, size_t value_cnt);
+void case_copy_in (struct ccase *,
+ size_t start_idx, const union value *, size_t
value_cnt);
const union value *case_data (const struct ccase *, const struct variable *);
double case_num (const struct ccase *, const struct variable *);
Index: merge/src/data/fastfile.c
===================================================================
--- merge.orig/src/data/fastfile.c 2007-06-03 15:38:01.000000000 -0700
+++ merge/src/data/fastfile.c 2007-06-03 15:41:16.000000000 -0700
@@ -246,8 +246,7 @@
ffr->buffer_pos = 0;
}
- case_from_values (&ffr->c, ffr->buffer + ffr->buffer_pos,
- ff->value_cnt);
+ case_copy_in (&ffr->c, 0, ffr->buffer + ffr->buffer_pos, ff->value_cnt);
ffr->buffer_pos += ff->value_cnt;
read_case = &ffr->c;
@@ -645,7 +644,7 @@
if (!ff->ok)
return;
- case_to_values (c, ff->buffer + ff->buffer_used, ff->value_cnt);
+ case_copy_out (c, 0, ff->buffer + ff->buffer_used, ff->value_cnt);
ff->buffer_used += ff->value_cnt;
if (ff->buffer_used + ff->value_cnt > ff->buffer_size)
flush_buffer (ff);
--
- [patch 0/5] more minor simpler-proc changes, blp, 2007/06/03
- [patch 2/5] Add range_set_clone function and corresponding test., blp, 2007/06/03
- [patch 3/5] Cache repeated lookups of a single tower element., blp, 2007/06/03
- [patch 1/5] Add move_range function., blp, 2007/06/03
- [patch 5/5] Slightly generalize the case_to_values and case_from_values functions.,
blp <=
- [patch 4/5] Allow traversing tower nodes in reverse order., blp, 2007/06/03
- Re: [patch 0/5] more minor simpler-proc changes, John Darrington, 2007/06/03