diff options
| author | 2026-03-29 14:42:13 +0000 | |
|---|---|---|
| committer | 2026-03-29 14:47:04 +0000 | |
| commit | df73a4c6f1b58075316ba7449fbfb127b9fbb79d (patch) | |
| tree | 62fee259ec037410b06419ee3ac9c2c189c35ab3 /commitquery/reduce.go | |
| parent | internal/priorityqueue: Update docs (diff) | |
| signature | No signature | |
commitquery: Reorganize
Diffstat (limited to 'commitquery/reduce.go')
| -rw-r--r-- | commitquery/reduce.go | 166 |
1 files changed, 0 insertions, 166 deletions
diff --git a/commitquery/reduce.go b/commitquery/reduce.go deleted file mode 100644 index 46c3bf39..00000000 --- a/commitquery/reduce.go +++ /dev/null @@ -1,166 +0,0 @@ -package commitquery - -import ( - "slices" -) - -// removeRedundant removes redundant merge-base candidates. -func removeRedundant(query *query, candidates []nodeIndex) ([]nodeIndex, error) { - for _, idx := range candidates { - if query.effectiveGeneration(idx) != generationInfinity { - return removeRedundantWithGen(query, candidates), nil - } - } - - return removeRedundantNoGen(query, candidates) -} - -func removeRedundantNoGen(query *query, candidates []nodeIndex) ([]nodeIndex, error) { - redundant := make([]bool, len(candidates)) - work := make([]nodeIndex, 0, len(candidates)-1) - filledIndex := make([]int, 0, len(candidates)-1) - - for i, candidate := range candidates { - if redundant[i] { - continue - } - - work = work[:0] - filledIndex = filledIndex[:0] - - minGeneration := query.effectiveGeneration(candidate) - - for j, other := range candidates { - if i == j || redundant[j] { - continue - } - - work = append(work, other) - filledIndex = append(filledIndex, j) - - otherGeneration := query.effectiveGeneration(other) - if otherGeneration < minGeneration { - minGeneration = otherGeneration - } - } - - err := query.paintDownToCommon(candidate, work, minGeneration) - if err != nil { - return nil, err - } - - if query.hasAnyMarks(candidate, markRight) { - redundant[i] = true - } - - for j, other := range work { - if query.hasAnyMarks(other, markLeft) { - redundant[filledIndex[j]] = true - } - } - - query.clearTouchedMarks(allMarks) - } - - out := make([]nodeIndex, 0, len(candidates)) - for i, idx := range candidates { - if !redundant[i] { - out = append(out, idx) - } - } - - return out, nil -} - -func removeRedundantWithGen(query *query, candidates []nodeIndex) []nodeIndex { - sorted := append([]nodeIndex(nil), candidates...) - slices.SortFunc(sorted, query.compareByGeneration()) - - minGeneration := query.effectiveGeneration(sorted[0]) - minGenPos := 0 - countStillIndependent := len(candidates) - - query.beginMarkPhase() - - walkStart := make([]nodeIndex, 0, len(candidates)*2) - - for _, idx := range candidates { - query.setMarks(idx, markResult) - - for _, parent := range query.parents(idx) { - if query.hasAnyMarks(parent, markStale) { - continue - } - - query.setMarks(parent, markStale) - walkStart = append(walkStart, parent) - } - } - - slices.SortFunc(walkStart, query.compareByGeneration()) - - for _, idx := range walkStart { - query.clearMarks(idx, markStale) - } - - for i := len(walkStart) - 1; i >= 0 && countStillIndependent > 1; i-- { - stack := []nodeIndex{walkStart[i]} - query.setMarks(walkStart[i], markStale) - - for len(stack) > 0 { - top := stack[len(stack)-1] - - if query.hasAnyMarks(top, markResult) { - query.clearMarks(top, markResult) - - countStillIndependent-- - if countStillIndependent <= 1 { - break - } - - if top == sorted[minGenPos] { - for minGenPos < len(sorted)-1 && query.hasAnyMarks(sorted[minGenPos], markStale) { - minGenPos++ - } - - minGeneration = query.effectiveGeneration(sorted[minGenPos]) - } - } - - if query.effectiveGeneration(top) < minGeneration { - stack = stack[:len(stack)-1] - - continue - } - - pushed := false - - for _, parent := range query.parents(top) { - if query.hasAnyMarks(parent, markStale) { - continue - } - - query.setMarks(parent, markStale) - stack = append(stack, parent) - pushed = true - - break - } - - if !pushed { - stack = stack[:len(stack)-1] - } - } - } - - out := make([]nodeIndex, 0, len(candidates)) - for _, idx := range candidates { - if !query.hasAnyMarks(idx, markStale) { - out = append(out, idx) - } - } - - query.clearTouchedMarks(markStale | markResult) - - return out -} |
