File: xsort.go

package info (click to toggle)
golang-github-christrenkamp-goxpath 1.0~alpha3%2Bgit20170922.c385f95-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 308 kB
  • sloc: sh: 16; makefile: 3; xml: 3
file content (20 lines) | stat: -rw-r--r-- 418 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package xsort

import (
	"sort"

	"github.com/ChrisTrenkamp/goxpath/tree"
)

type nodeSort []tree.Node

func (ns nodeSort) Len() int      { return len(ns) }
func (ns nodeSort) Swap(i, j int) { ns[i], ns[j] = ns[j], ns[i] }
func (ns nodeSort) Less(i, j int) bool {
	return ns[i].Pos() < ns[j].Pos()
}

//SortNodes sorts the array by the node document order
func SortNodes(res []tree.Node) {
	sort.Sort(nodeSort(res))
}