@@ -342,10 +342,10 @@ func (s *TreeSet[T, C]) Empty() bool {
342342// Slice returns the elements of s as a slice, in order.
343343func (s * TreeSet [T , C ]) Slice () []T {
344344 result := make ([]T , 0 , s .Size ())
345- s .infix (func (n * node [ T ] ) bool {
346- result = append (result , n . element )
345+ s .ForEach (func (element T ) bool {
346+ result = append (result , element )
347347 return true
348- }, s . root )
348+ })
349349 return result
350350}
351351
@@ -496,10 +496,10 @@ func (s *TreeSet[T, C]) String() string {
496496// element into a string. The result contains elements in order.
497497func (s * TreeSet [T , C ]) StringFunc (f func (element T ) string ) string {
498498 l := make ([]string , 0 , s .Size ())
499- s .infix (func (n * node [ T ] ) bool {
500- l = append (l , f (n . element ))
499+ s .ForEach (func (element T ) bool {
500+ l = append (l , f (element ))
501501 return true
502- }, s . root )
502+ })
503503 return fmt .Sprintf ("%s" , l )
504504}
505505
@@ -912,15 +912,17 @@ func (s *TreeSet[T, C]) compare(a, b *node[T]) int {
912912// TreeNodeVisit is a function that is called for each node in the tree.
913913type TreeNodeVisit [T any ] func (* node [T ]) (next bool )
914914
915- func (s * TreeSet [T , C ]) infix (visit TreeNodeVisit [T ], n * node [T ]) {
915+ func (s * TreeSet [T , C ]) infix (visit TreeNodeVisit [T ], n * node [T ]) ( next bool ) {
916916 if n == nil {
917+ return true
918+ }
919+ if next = s .infix (visit , n .left ); ! next {
917920 return
918921 }
919- s .infix (visit , n .left )
920- if ! visit (n ) {
922+ if next = visit (n ); ! next {
921923 return
922924 }
923- s .infix (visit , n .right )
925+ return s .infix (visit , n .right )
924926}
925927
926928func (s * TreeSet [T , C ]) fillLeft (n * node [T ], k * []T ) {
0 commit comments