File: sort-slice.go.tmpl

package info (click to toggle)
golang-github-ugorji-go-codec 1.2.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bookworm-proposed-updates, experimental, forky, sid, trixie
  • size: 2,532 kB
  • sloc: sh: 462; python: 100; makefile: 4
file content (68 lines) | stat: -rw-r--r-- 2,003 bytes parent folder | download
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2012-2020 Ugorji Nwoke. All rights reserved.
// Use of this source code is governed by a MIT license found in the LICENSE file.

// Code generated from sort-slice.go.tmpl - DO NOT EDIT.

{{/*
xxxSlice
xxxIntf
xxxIntfSlice
xxxRv
xxxRvSlice

I'm now going to create them for
- sortables
- sortablesplus

With the parameters passed in sortables or sortablesplus,
'time, 'bytes' are special, and correspond to time.Time and []byte respectively.
*/}}

package codec

import (
	"time"
	"reflect"
	"bytes"
)

{{/* func init() { _ = time.Unix } */}}

{{define "T"}}
func (p {{ .Type }}) Len() int           { return len(p) }
func (p {{ .Type }}) Swap(i, j int)      { p[uint(i)], p[uint(j)] = p[uint(j)], p[uint(i)] }
func (p {{ .Type }}) Less(i, j int) bool {
	{{ if eq .Kind "bool"         }} return !p[uint(i)]{{.V}} && p[uint(j)]{{.V}}
    {{ else if eq .Kind "float32" }} return p[uint(i)]{{.V}} < p[uint(j)]{{.V}} || isNaN32(p[uint(i)]{{.V}}) && !isNaN32(p[uint(j)]{{.V}})
    {{ else if eq .Kind "float64" }} return p[uint(i)]{{.V}} < p[uint(j)]{{.V}} || isNaN64(p[uint(i)]{{.V}}) && !isNaN64(p[uint(j)]{{.V}})
    {{ else if eq .Kind "time"    }} return p[uint(i)]{{.V}}.Before(p[uint(j)]{{.V}})
    {{ else if eq .Kind "bytes"   }} return bytes.Compare(p[uint(i)]{{.V}}, p[uint(j)]{{.V}}) == -1
    {{ else                    }} return p[uint(i)]{{.V}} < p[uint(j)]{{.V}}
    {{ end -}}
}
{{end}}

{{range $i, $v := sortables }}{{ $t := tshort $v }}
type {{ $v }}Slice []{{ $t }}
{{template "T" args "Kind" $v "Type" (print $v "Slice") "V" ""}}
{{end}}

{{range $i, $v := sortablesplus }}{{ $t := tshort $v }}

type {{ $v }}Rv struct {
	v {{ $t }}
	r reflect.Value
}
type {{ $v }}RvSlice []{{ $v }}Rv
{{template "T" args "Kind" $v "Type" (print $v "RvSlice") "V" ".v"}}

{{if eq $v "bytes" "string" -}}
type {{ $v }}Intf struct {
	v {{ $t }}
	i interface{}
}
type {{ $v }}IntfSlice []{{ $v }}Intf
{{template "T" args "Kind" $v "Type" (print $v "IntfSlice") "V" ".v"}}
{{end}}

{{end}}