Vai al contenuto principale
ProdottiStrumenti desktopTASTECADVisualizzazione disegniTASTEFILESGestione fileTASTEFTPTrasferimento fileTASTESSHSpazio di lavoro remotoTASTEZIPCompressione ed estrazioneTASTEWINMGestione fileStrumenti per sviluppatoriTASTECODEAmbiente di sviluppo integrato per RustTASTESTUDIOAmbiente integrato di sviluppo e testTASTEETLIntegrazione dati (ETL)ServerTASTEREMOTEServer di desktop remotoTASTEGEOServer geospazialeTASTEMAILSpazio di lavoro emailInvestimentiTASTESTOCKApp desktop di trading automatico azionarioIniziaDownloadDocumentazioneAcquistaTutti i prodotti
Marketplace
Notizie
TecnologiaNotizieNotizie di sviluppo di oggiDocumentazioneLinguaggi di programmazioneRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartFramework frontend webNext.jsReactVue.js · NuxtSvelteKitAngularFramework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressFramework per app e desktopTauriFlutterReact NativeElectronAlgoritmiBasi degli algoritmiAlgoritmi fondamentaliAlgoritmi avanzatiAlgoritmi pratici
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrinaGuida alla community
CollaboraTrasferimento tecnicoRealizzazione del sito webRealizzazione di app desktopPipeline di rilascio e pagamentoPartner commercialeContatti
ServiziDesktop remotoPacchetti di installazione su misura
TASTEDEV
Prodotti

Strumenti desktop

TASTECADApri con leggerezza anche i disegni più complessiTASTEFILESSolo i file che servono, alla massima velocitàTASTEFTPLa via più ordinata per i tuoi fileTASTESSHUn legame più solido tra te e i tuoi serverTASTEZIPComprimi più veloce, estrai più sicuroTASTEWINMUn file manager a due pannelli pensato per la tastiera

Strumenti per sviluppatori

TASTECODEModifica, compila, esegui il debug e testa app Rust in un'unica finestraTASTESTUDIODalla modifica ai test remoti e alle correzioni IA approvateTASTEETLSposta i dati guardando i valori

Server

TASTEREMOTEUn desktop remoto che gira sul tuo serverTASTEGEOUn server geospaziale compatibile con GeoServer, ricostruito in RustTASTEMAILRiprendi il controllo della tua posta

Investimenti

TASTESTOCKTrading automatico azionario secondo le regole che decidi tu: quando e che cosa

Inizia

DownloadUltime versioni di ogni prodottoDocsCome usare ogni prodottoAcquistaAbbonamenti e licenze perpetueTutti i prodottiTutti i prodotti a colpo d’occhio
Tutti i prodotti
MarketplaceNotizie
Tecnologia

Notizie

Notizie di sviluppo di oggiAnnunci ufficiali su linguaggi, framework, GitHub e IADocumentazioneGuide a linguaggi, framework e algoritmi

Linguaggi di programmazione

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Framework

Framework frontend webNext.jsReactVue.js · NuxtSvelteKitAngular
Framework serverSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
Framework per app e desktopTauriFlutterReact NativeElectron

Algoritmi

Basi degli algoritmiAnalisi della complessità · Ordinamento · Ricerca · Strutture dati di base · Alberi e heapAlgoritmi fondamentaliVisita dei grafi · Cammini minimi e alberi ricoprenti · Programmazione dinamica · Algoritmi greedy · Divide et impera · BacktrackingAlgoritmi avanzatiAlgoritmi sulle stringhe · Matematica e teoria dei numeri · Manipolazione dei bit · Alberi di segmenti · Union-FindAlgoritmi praticiStrategia per colloqui di programmazione · Cache LRU · Rate limiting · Hashing consistente
Tutta la documentazione di sviluppo
Community
ProgettiScopri sviluppatori e lavoriLog di sviluppoDecisioni e lezioni appresePromptIstruzioni riutilizzabiliProblemi degli strumenti di IAProblemi e alternative di Claude, Codex, GeminiVetrinaRisultati completatiGuida alla communityCome sviluppiamo in modo aperto
Collabora
Trasferimento tecnicoApp native in Rust ed eguiRealizzazione del sito web10 lingue, account, documentazione e downloadRealizzazione di app desktopRust ed egui, senza WebViewPipeline di rilascio e pagamentoFirma, MSI, deb, rpm, AppImage, hashPartner commercialeConsigliaci e ricevi il 30%ContattiSviluppo, partnership e investimenti
Servizi
Desktop remotoRaggiungi il tuo computer dal browserPacchetti di installazione su misuraSolo il necessario, impostazioni precaricate
Acquista
IT
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Accedi
Accedi
TASTEDEV

Dai piccoli strumenti a uno sviluppo migliore.

support@tastedev.netSostieni TASTEDEV
ProdottiGamma di prodottiAcquistaDocsDownloadMarketplaceAssistenza
CommunityProgettiLog di sviluppoPromptProblemi degli strumenti di IAVetrina
NormeChi siamoInformativa sulla privacyTermini di servizioCondizioni di abbonamentoRimborsiLinee guida della community
AccountAccediRegistrati
Visitatori
Oggi
Ieri
Visualizzazioni totali
Società
GXSOFT
Rappresentante
CHOI YOUNG GU
Numero di registrazione
853-44-00368
Indirizzo
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefono
+82-10-4404-1523
E-mail
whitecalvin@tastedev.net
Responsabile privacy
CHOI YOUNG GU

© 2026 TASTEDEVLe informazioni sui prodotti si basano su fonti di sviluppo verificate.Rilasciato · in miglioramento

