B
    Sc                 @   s    d Z ddlmZmZ dd ZdS )z%Generic tools for working with trees.    )ceillogc                s  | sg S  dkst ttt|  }|dkr6t| S g }d} |d  }xvtdt| |D ]b}| |||  t|k r}P x0t kr fddtdt D qW | q\W |rt| t t| kr| n
| t| kst |S )zBuild N-ary tree from sequence of leaf nodes.

    Return a list of lists where each non-leaf node is a list containing
    max n nodes.
       Nr   c                s   g | ]}||   qS  r   ).0k)nsubtreer   7lib/python3.7/site-packages/fontTools/misc/treeTools.py
<listcomp>    s    z$build_n_ary_tree.<locals>.<listcomp>)	AssertionErrorr   r   lenlistrangeappendbuild_n_ary_treeextend)Zleavesr   ZdepthrootZ
unassignedZ	full_stepir   )r   r	   r
   r      s0    $

r   N)__doc__Zmathr   r   r   r   r   r   r
   <module>   s   