zhash

package
Version: v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package zhash implements a kiwi.Value which can store a hash with each element having a value and a score.

Index

Constants

View Source
const (
	// Insert inserts the element(s) in the zhash.
	// Default score is 0.
	// If element is already present, updates the score to 0.
	//
	// Returns an array of added elements.
	Insert kiwi.Action = "INSERT"

	// Remove removes the element(s) from the zhash.
	//
	// Returns an array of removed elements.
	Remove kiwi.Action = "REMOVE"

	// Increment increments the score by given value.
	//
	// Returns updated score.
	Increment kiwi.Action = "INCREMENT"

	// Len gets the length of the zhash.
	//
	// Returns an integer.
	Len kiwi.Action = "LEN"

	// Get gets the score and vaue of given element.
	//
	// Returns an item struct containing score and value of element.
	Get kiwi.Action = "GET"

	// Set set the vaue of given element.
	//
	// Returns they element's key
	Set kiwi.Action = "SET"

	// PeekMax gets the element with maximum score.
	//
	// Returns string value.
	// Returns nil if zhash is empty.
	PeekMax kiwi.Action = "PEEKMAX"

	// PeekMin gets the element with minimum score.
	//
	// Returns string value.
	// Returns nil if zhash is empty.
	PeekMin kiwi.Action = "PEEKMIN"
)
View Source
const Type kiwi.ValueType = "zhash"

Type of zhash value.

Variables

View Source
var (
	ErrInvalidParamLen   = fmt.Errorf("not enough parameters")
	ErrInvalidParamType  = fmt.Errorf("invalid paramater type")
	ErrInvalidParamValue = fmt.Errorf("invalid parameter value")
)

Various errors for zhash value type.

Functions

This section is empty.

Types

type Item

type Item struct {
	Value string `json:"value"`
	Score int    `json:"score"`
}

Item contains the value and the score for a particular key present in the zhash

type Value

type Value struct{ sortedset.SortedSet }

Value can store a set of elements having scores.

It implements the kiwi.Value interface.

func (*Value) DoMap

func (v *Value) DoMap() map[kiwi.Action]kiwi.DoFunc

DoMap returns the map of v's actions with it's do functions.

func (*Value) FromJSON

func (v *Value) FromJSON(rawmessage json.RawMessage) error

FromJSON populates the s with the data from RawMessage

func (*Value) ToJSON

func (v *Value) ToJSON() (json.RawMessage, error)

ToJSON returns the raw byte array of v's data

func (*Value) Type

func (v *Value) Type() kiwi.ValueType

Type returns v's type, i.e., "zhash".

Source Files

Jump to

Keyboard shortcuts

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