code: func (b *builder) collapsedTags(ts []*Tag, count int, flatTags bool) []*Tag {
  	ts = SortTags(ts, flatTags)
  	if len(ts) <= count {
  		return ts
  	}
  
  	tagGroups := make([][]*Tag, count)
  	for i, t := range (ts)[:count] {
  		tagGroups[i] = []*Tag{t}
  	}
  	for _, t := range (ts)[count:] {
  		g, d := 0, tagDistance(t, tagGroups[0][0])
  		for i := 1; i < count; i++ {
  			if nd := tagDistance(t, tagGroups[i][0]); nd < d {
  				g, d = i, nd
  			}
  		}
  		tagGroups[g] = append(tagGroups[g], t)
  	}
  
  	var nts []*Tag
  	for _, g := range tagGroups {
  		l, w, c := b.tagGroupLabel(g)
  		nts = append(nts, &Tag{
  			Name: l,
  			Flat: w,
  			Cum:  c,
  		})
  	}
  	return SortTags(nts, flatTags)
  }
docs: // collapsedTags trims and sorts a slice of tags.