File: node_test.go

package info (click to toggle)
golang-github-canonical-go-dqlite 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 712 kB
  • sloc: sh: 380; makefile: 5
file content (36 lines) | stat: -rw-r--r-- 583 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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package dqlite_test

import (
	"fmt"
	"sort"

	dqlite "github.com/canonical/go-dqlite/v2"
)

type infoSorter []dqlite.LastEntryInfo

func (is infoSorter) Len() int {
	return len(is)
}

func (is infoSorter) Less(i, j int) bool {
	return is[i].Before(is[j])
}

func (is infoSorter) Swap(i, j int) {
	is[i], is[j] = is[j], is[i]
}

func ExampleLastEntryInfo() {
	infos := []dqlite.LastEntryInfo{
		{Term: 1, Index: 2},
		{Term: 2, Index: 2},
		{Term: 1, Index: 1},
		{Term: 2, Index: 1},
	}
	sort.Sort(infoSorter(infos))
	fmt.Println(infos)
	// Output:
	// [{1 1} {1 2} {2 1} {2 2}]

}