counter

package
Version: v0.0.0-...-93f7a3c Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2019 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SortAsc = SortBy(func(d1, d2 *Dict) bool {
	return d1.Value < d2.Value
})

SortAsc is a SortBy function for sorting in descending order based on values

View Source
var SortDesc = SortBy(func(d1, d2 *Dict) bool {
	return d1.Value > d2.Value
})

SortDesc is a SortBy function for sorting in descending order based on values

Functions

This section is empty.

Types

type Counter

type Counter struct {
	Dict       []Dict
	SortByFunc SortBy
	// contains filtered or unexported fields
}

Counter is an interface that allows for counting the number of unique keys added to the map so it can be sorted

func New

func New() *Counter

New returns an initialized Counter

func (*Counter) Increment

func (m *Counter) Increment(key string)

Increment increments the counter for the supplied key

func (*Counter) Len

func (m *Counter) Len() int

Len is part of sort.Interface.

func (*Counter) Less

func (m *Counter) Less(i, j int) bool

Less is part of sort.Interface. We use value as the value to sort by

func (*Counter) Swap

func (m *Counter) Swap(i, j int)

Swap is part of sort.Interface.

type Dict

type Dict struct {
	Key   string
	Value int
}

Dict is a "Dictionary" entry that is used to sort based on the value

type SortBy

type SortBy func(d1, d2 *Dict) bool

SortBy is the type of a "less" function that defines the ordering. Based on: https://golang.org/pkg/sort/#example__sortKeys

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL