collection.trie
===============

.. py:module:: collection.trie


Classes
-------

.. autoapisummary::

   collection.trie.Trie


Module Contents
---------------

.. py:class:: Trie(word_list: Iterable[str] | None = None, use_suffix: bool = False, match_delimiter: str = '')

   Implements a trie data structure.

   This structure can be used to do the following:

   * check if a word match a suffix in a list of suffixes
   * check if a word match a prefix in a list of prefixes
   * check if a word is in a list of words

   This is more efficient than iterating other sets or than using a simple
   regexp that concatenates the list of words/prefixes/suffixes


   .. py:attribute:: END_MARKER
      :value: ''



   .. py:attribute:: tree
      :type:  dict[str, Any]


   .. py:attribute:: match_delimiter
      :value: ''



   .. py:attribute:: word_iterator
      :type:  collections.abc.Callable[[str], Iterable[str]]


   .. py:method:: add(word: str) -> None

      Add a word to the trie.

      :param word: the word to add



   .. py:method:: contains(word: str) -> bool

      Check whether word is in the trie.

      :param word: a word
      :return: True if the word is in the trie, False otherwise



   .. py:method:: __contains__(word: str) -> bool


   .. py:method:: match(word: str, delimiter: str | None = None) -> bool

      Check if there is word in the trie which is a prefix/suffix of word.

      :param word: the word to check
      :param delimiter: if None use the default delimiter. If delimiter is ''
          then the function returns True whenever a word in the trie is a
          prefix or suffix of word. If delimiter is a non empty string then
          the function returns True if there is a word W in the trie such as
          W is equal to word or if W is a prefix/suffix of word and that the
          next/previous character in word is in delimiter.
      :return: True if matched, False otherwise



