ranking

package
v0.0.0-...-3c22c5d Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultPriorityQueueSize = 10000

DefaultPriorityQueueSize max priority queue size

View Source
const SortedSetKey = "location-ranking"

Variables

This section is empty.

Functions

This section is empty.

Types

type InMemory

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

InMemory defines an inMemory ranking in top of a priority queue over the heap

func NewInMemory

func NewInMemory(size int) *InMemory

NewInMemory instantiates inMemory ranking

func (*InMemory) IncreaseScore

func (i *InMemory) IncreaseScore(_ context.Context, city string) error

IncreaseScore city score increase by 1

func (*InMemory) Len

func (i *InMemory) Len(_ context.Context) (int64, error)

Len returns ranking size

func (*InMemory) Top

func (i *InMemory) Top(_ context.Context, size int) ([]*provider.Location, error)

Top returns priority queue from head up to "size" length

type PriorityQueue

type PriorityQueue []*provider.Location

A PriorityQueue implements heap.Interface and holds Locations.

func (PriorityQueue) Len

func (pq PriorityQueue) Len() int

Len returns priority queue size

func (PriorityQueue) Less

func (pq PriorityQueue) Less(i, j int) bool

Less comparative method between locations

func (*PriorityQueue) Pop

func (pq *PriorityQueue) Pop() interface{}

Pop remove and returns last element on priority queue

func (*PriorityQueue) Push

func (pq *PriorityQueue) Push(x interface{})

Push inserts a location in the top of the priority queue

func (PriorityQueue) Swap

func (pq PriorityQueue) Swap(i, j int)

Swap exchanges 2 locations

type Redis

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

Redis implements a redis baked ranking in top of a sorted set

func NewRedis

func NewRedis(cl *redis.Client) *Redis

NewRedis instantiates redis ranking

func (*Redis) IncreaseScore

func (r *Redis) IncreaseScore(ctx context.Context, city string) error

IncreaseScore city score increase by 1

func (*Redis) Len

func (r *Redis) Len(ctx context.Context) (int64, error)

Len returns ranking size

func (*Redis) Top

func (r *Redis) Top(ctx context.Context, size int) ([]*provider.Location, error)

Top returns priority queue from head up to "size" length

Jump to

Keyboard shortcuts

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