MCPcopy Create free account
hub / github.com/codechenx/FastTableViewer / sortByStr

Method sortByStr

buffer.go:271–297  ·  view source on GitHub ↗

sortByStr sorts the buffer by column in string mode colIndex: column to sort by rev: true for descending, false for ascending

(colIndex int, rev bool)

Source from the content-addressed store, hash-verified

269// colIndex: column to sort by
270// rev: true for descending, false for ascending
271func (b *Buffer) sortByStr(colIndex int, rev bool) {
272 hasHeader := I2B(b.rowFreeze)
273
274 if rev {
275 // Descending sort
276 if hasHeader {
277 sort.SliceStable(b.cont[1:], func(i, j int) bool {
278 return b.cont[1:][i][colIndex] > b.cont[1:][j][colIndex]
279 })
280 } else {
281 sort.SliceStable(b.cont, func(i, j int) bool {
282 return b.cont[i][colIndex] > b.cont[j][colIndex]
283 })
284 }
285 } else {
286 // Ascending sort
287 if hasHeader {
288 sort.SliceStable(b.cont[1:], func(i, j int) bool {
289 return b.cont[1:][i][colIndex] < b.cont[1:][j][colIndex]
290 })
291 } else {
292 sort.SliceStable(b.cont, func(i, j int) bool {
293 return b.cont[i][colIndex] < b.cont[j][colIndex]
294 })
295 }
296 }
297}
298
299// sortByNum sorts column by number format with optimized numeric conversion
300func (b *Buffer) sortByNum(colIndex int, rev bool) {

Callers 4

TestBuffer_sortByStrFunction · 0.80
TestBuffer_SortByStrFunction · 0.80
drawUIFunction · 0.80

Calls 1

I2BFunction · 0.85

Tested by 3

TestBuffer_sortByStrFunction · 0.64
TestBuffer_SortByStrFunction · 0.64