Add efficient findCharIndex

Aperta
#445 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
30/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
haskell
Ambito
performance

Direzione di ricerca

Inizia leggendo la discussione correlata in #369 e seguendo i percorsi esistenti di findIndex e isSubsequenceOf. L’issue non indica file sorgente né test; per completarla sarebbe necessario concordare sul primitivo e valutare le regole di riscrittura di Char proposte e il comportamento della ricerca UTF-8.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

feature request
findCharIndex :: Char -> Text -> Maybe Int

When having look at #369, it looks like having access to this primitive, with a fast C implementation that uses the known size of each char in utf-8 might be able to make isSubsequenceOf quite fast, particularly when the haystack is quite large and the needle chars are spread far apart.

int findCharIndex(const char * haystack, int length, int target) {
    char * offset;
    if (target < 128) {
        offset = memchr(haystack, length target);
    } else {
        // Implementation left as an exercise to the reader, but it would look for
        // utf-8 encoded bytes for the Char.
        offset = efficientlyFindUTF8Codepoint(haystack, length, target);
    }
    if (offset == NULL) return -1;
    return (int)(offset - haystack);
}

Having this also means we could add the rule

{-# RULES "findIndex Char" findIndex (c ==) = findCharIndex c #-}
{-# RULES "findIndex Char2" findIndex (== c) = findCharIndex c #-}
Lingua principale
Haskell
Stelle
424
Fork
167
Merge medio
1g 21h
PR unite (30g)
6

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di haskell/text

Tutte le issue di haskell/text

Issue simili

Altre issue su Haskell

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.