ordering

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	L = map[string]T{
		"titles": OrderingTitles,
		"queued": OrderingQueued,
		"score":  OrderingScore,
		"corpus": OrderingCorpus,
	}

	F = map[T]C{
		OrderingTitles: func(a *dpb.Entry, b *dpb.Entry) int {
			var at string
			var bt string

			if len(a.GetTitles()) > 0 {
				at = strings.ToLower(a.GetTitles()[0])
			}
			if len(b.GetTitles()) > 0 {
				bt = strings.ToLower(b.GetTitles()[0])
			}
			return strings.Compare(at, bt)
		},
		OrderingCorpus: func(a *dpb.Entry, b *dpb.Entry) int {
			return strings.Compare(a.GetCorpus().String(), b.GetCorpus().String())
		},
		OrderingQueued: func(a *dpb.Entry, b *dpb.Entry) int {
			if a.GetQueued() && !b.GetQueued() {
				return -1
			}
			if b.GetQueued() && !a.GetQueued() {
				return 1
			}
			return 0
		},
		OrderingScore: func(a *dpb.Entry, b *dpb.Entry) int {
			if a.GetScore() > b.GetScore() {
				return -1
			}
			if a.GetScore() < b.GetScore() {
				return 1
			}
			return 0
		},
	}
)

Functions

func Order

func Order(entries []*dpb.Entry, orderings []T) ([]*dpb.Entry, error)

Types

type C

type C func(a *dpb.Entry, b *dpb.Entry) int

type S

type S struct {
	// contains filtered or unexported fields
}

func (*S) Len

func (s *S) Len() int

func (*S) Less

func (s *S) Less(i, j int) bool

func (*S) Swap

func (s *S) Swap(i, j int)

type T

type T int
const (
	OrderingUnknown T = iota
	OrderingTitles
	OrderingQueued
	OrderingScore
	OrderingCorpus
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL