aboutsummaryrefslogtreecommitdiff
path: root/km-set.c
diff options
context:
space:
mode:
Diffstat (limited to 'km-set.c')
-rw-r--r--km-set.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/km-set.c b/km-set.c
index 58792c0..ca028f8 100644
--- a/km-set.c
+++ b/km-set.c
@@ -180,6 +180,50 @@ km_set_push(
}
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
) {