+#include "data/variable.h"
+#include "data/value.h"
+#include "libpspp/array.h"
+#include "libpspp/compiler.h"
+
+struct freq *
+freq_clone (const struct freq *in, int values, int *widths)
+{
+ int i;
+ struct freq *f = xmalloc (sizeof (struct freq) +
+ (sizeof (union value) * (values - 1)));
+
+ f->node = in->node;
+ f->count = in->count;
+ for (i = 0; i < values; ++i)
+ {
+ value_init (&f->values[i], widths[i]);
+ value_copy (&f->values[i], &in->values[i], widths[i]);
+ }
+
+ return f;
+}
+
+void
+freq_destroy (struct freq *f, int values, int *widths)
+{
+ int i;
+ for (i = 0; i < values; ++i)
+ {
+ value_destroy (&f->values[i], widths[i]);
+ }
+
+ free (f);
+}
+
+
+
+void
+freq_hmap_destroy (struct hmap *hmap, int width)
+{
+ struct freq *f, *next;
+
+ HMAP_FOR_EACH_SAFE (f, next, struct freq, node, hmap)
+ {
+ value_destroy (&f->values[0], width);
+ hmap_delete (hmap, &f->node);
+ free (f);
+ }
+ hmap_destroy (hmap);
+}