
    jke                         d Z ddlmZmZ d Zy)z%Generic tools for working with trees.    )ceillogc                 h   | sg S |dkD  sJ t        t        t        |       |            }|dk  rt        |       S g }d}||dz
  z  }t	        dt        |       |      D ]s  }| |||z    }t        |      |k  r|} nYt        |      |kD  r8t	        dt        |      |      D cg c]
  }||||z     }}t        |      |kD  r8|j                  |       u |rYt        ||      }t        |      |t        |      z
  k  r|j                  |       n|j                  |       t        |      |k  sJ |S c c}w )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   )r   r   lenlistrangeappendbuild_n_ary_treeextend)	leavesndepthroot
unassigned	full_stepisubtreeks	            :/usr/lib/python3/dist-packages/fontTools/misc/treeTools.pyr   r      s@    	q5L5S[!$%EzF| DJeai I1c&k9- Q]+w<)# J'lQ38CL!3LMawq1q5)MGM 'lQG ":q1w<1s4y=(KK KK 4yA~~K Ns   D/N)__doc__mathr   r   r        r   <module>r      s    + 'r   