From b88251b9c4e6e2932bfa4179379586c9fa578d52 Mon Sep 17 00:00:00 2001 From: Michael Sippel <micha@fragmental.art> Date: Thu, 20 Feb 2025 05:16:31 +0100 Subject: [PATCH] add length_prefix_array_map_8_to_8 --- morphisms/include/array/length-prefix.h | 5 +++++ morphisms/src/length-prefix.c | 15 +++++++++++++++ src/main.rs | 13 ++++--------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/morphisms/include/array/length-prefix.h b/morphisms/include/array/length-prefix.h index 844340c..6831aad 100644 --- a/morphisms/include/array/length-prefix.h +++ b/morphisms/include/array/length-prefix.h @@ -63,3 +63,8 @@ int length_prefix_array_map_64_to_8( struct LengthPrefixUInt64Array const * restrict src, struct LengthPrefixUInt8Array * restrict dst ); +int length_prefix_array_map_8_to_8( + int (*f) ( uint8_t const * restrict, uint8_t * restrict ), + struct LengthPrefixUInt8Array const * restrict src, + struct LengthPrefixUInt8Array * restrict dst +); diff --git a/morphisms/src/length-prefix.c b/morphisms/src/length-prefix.c index 4a93bec..281a8cb 100644 --- a/morphisms/src/length-prefix.c +++ b/morphisms/src/length-prefix.c @@ -28,6 +28,21 @@ int length_prefix_uint64_array_reverse( return 0; } +int length_prefix_array_map_8_to_8( + int (*f) ( uint8_t const * restrict, uint8_t * restrict ), + struct LengthPrefixUInt8Array const * restrict src, + struct LengthPrefixUInt8Array * restrict dst +) { + dst->len = src->len; + for( uint64_t i = 0; i < src->len; ++i ) { + int result = f( &src->items[i], &dst->items[i] ); + if( result ) { + return result; + } + } + return 0; +} + int length_prefix_array_map_64_to_64( int (*f) ( uint64_t const * restrict, uint64_t * restrict ), struct LengthPrefixUInt64Array const * restrict src, diff --git a/src/main.rs b/src/main.rs index 268e4de..8779e31 100644 --- a/src/main.rs +++ b/src/main.rs @@ -197,15 +197,10 @@ impl LdmcMorphism { let dst_c_type = get_c_repr_type(dict, self.get_type().dst_type, true).expect("cant get c-repr type for dst type"); let map_fn = match (src_c_type.as_str(), dst_c_type.as_str()) { - ("struct LengthPrefixUInt64Array", "struct LengthPrefixUInt64Array") => { - "length_prefix_array_map_64_to_64" - }, - ("struct LengthPrefixUInt8Array", "struct LengthPrefixUInt64Array") => { - "length_prefix_array_map_8_to_64" - }, - ("struct LengthPrefixUInt64Array", "struct LengthPrefixUInt8Array") => { - "length_prefix_array_map_64_to_8" - }, + ("struct LengthPrefixUInt64Array", "struct LengthPrefixUInt64Array") => "length_prefix_array_map_64_to_64", + ("struct LengthPrefixUInt8Array", "struct LengthPrefixUInt64Array") => "length_prefix_array_map_8_to_64", + ("struct LengthPrefixUInt64Array", "struct LengthPrefixUInt8Array") => "length_prefix_array_map_64_to_8", + ("struct LengthPrefixUInt8Array", "struct LengthPrefixUInt8Array") => "length_prefix_array_map_8_to_8", _ => { "{{ ERROR: no map function implemented }}" }