o
    @@i                     @   s   d Z ddlZG dd dZdS )u  
In computer science, a trie (/ˈtraɪ/, /ˈtriː/), also called digital tree or prefix tree, is a type of k-ary search tree,
a tree data structure used for locating specific keys from within a set. These keys are most often strings,
with links between nodes defined not by the entire key, but by individual characters.
In order to access a key (to recover its value, change it, or remove it), the trie is traversed depth-first,
following the links between nodes, which represent each character in the key.
    Nc                   @   sR   e Zd ZdZG dd dZdd Zdejej fddZ	de
fd	d
Zdd ZdS )Trieu  
    In computer science, a trie (/ˈtraɪ/, /ˈtriː/), also called digital tree or prefix tree, is a type of k-ary search tree,
    a tree data structure used for locating specific keys from within a set. These keys are most often strings,
    with links between nodes defined not by the entire key, but by individual characters.
    In order to access a key (to recover its value, change it, or remove it), the trie is traversed depth-first,
    following the links between nodes, which represent each character in the key.
    c                   @   sF   e Zd ZdZddejej fddZdefddZ	dejfd	d
Z
dS )zTrie.TrieNodez8
        This class represents a node in a trie
        Nvaluec                 C   s   i | _ || _d S N)	_children_value)selfr    r   Y/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/borb/datastructure/str_trie.py__init__   s   
zTrie.TrieNode.__init__returnc                 C   s*   | j d u rdndtdd | j D  S )Nr      c                 S   s   g | ]\}}t |qS r   )len).0kvr   r   r	   
<listcomp>"   s    z)Trie.TrieNode.__len__.<locals>.<listcomp>)r   sumr   itemsr   r   r   r	   __len__    s   zTrie.TrieNode.__len__c                 C   s   | j S )z}
            This function returns the value of this TrieNode
            :return:    the value of this TrieNode
            )r   r   r   r   r	   	get_value%   s   zTrie.TrieNode.get_valuer   )__name__
__module____qualname____doc__typingOptionalAnyr
   intr   r   r   r   r   r	   TrieNode   s
    r   c                 C   s
   d | _ d S r   )_rootr   r   r   r	   r
   0   s   
zTrie.__init__r   c                 C   sN   | j }|d u r	d S |D ]}||jv r|j| }q d S |d us#J d| S )Nz5unexpected error while performing __getitem__ on Trie)r    r   r   )r   itemncr   r   r	   __getitem__7   s   
zTrie.__getitem__c                 C   s   | j d u rdS t| j S )Nr   )r    r   r   r   r   r	   r   E   s   zTrie.__len__c                 C   st   | j }|d u rt | _ | j }|d usJ d|D ]}||jvr't |j|< |j| }q|d us5J d||_| S )Nz5unexpected error while performing __setitem__ on Trie)r    r   r   r   r   )r   keyr   r"   r#   r   r   r	   __setitem__H   s   

zTrie.__setitem__N)r   r   r   r   r   r
   r   r   r   r$   r   r   r&   r   r   r   r	   r      s    r   )r   r   r   r   r   r   r	   <module>   s   