Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COThis non-backtracking answer works rather better for the needle "TOKEN", which contains no repeated letters, than it does for other needles. For example it doesn't find the needle "AAB" in the haystack "AAAB", because when it hits the third A it sets `pos` to zero (because it expects a B) and doesn't realize that it has already seen an initial substring of the needle. Of course it's possible to build a finite state machine for any given needle (so if you know the needle now, this might be a good option). But the code to build that machine at runtime is *probably* overkill.
      singulars
    2. CO@SteveJessop Isn't this only an issue for the start letter? Anyway +1 for pointing out this issue. Actually you could build a non deterministic machine having multiple versions of the counter while running through your word. (Would make the implementation a bit more complicated of course)
      singulars
    3. COyeah, I think it has to involve the first letter. The failure is when some initial segment of the needle occurs elsewhere (and hence gets discarded by the reset), implying that the first letter must occur elsewhere as part of that initial segment. And agreed, you can easily do it using a number of counters equal to the number of bytes that you would have to buffer, if you buffered it. If the questioner wants to do anything clever then there is *plenty* of literature on the subject :-)
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload