kpol / trie

Trie (a.k.a. prefix tree) C# implementation. Has constant-time string prefix lookup.
MIT License
100 stars 19 forks source link

Add Span Support #21

Closed leorg99 closed 6 months ago

leorg99 commented 6 months ago

Added support for ReadOnlySpan<char>.

The motivation for this change is to increase efficiency in a library I am creating to break string inputs along dictionary words. For example: thebigbrownduck -> the big brown duck.

To do this, you have to go character by character down the Trie and break the string when you reach a null node. Then recursively try with the next part. Using spans instead of substrings can be a big performance gain because there are no additional string allocations. We can just keep slicing the original input and work with ReadOnly<char> spans

kpol commented 6 months ago

Looks good. Thanks!