lt-core/lt-stdlib/string.lt

42 lines
671 B
Text
Raw Permalink Normal View History

2024-06-11 15:17:58 +02:00
#complexity O(n)
let strlen-nullterm =
λ str : &[Char~Ascii~machine::Word]
~ &<NullTerminatedSeq machine::Word>
~ machine::Address
~ machine::Word
->
~ _2^64
~ machine::UInt64
~ machine::Word
{
let mut len = 0;
while ( @str ) {
! len (i+ len 1);
! str (i+ str 1);
}
len;
};
#complexity O(1)
let strlen-lenprefix =
λ str : &[Char~Ascii~machine::Word]
~ &<LenPrefixArray machine::Word>
~ &{
len : _2^64
~ machine::UInt64
~ machine::Word,
data : [machine::Word]
}
~ machine::Address
~ machine::Word
->
~ _2^64
~ machine::UInt64
~ machine::Word
{
str.len
};