add C functions for map lengthPrefix
This commit is contained in:
parent
10dab73876
commit
e07b3585f9
6 changed files with 81 additions and 13 deletions
morphisms
|
@ -1,5 +1,5 @@
|
|||
LIB_DIR=$(shell pwd)/lib
|
||||
TARGETS=lib/libmorph_length-prefix.so lib/libmorph_posint.so test
|
||||
TARGETS=lib/libmorph_length-prefix.so lib/libmorph_posint.so
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ void length_prefix_uint8_array_dump(
|
|||
struct LengthPrefixUInt8Array const * data
|
||||
);
|
||||
|
||||
|
||||
/* UInt64 */
|
||||
|
||||
struct LengthPrefixUInt64Array {
|
||||
|
@ -46,6 +45,25 @@ void length_prefix_uint64_array_dump(
|
|||
struct LengthPrefixUInt64Array const * data
|
||||
);
|
||||
|
||||
/*
|
||||
* Map
|
||||
*/
|
||||
int length_prefix_array_map_64_to_64(
|
||||
int (*f) ( uint64_t const * restrict, uint64_t * restrict ),
|
||||
struct LengthPrefixUInt64Array const * restrict src,
|
||||
struct LengthPrefixUInt64Array * restrict dst
|
||||
);
|
||||
int length_prefix_array_map_8_to_64(
|
||||
int (*f) ( uint8_t const * restrict, uint64_t * restrict ),
|
||||
struct LengthPrefixUInt8Array const * restrict src,
|
||||
struct LengthPrefixUInt64Array * restrict dst
|
||||
);
|
||||
int length_prefix_array_map_64_to_8(
|
||||
int (*f) ( uint64_t const * restrict, uint8_t * restrict ),
|
||||
struct LengthPrefixUInt64Array const * restrict src,
|
||||
struct LengthPrefixUInt8Array * restrict dst
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
* Morphisms
|
||||
|
|
|
@ -3,22 +3,22 @@
|
|||
#include <morphisms/length-prefix.h>
|
||||
|
||||
int morph_digit_as_char_to_uint8(
|
||||
uint64_t const radix,
|
||||
//uint64_t const radix,
|
||||
uint8_t const * restrict src,
|
||||
uint8_t * restrict dst
|
||||
);
|
||||
int morph_digit_as_char_to_uint64(
|
||||
uint64_t const radix,
|
||||
//uint64_t const radix,
|
||||
uint8_t const * restrict src,
|
||||
uint64_t * restrict dst
|
||||
);
|
||||
int morph_digit_as_uint8_to_char(
|
||||
uint64_t const radix,
|
||||
//uint64_t const radix,
|
||||
uint8_t const * restrict src,
|
||||
uint8_t * restrict dst
|
||||
);
|
||||
int morph_digit_as_uint64_to_char(
|
||||
uint64_t const radix,
|
||||
//uint64_t const radix,
|
||||
uint64_t const * restrict src,
|
||||
uint8_t * restrict dst
|
||||
);
|
||||
|
|
|
@ -22,10 +22,12 @@ int main() {
|
|||
{
|
||||
struct LengthPrefixUInt8Array * src = (void*) bufB;
|
||||
struct LengthPrefixUInt64Array * dst = (void*) bufA;
|
||||
|
||||
length_prefix_array_map_8_to_64( morph_digit_as_char_to_uint64, src, dst );
|
||||
/*
|
||||
dst->len = src->len;
|
||||
for( uint64_t i = 0; i < src->len; ++i )
|
||||
morph_digit_as_char_to_uint64( &src->items[i], &dst->items[i] );
|
||||
*/
|
||||
}
|
||||
|
||||
// morph to
|
||||
|
@ -63,9 +65,12 @@ int main() {
|
|||
struct LengthPrefixUInt64Array * src = (void*) bufB;
|
||||
struct LengthPrefixUInt8Array * dst = (void*) bufA;
|
||||
|
||||
length_prefix_array_map_64_to_8( morph_digit_as_uint64_to_char, src, dst );
|
||||
/*
|
||||
dst->len = src->len;
|
||||
for( uint64_t i = 0; i < src->len; ++i )
|
||||
morph_digit_as_uint64_to_char( &src->items[i], &dst->items[i] );
|
||||
*/
|
||||
}
|
||||
|
||||
// morph to
|
||||
|
|
|
@ -28,6 +28,51 @@ int length_prefix_uint64_array_reverse(
|
|||
return 0;
|
||||
}
|
||||
|
||||
int length_prefix_array_map_64_to_64(
|
||||
int (*f) ( uint64_t const * restrict, uint64_t * restrict ),
|
||||
struct LengthPrefixUInt64Array const * restrict src,
|
||||
struct LengthPrefixUInt64Array * 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_8_to_64(
|
||||
int (*f) ( uint8_t const * restrict, uint64_t * restrict ),
|
||||
struct LengthPrefixUInt8Array const * restrict src,
|
||||
struct LengthPrefixUInt64Array * 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_8(
|
||||
int (*f) ( uint64_t const * restrict, uint8_t * restrict ),
|
||||
struct LengthPrefixUInt64Array 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;
|
||||
}
|
||||
|
||||
void length_prefix_uint64_array_dump(
|
||||
struct LengthPrefixUInt64Array const * data
|
||||
) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include <morphisms/length-prefix.h>
|
||||
|
||||
int morph_digit_as_char_to_uint8(
|
||||
uint64_t const radix,
|
||||
//uint64_t const radix,
|
||||
uint8_t const * restrict src,
|
||||
uint8_t * restrict dst
|
||||
) {
|
||||
|
@ -19,15 +19,15 @@ int morph_digit_as_char_to_uint8(
|
|||
}
|
||||
|
||||
int morph_digit_as_char_to_uint64(
|
||||
uint64_t const radix,
|
||||
//uint64_t const radix,
|
||||
uint8_t const * restrict src,
|
||||
uint64_t * restrict dst
|
||||
) {
|
||||
return morph_digit_as_char_to_uint8(radix, src, dst);
|
||||
return morph_digit_as_char_to_uint8(src, (void*)dst);
|
||||
}
|
||||
|
||||
int morph_digit_as_uint8_to_char(
|
||||
uint64_t const radix,
|
||||
//uint64_t const radix,
|
||||
uint8_t const * restrict src,
|
||||
uint8_t * restrict dst
|
||||
) {
|
||||
|
@ -42,11 +42,11 @@ int morph_digit_as_uint8_to_char(
|
|||
}
|
||||
|
||||
int morph_digit_as_uint64_to_char(
|
||||
uint64_t const radix,
|
||||
//uint64_t const radix,
|
||||
uint64_t const * restrict src,
|
||||
uint8_t * restrict dst
|
||||
) {
|
||||
return morph_digit_as_uint8_to_char(radix, src, dst);
|
||||
return morph_digit_as_uint8_to_char((void*)src, dst);
|
||||
}
|
||||
|
||||
/* switches endianness by reversing the digit sequence
|
||||
|
|
Loading…
Add table
Reference in a new issue