MergeSortedSlices merges a set of sorted string slices into a single ones while removing all duplicates.
(ctx context.Context, a ...[]string)
| 109 | // MergeSortedSlices merges a set of sorted string slices into a single ones |
| 110 | // while removing all duplicates. |
| 111 | func MergeSortedSlices(ctx context.Context, a ...[]string) ([]string, error) { |
| 112 | if len(a) == 1 { |
| 113 | return a[0], nil |
| 114 | } |
| 115 | its := make([]*StringListIter, 0, len(a)) |
| 116 | sumLengh := 0 |
| 117 | for _, s := range a { |
| 118 | sumLengh += len(s) |
| 119 | its = append(its, NewStringListIter(s)) |
| 120 | } |
| 121 | lt := loser.New(its, MAX_STRING) |
| 122 | |
| 123 | if sumLengh == 0 { |
| 124 | return []string{}, nil |
| 125 | } |
| 126 | |
| 127 | r := make([]string, 0, sumLengh*2/10) |
| 128 | var current string |
| 129 | cnt := 0 |
| 130 | for lt.Next() { |
| 131 | cnt++ |
| 132 | if cnt%CheckContextEveryNIterations == 0 && ctx.Err() != nil { |
| 133 | return nil, ctx.Err() |
| 134 | } |
| 135 | if lt.At() != current { |
| 136 | current = lt.At() |
| 137 | r = append(r, current) |
| 138 | } |
| 139 | } |
| 140 | return r, nil |
| 141 | } |
| 142 | |
| 143 | type Interner interface { |
| 144 | Intern(s string) string |
no test coverage detected