MCPcopy Index your code
hub / github.com/codechenx/FastTableViewer / sortByNum

Method sortByNum

buffer.go:300–336  ·  view source on GitHub ↗

sortByNum sorts column by number format with optimized numeric conversion

(colIndex int, rev bool)

Source from the content-addressed store, hash-verified

298
299// sortByNum sorts column by number format with optimized numeric conversion
300func (b *Buffer) sortByNum(colIndex int, rev bool) {
301 hasHeader := I2B(b.rowFreeze)
302 dataRows := b.cont
303 if hasHeader {
304 dataRows = b.cont[1:]
305 }
306
307 // Create index-value pairs to sort
308 type numRow struct {
309 row []string
310 num float64
311 }
312
313 pairs := make([]numRow, len(dataRows))
314 for i := range dataRows {
315 pairs[i] = numRow{
316 row: dataRows[i],
317 num: parseNumericValueFast(dataRows[i][colIndex]),
318 }
319 }
320
321 // Sort the pairs
322 if rev {
323 sort.SliceStable(pairs, func(i, j int) bool {
324 return pairs[i].num > pairs[j].num
325 })
326 } else {
327 sort.SliceStable(pairs, func(i, j int) bool {
328 return pairs[i].num < pairs[j].num
329 })
330 }
331
332 // Copy back sorted rows
333 for i := range pairs {
334 dataRows[i] = pairs[i].row
335 }
336}
337
338// sortByDate sorts column by date format with optimized date parsing
339func (b *Buffer) sortByDate(colIndex int, rev bool) {

Callers 4

TestBuffer_sortByNumFunction · 0.80
TestBuffer_SortByNumFunction · 0.80
drawUIFunction · 0.80

Calls 2

I2BFunction · 0.85
parseNumericValueFastFunction · 0.85

Tested by 3

TestBuffer_sortByNumFunction · 0.64
TestBuffer_SortByNumFunction · 0.64