Documentazione di Algoritmi sulle stringhe
Algoritmi sulle stringhe
ConceptsHow It WorksImplementationComplexityPractice ProblemsReal-World Use
Discussioni

Guida a Algoritmi sulle stringhe · 6/6

Real-World Use

Per ora questo capitolo è disponibile solo in inglese.

Most string algorithms you rely on live inside libraries and tools. This chapter shows where, and which traps to avoid when writing your own.

String algorithms in real systems

  • Standard library search: CPython's str.find and in are built on a simplified Boyer-Moore-Horspool scheme, and since Python 3.10 long needles use the Crochemore-Perrin Two-Way algorithm. glibc's memmem and strstr also use Two-Way for long needles. Two-Way guarantees linear worst-case time with only constant extra memory.
  • grep-style tools: GNU grep combines Boyer-Moore style search with algorithms for matching many keywords at once. ripgrep builds on the Rust crates aho-corasick and memchr, which provide multi-pattern search and SIMD acceleration.
  • Intrusion detection and antivirus: thousands of signatures must be found in packets or files in a single pass, so Aho-Corasick and its variants are common.
  • File sync and deduplication: rsync uses a rolling checksum to find which blocks changed and sends only those. Backup tools use rolling hashes such as Rabin fingerprints to pick content-defined chunk boundaries.
  • Plagiarism detection: documents are turned into hashes of k-grams, and the winnowing technique keeps a subset of them as a fingerprint.
  • Routing and dictionaries: longest-prefix matching in IP routing uses trie variants; the Linux kernel's IPv4 routing table is an LC-trie. Search-box autocomplete, spelling dictionaries and prefix queries in key-value stores also use tries or radix trees.
  • Bioinformatics: tools that align short reads to a reference genome index the huge text with suffix arrays and BWT-based FM-indexes.

Pitfall 1: Unicode

Languages count string length and positions in different units.

EnvironmentIndex unitLength of "😀"
Python strcode point1
Java String, JavaScriptUTF-16 code unit2
C++ std::string, Rust str::lenUTF-8 byte4

Pass a position computed in Java or JavaScript to a Python service and it will be off as soon as the text contains an emoji. When positions cross an API boundary, state the unit explicitly.

const s = "a😀b";
console.log(s.length);            // 4 (UTF-16 code units)
console.log([...s].length);       // 3 (code points)
const seg = new Intl.Segmenter("en", { granularity: "grapheme" });
console.log([...seg.segment("👍🏽")].length); // 1 (user-perceived character)
Domande su questo capitolo?
Capitolo precedentePractice Problems

The same character can also be encoded in more than one way. é may be a single precomposed code point (U+00E9) or e followed by a combining accent. Text stored in NFD, as macOS file names often are, will not match an NFC query. For case-insensitive comparison, casefold() is more correct than lower().

import unicodedata

nfd = unicodedata.normalize("NFD", "café")
print(len("café"), len(nfd))                           # 4 5
print("café" in nfd)                                   # False
print("café" in unicodedata.normalize("NFC", nfd))     # True
print("Straße".lower() == "STRASSE".lower())          # False
print("Straße".casefold() == "STRASSE".casefold())    # True

A search pipeline should apply the same normalization and case folding when indexing and when querying.

Pitfall 2: hash collisions and hostile input

If Rabin-Karp skips the confirmation step on a hash hit, it can report wrong answers. With a fixed base and modulus an attacker can build colliding inputs, so pick a random base on each run and use a large prime modulus such as 2^61 - 1, or combine two independent hashes.

import random

MOD = (1 << 61) - 1
BASE = random.randrange(256, MOD - 1)   # different base on every run


def poly_hash(s: str) -> int:
    h = 0
    for ch in s:
        h = (h * BASE + ord(ch)) % MOD
    return h


print(poly_hash("abc") == poly_hash("abc"), poly_hash("abc") == poly_hash("acb"))
# True False (a collision is very unlikely, but never impossible)

Pitfall 3: memory and recursion

  • Tries allocate many node objects and use a lot of memory. With millions of words, consider compact structures: radix trees, double-array tries, or a sorted list with binary search.
  • A recursive DFS over a trie can hit Python's recursion limit on very long keys. Use an explicit stack.
  • Regular expressions are convenient, but on backtracking engines patterns like (a+)+ can take exponential time (ReDoS). Escape user input with re.escape before using it as a pattern.

What to pick

SituationRecommendation
One simple searchThe language's built-ins (in, find, indexOf)
Need borders, periods or prefix dataPrefix function (KMP) or Z-array
Many patterns of equal length, substring comparisonRolling hash
Thousands of patterns of varying lengthAn Aho-Corasick library
Prefix lookup in a dictionary, autocompleteTrie, or sorted list plus binary search
Many queries over one large textSuffix array, FM-index, a search engine

Summary

  • Libraries and tools use Two-Way, Boyer-Moore, Aho-Corasick, rolling hashes and tries depending on the job.
  • With Unicode, agree on index units, normalization and case folding first.
  • Defend against hash collisions with a random base and a confirmation step, and consider compact structures for large dictionaries.

Further reading

  • String-searching algorithm (Wikipedia)
  • Prefix function. Knuth-Morris-Pratt (cp-algorithms)
  • Z-function and its calculation (cp-algorithms)
  • String Hashing (cp-algorithms)
  • Trie (Wikipedia)
  • Aho-Corasick algorithm (Wikipedia)
  • Unicode HOWTO (Python docs)

0 commenti

Commenti principaliPrima i più recenti

Accedi · Accedi per lasciare un commento.