code: func collapseTags(ts tags, count int) tags {
  	if len(ts) <= count {
  		return ts
  	}
  
  	sort.Sort(ts)
  	tagGroups := make([]tags, count)
  	for i, t := range ts[:count] {
  		tagGroups[i] = tags{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 tags
  	for _, g := range tagGroups {
  		l, w := tagGroupLabel(g)
  		nts = append(nts, &tag{
  			name:   l,
  			weight: w,
  		})
  	}
  	return nts
  }
docs: // collapseTags reduces the number of entries in a tagMap by merging
  // adjacent nodes into ranges. It uses a greedy approach to merge
  // starting with the entries with the lowest weight.