Documentation ¶
Index ¶
- Constants
- Variables
- func ToScoreF(score string) float64
- func ToScoreS(score float64) string
- type Bucket
- type DB
- type KeyValue
- type ScoreMember
- type SortedScores
- func (s *SortedScores) Add(scoreMember ScoreMember)
- func (s *SortedScores) BuildRank()
- func (s *SortedScores) Count(min, max string) int
- func (s *SortedScores) Get(member string) (ScoreMember, bool)
- func (s SortedScores) Len() int
- func (s SortedScores) Less(prev, next int) bool
- func (s *SortedScores) Range(start, stop int) []ScoreMember
- func (s SortedScores) Swap(i, j int)
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 ¶
Types ¶
type Bucket ¶
Holds keyvalue with synchronized for concurrent access
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)
Click to show internal directories.
Click to hide internal directories.