
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
3
B;W                 @   s4   d dl mZmZmZ d dlmZ G dd deZdS )    )absolute_importdivisionunicode_literals)Mappingc                   s:   e Zd ZdZd fdd	Zdd Zdd Zd	d
 Z  ZS )TriezAbstract base class for triesNc                s4   t t| j } d krt|S t fdd|D S )Nc                s   g | ]}|j  r|qS  )
startswith).0x)prefixr   /usr/lib/python3.6/_base.py
<listcomp>   s    zTrie.keys.<locals>.<listcomp>)superr   keysset)selfr   r   )	__class__)r   r   r   	   s    z	Trie.keysc             C   s$   x| j  D ]}|j|r
dS q
W dS )NTF)r   r   )r   r   keyr   r   r   has_keys_with_prefix   s    
zTrie.has_keys_with_prefixc             C   sT   || kr|S x:t dt|d D ]$}|d |  | kr |d |  S q W t|d S )N   )rangelenKeyError)r   r   ir   r   r   longest_prefix   s    zTrie.longest_prefixc             C   s   | j |}|| | fS )N)r   )r   r   Zlprefixr   r   r   longest_prefix_item$   s    
zTrie.longest_prefix_item)N)	__name__
__module____qualname____doc__r   r   r   r   __classcell__r   r   )r   r   r      s
   

r   N)Z
__future__r   r   r   collectionsr   r   r   r   r   r   <module>   s   