+Sat May 6 15:36:59 2006 Ben Pfaff <blp@gnu.org>
+
+ Make dictionary compacting functions a little more general.
+
+ * sys-file-writer.c (sfm_open_writer): Use
+ dict_compacting_would_change().
+ (does_dict_need_translation) Removed.
+
+Sat May 6 15:35:42 2006 Ben Pfaff <blp@gnu.org>
+
+ Make dictionary compacting functions a little more general.
+
+ * dictionary.c (dict_needs_compaction): Rename
+ dict_compacting_would_shrink(). Update all callers.
+ (dict_compacting_would_change) New function.
+
Sat May 6 14:25:49 2006 Ben Pfaff <blp@gnu.org>
* sys-file-writer.c: (does_dict_need_translation) Fix bug:
}
/* Returns true if a case for dictionary D would be smaller after
- compaction, false otherwise. Compacting a case eliminates
+ compacting, false otherwise. Compacting a case eliminates
"holes" between values and after the last value. Holes are
created by deleting variables (or by scratch variables).
The return value may differ from whether compacting a case
- from dictionary D would *change* the case: compaction could
+ from dictionary D would *change* the case: compacting could
rearrange values even if it didn't reduce space
requirements. */
bool
-dict_needs_compaction (const struct dictionary *d)
+dict_compacting_would_shrink (const struct dictionary *d)
{
return dict_get_compacted_value_cnt (d) < dict_get_next_value_idx (d);
}
+
+/* Returns true if a case for dictionary D would be smaller after
+ compacting, false otherwise. Compacting a case eliminates
+ "holes" between values and after the last value. Holes are
+ created by deleting variables (or by scratch variables).
+
+ The return value may differ from whether compacting a case
+ from dictionary D would *shrink* the case: compacting could
+ rearrange values without reducing space requirements. */
+bool
+dict_compacting_would_change (const struct dictionary *d)
+{
+ size_t case_idx;
+ size_t i;
+
+ case_idx = 0;
+ for (i = 0; i < dict_get_var_cnt (d); i++)
+ {
+ struct variable *v = dict_get_var (d, i);
+ if (v->fv != case_idx)
+ return true;
+ case_idx += v->nv;
+ }
+ return false;
+}
\f
/* How to copy a contiguous range of values between cases. */
struct copy_map
void dict_compact_values (struct dictionary *);
size_t dict_get_compacted_value_cnt (const struct dictionary *);
int *dict_get_compacted_idx_to_fv (const struct dictionary *);
-bool dict_needs_compaction (const struct dictionary *);
+bool dict_compacting_would_shrink (const struct dictionary *);
+bool dict_compacting_would_change (const struct dictionary *);
struct dict_compactor *dict_make_compactor (const struct dictionary *);
void dict_compactor_compact (const struct dict_compactor *,
struct ccase trns_case; /* Case used for transformations. */
struct ccase sink_case; /* Case written to sink, if
- compaction is necessary. */
+ compacting is necessary. */
size_t cases_written; /* Cases output so far. */
};
if (permanent_dict == NULL)
permanent_dict = default_dict;
- /* Figure out compaction. */
- compactor = (dict_needs_compaction (permanent_dict)
+ /* Figure out whether to compact. */
+ compactor = (dict_compacting_would_shrink (permanent_dict)
? dict_make_compactor (permanent_dict)
: NULL);
/* Dictionary from before TEMPORARY becomes permanent. */
proc_cancel_temporary_transformations ();
- /* Finish compaction. */
+ /* Finish compacting. */
if (compactor != NULL)
{
dict_compactor_destroy (compactor);
/* Copy the dictionary and compact if needed. */
scratch_dict = dict_clone (dictionary);
- if (dict_needs_compaction (scratch_dict))
+ if (dict_compacting_would_shrink (scratch_dict))
{
compactor = dict_make_compactor (scratch_dict);
dict_compact_values (scratch_dict);
const struct dictionary *dict);
static void write_documents (struct sfm_writer *, const struct dictionary *);
-static int does_dict_need_translation (const struct dictionary *);
static inline int
var_flt64_cnt (const struct variable *v)
w->fh = fh;
w->file = fdopen (fd, "w");
- w->needs_translation = does_dict_need_translation (d);
+ w->needs_translation = dict_compacting_would_change (d);
w->compress = opts.compress;
w->case_cnt = 0;
w->flt64_cnt = 0;
goto error;
}
-/* Returns zero if dictionary D's cases are ordered in the
- natural manner, with the first variable followed by the
- second, and so on,
- nonzero otherwise. */
-static int
-does_dict_need_translation (const struct dictionary *d)
-{
- size_t case_idx;
- size_t i;
-
- case_idx = 0;
- for (i = 0; i < dict_get_var_cnt (d); i++)
- {
- struct variable *v = dict_get_var (d, i);
- if (v->fv != case_idx)
- return 1;
- case_idx += v->nv;
- }
- return 0;
-}
-
/* Returns value of X truncated to two least-significant digits. */
static int
rerange (int x)