StrSlicesSubstract finds all the strings which are in l but not in r, both slices shoult be sorted
(l, r []string)
| 104 | |
| 105 | // StrSlicesSubstract finds all the strings which are in l but not in r, both slices shoult be sorted |
| 106 | func StrSlicesSubstract(l, r []string) []string { |
| 107 | var result []string |
| 108 | |
| 109 | // pointer to left and right reflists |
| 110 | il, ir := 0, 0 |
| 111 | // length of reflists |
| 112 | ll, lr := len(l), len(r) |
| 113 | |
| 114 | for il < ll || ir < lr { |
| 115 | if il == ll { |
| 116 | // left list exhausted, we got the result |
| 117 | break |
| 118 | } |
| 119 | if ir == lr { |
| 120 | // right list exhausted, append what is left to result |
| 121 | result = append(result, l[il:]...) |
| 122 | break |
| 123 | } |
| 124 | |
| 125 | if l[il] == r[ir] { |
| 126 | // r contains entry from l, so we skip it |
| 127 | il++ |
| 128 | ir++ |
| 129 | } else if l[il] < r[ir] { |
| 130 | // item il is not in r, append |
| 131 | result = append(result, l[il]) |
| 132 | il++ |
| 133 | } else { |
| 134 | // skip over to next item in r |
| 135 | ir++ |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | return result |
| 140 | } |
no outgoing calls