add array morphisms : StaticLength <--> LengthPrefix
This commit is contained in:
parent
76c005ac8b
commit
62f0ff9eac
1 changed files with 26 additions and 6 deletions
|
@ -3,15 +3,35 @@
|
|||
#include <array/length-prefix.h>
|
||||
```
|
||||
|
||||
morph_array_as_valterm_to_lenpfx (Terminator:native.UInt8)
|
||||
<Seq~<ValueTerminated Terminator> native.UInt8>
|
||||
--> <Seq~<LengthPrefix native.UInt64> native.UInt8>
|
||||
morph_array_as_static_to_lenpfx (Len: ℤ, T: Type)
|
||||
<Seq~<StaticLength Len> T>
|
||||
--> <Seq~<LengthPrefix native.UInt64> T>
|
||||
```
|
||||
length_prefix_nativeUInt64_array_nativeUInt8_clear(dst);
|
||||
while( *src != Terminator )
|
||||
length_prefix_nativeUInt64_array_nativeUInt8_push(dst, *src++);
|
||||
PRESCAN_LENGTH_PREFIX_CALL(nativeUInt64, T, clear)( dst );
|
||||
for( nativeUInt64 i = 0; i < Len; ++i )
|
||||
PRESCAN_LENGTH_PREFIX_CALL(nativeUInt64, T, push)( dst, src->items[i] );
|
||||
```
|
||||
|
||||
morph_array_as_lenpfx_to_static (Len: ℤ, T: Type)
|
||||
<Seq~<LengthPrefix native.UInt64> T>
|
||||
--> <Seq~<StaticLength Len> T>
|
||||
```
|
||||
nativeUInt64 i;
|
||||
for( i = 0; i < Len && i < src->len; ++i )
|
||||
dst->items[i] = src->items[i];
|
||||
|
||||
if( i < Len )
|
||||
memset( &dst[i], 0, (Len-i) * sizeof(T) );
|
||||
```
|
||||
|
||||
morph_array_as_valterm_to_lenpfx (T: Type, Terminator:T)
|
||||
<Seq~<ValueTerminated Terminator> T>
|
||||
--> <Seq~<LengthPrefix native.UInt64> T>
|
||||
```
|
||||
PRESCAN_LENGTH_PREFIX_CALL(nativeUInt64, T, push)( dst );
|
||||
while( *src != Terminator )
|
||||
PRESCAN_LENGTH_PREFIX_CALL(nativeUInt64, T, push)( dst, *src++ );
|
||||
```
|
||||
|
||||
morph_array_as_lenpfx_to_valterm (T: Type, Terminator: T)
|
||||
<Seq~<LengthPrefix native.UInt64> T>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue