-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve issues around negative permutation sorts
There are some genuinely hard problems with negative permutation sorts. The current solution is simply to prohibit permutation sorts whose "index column" (i.e. leftmost column) is negatively sorted. There is an additional issue that traces which have a `0` for this column prior to expansion will (most likely) be rejected.
- Loading branch information
1 parent
31e59dc
commit 953de6b
Showing
21 changed files
with
213 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package table | ||
|
||
import ( | ||
"fmt" | ||
"unicode/utf8" | ||
) | ||
|
||
// PrintTrace prints a trace in a more human-friendly fashion. | ||
func PrintTrace(tr Trace) { | ||
n := tr.Width() | ||
// | ||
rows := make([][]string, n) | ||
for i := uint(0); i < n; i++ { | ||
rows[i] = traceColumnData(tr, i) | ||
} | ||
// | ||
widths := traceRowWidths(tr.Height(), rows) | ||
// | ||
printHorizontalRule(widths) | ||
// | ||
for _, r := range rows { | ||
printTraceRow(r, widths) | ||
printHorizontalRule(widths) | ||
} | ||
} | ||
|
||
func traceColumnData(tr Trace, col uint) []string { | ||
n := tr.Height() | ||
data := make([]string, n+1) | ||
data[0] = tr.ColumnName(int(col)) | ||
|
||
for row := uint(0); row < n; row++ { | ||
data[row+1] = tr.GetByIndex(int(col), int(row)).String() | ||
} | ||
|
||
return data | ||
} | ||
|
||
func traceRowWidths(height uint, rows [][]string) []int { | ||
widths := make([]int, height+1) | ||
|
||
for _, row := range rows { | ||
for i, col := range row { | ||
w := utf8.RuneCountInString(col) | ||
widths[i] = max(w, widths[i]) | ||
} | ||
} | ||
|
||
return widths | ||
} | ||
|
||
func printTraceRow(row []string, widths []int) { | ||
for i, col := range row { | ||
fmt.Printf(" %*s |", widths[i], col) | ||
} | ||
|
||
fmt.Println() | ||
} | ||
|
||
func printHorizontalRule(widths []int) { | ||
for _, w := range widths { | ||
fmt.Print("-") | ||
|
||
for i := 0; i < w; i++ { | ||
fmt.Print("-") | ||
} | ||
fmt.Print("-+") | ||
} | ||
|
||
fmt.Println() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.