From d3bf941f12d1ed453250cb74168a9999bda04a74 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 3 Feb 2019 06:07:00 -0500 Subject: add km_set_copy() --- km-set.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ km.h | 3 +++ 2 files changed, 47 insertions(+) diff --git a/km-set.c b/km-set.c index 58792c0..ca028f8 100644 --- a/km-set.c +++ b/km-set.c @@ -179,6 +179,50 @@ km_set_push( return true; } +bool +km_set_copy( + km_set_t * const dst, + const km_set_t * const src +) { + if (src->state != KM_SET_STATE_INIT || src->state != KM_SET_STATE_NORMALIZED) { + // return failure + return false; + } + + // init dst set + if (!km_set_init(dst, &(src->shape), src->num_rows)) { + // return failure + return false; + } + + // copy floats + const size_t num_floats = src->shape.num_floats; + if (num_floats > 0) { + const size_t stride = sizeof(float) * num_floats; + + // copy floats + memcpy(dst->floats, src->floats, stride * src->num_rows); + + // copy bounds + memcpy(dst->bounds, src->bounds, 2 * stride); + } + + // copy ints + const size_t num_ints = src->shape.num_ints; + if (num_ints > 0) { + const size_t stride = sizeof(int) * num_ints; + + // copy ints + memcpy(dst->ints, src->ints, stride * src->num_rows); + } + + // increment row count + dst->num_rows = src->num_rows; + + // return success + return true; +} + bool km_set_normalize( km_set_t * const set diff --git a/km.h b/km.h index 1d00d50..9a58a6d 100644 --- a/km.h +++ b/km.h @@ -64,6 +64,9 @@ void km_set_fini(km_set_t * const); // append rows to data set, growing set if necessary _Bool km_set_push(km_set_t *, const size_t, const float *, const int *); +// deep copy data set +_Bool km_set_copy(km_set_t * const, const km_set_t * const); + // normalize data set _Bool km_set_normalize(km_set_t * const); -- cgit v1.2.3