store

package
v0.0.0-...-a39819d Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2016 License: GPL-3.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const (
	StringType = iota
	IntType    = iota
	SetType    = iota
)
View Source
const (
	MINSCORE = "-inf"
	MAXSCORE = "+inf"
)

Variables

View Source
var (
	NilTime = time.Time{}
)

Functions

func ToScoreF

func ToScoreF(score string) float64

func ToScoreS

func ToScoreS(score float64) string

Types

type Bucket

type Bucket struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Holds keyvalue with synchronized for concurrent access

func NewBucket

func NewBucket(id int) *Bucket

func (*Bucket) Cleanup

func (b *Bucket) Cleanup()

Delete expired keyvalues from bucket

func (*Bucket) Get

func (b *Bucket) Get(key string) (KeyValue, bool)

Return false if key is expired

func (*Bucket) Load

func (b *Bucket) Load(fileName string) (bool, error)

Load the bucket from json file

func (*Bucket) Save

func (b *Bucket) Save(filePath string) (string, error)

Save the bucket to json file

func (*Bucket) Set

func (b *Bucket) Set(kv KeyValue)

type DB

type DB struct {
	Files map[string]string `json:"files"`
}

type KeyValue

type KeyValue struct {
	Key        string       `json:"key"`
	Value      []byte       `json:"value"`
	Expiration time.Time    `json:"expiration"`
	ValueType  int          `json:"valueType"`
	Scores     SortedScores `json:"scores"`
}

type ScoreMember

type ScoreMember struct {
	Member string `json:"member"`
	//String type is required to save the value in json
	Score string `json:"score"`
}

Holds Score-Member pair

type SortedScores

type SortedScores struct {
	Scores  map[string]ScoreMember `json:"scores"`
	Members []string               `json:"members"`
	Ranks   map[string]string      `json:"ranks"`
}

Holds Score-Member along with the knowledge of their ranks and order

func NewSortedScores

func NewSortedScores() SortedScores

func (*SortedScores) Add

func (s *SortedScores) Add(scoreMember ScoreMember)

Ensure both the map and array is consistent

func (*SortedScores) BuildRank

func (s *SortedScores) BuildRank()

Array [1, 2, 3] will have Rank{0, -3} = 1 Rank{1, -2} = 2 Rank{2, -1} = 3 BuildRank will store the Ranks and their index to Members array for easy access

func (*SortedScores) Count

func (s *SortedScores) Count(min, max string) int

Return number of elements (min, max) min, max are inclusive

func (*SortedScores) Get

func (s *SortedScores) Get(member string) (ScoreMember, bool)

func (SortedScores) Len

func (s SortedScores) Len() int

func (SortedScores) Less

func (s SortedScores) Less(prev, next int) bool

func (*SortedScores) Range

func (s *SortedScores) Range(start, stop int) []ScoreMember

Returns slice of ScoreMember within the range

func (SortedScores) Swap

func (s SortedScores) Swap(i, j int)

Jump to

Keyboard shortcuts

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