Skip to content

module algorithms.strings

Source: stdlib/algorithms/strings.codon


cttz(n: UInt[N], N: Literal[int]) @pure Function has no side effects and returns same value for same inputs @llvm Function is implemented with inline LLVM IR

declare i{=N} @llvm.cttz.i{=N}(i{=N}, i1)
%0 = call i{=N} @llvm.cttz.i{=N}(i{=N} %n, i1 true)
ret i{=N} %0

ctlz(n: UInt[N], N: Literal[int]) @pure Function has no side effects and returns same value for same inputs @llvm Function is implemented with inline LLVM IR

declare i{=N} @llvm.ctlz.i{=N}(i{=N}, i1)
%0 = call i{=N} @llvm.ctlz.i{=N}(i{=N} %n, i1 true)
ret i{=N} %0

forward_mask(s: Ptr[byte], n: int, needle: Ptr[byte], k: int, i: int, firstb: byte, lastb: byte) @pure Function has no side effects and returns same value for same inputs @llvm Function is implemented with inline LLVM IR

%first0 = insertelement <16 x i8> undef, i8 %firstb, i64 0
%first = shufflevector <16 x i8> %first0, <16 x i8> poison, <16 x i32> zeroinitializer
%last0 = insertelement <16 x i8> undef, i8 %lastb, i64 0
%last = shufflevector <16 x i8> %last0, <16 x i8> poison, <16 x i32> zeroinitializer
%offset0 = add i64 %i, %k
%offset = sub i64 %offset0, 1
%ptr_first = getelementptr inbounds i8, ptr %s, i64 %i
%ptr_last = getelementptr inbounds i8, ptr %s, i64 %offset
%block_first = load <16 x i8>, ptr %ptr_first, align 1
%block_last = load <16 x i8>, ptr %ptr_last, align 1
%eq_first = icmp eq <16 x i8> %first, %block_first
%eq_last = icmp eq <16 x i8> %last, %block_last
%mask0 = and <16 x i1> %eq_first, %eq_last
%mask = bitcast <16 x i1> %mask0 to i16
ret i16 %mask

backward_mask(s: Ptr[byte], n: int, needle: Ptr[byte], k: int, i: int, firstb: byte, lastb: byte) @pure Function has no side effects and returns same value for same inputs @llvm Function is implemented with inline LLVM IR

%j0 = sub i64 %i, 16
%j = add i64 %j0, 1
%first0 = insertelement <16 x i8> undef, i8 %firstb, i64 0
%first = shufflevector <16 x i8> %first0, <16 x i8> poison, <16 x i32> zeroinitializer
%last0 = insertelement <16 x i8> undef, i8 %lastb, i64 0
%last = shufflevector <16 x i8> %last0, <16 x i8> poison, <16 x i32> zeroinitializer
%offset0 = sub i64 %j, %k
%offset = add i64 %offset0, 1
%ptr_first = getelementptr inbounds i8, ptr %s, i64 %offset
%ptr_last = getelementptr inbounds i8, ptr %s, i64 %j
%block_first = load <16 x i8>, ptr %ptr_first, align 1
%block_last = load <16 x i8>, ptr %ptr_last, align 1
%eq_first = icmp eq <16 x i8> %last, %block_last
%eq_last = icmp eq <16 x i8> %first, %block_first
%mask0 = and <16 x i1> %eq_first, %eq_last
%mask = bitcast <16 x i1> %mask0 to i16
ret i16 %mask

forward_find(s: Ptr[byte], n: int, needle: Ptr[byte], k: int)


backward_find(s: Ptr[byte], n: int, needle: Ptr[byte], k: int)


find(haystack: str, needle: str)


rfind(haystack: str, needle: str)


count(haystack: str, needle: str)


count_with_max(haystack: str, needle: str, maxcount: int)