排行榜优化
This commit is contained in:
parent
3010a597f8
commit
80f8ff91ba
|
@ -52,6 +52,15 @@ func (slf *RankingList[CompetitorID, Score]) Competitor(competitorId CompetitorI
|
|||
}
|
||||
}
|
||||
|
||||
func (slf *RankingList[CompetitorID, Score]) CompetitorIncrease(competitorId CompetitorID, score Score) {
|
||||
oldScore, err := slf.GetScore(competitorId)
|
||||
if err != nil {
|
||||
slf.Competitor(competitorId, score)
|
||||
} else {
|
||||
slf.Competitor(competitorId, oldScore+score)
|
||||
}
|
||||
}
|
||||
|
||||
func (slf *RankingList[CompetitorID, Score]) RemoveCompetitor(competitorId CompetitorID) {
|
||||
if !slf.competitors.Exist(competitorId) {
|
||||
return
|
||||
|
|
|
@ -5,6 +5,9 @@ type RankingList[CompetitorID comparable, Score comparable] interface {
|
|||
// Competitor 声明排行榜竞争者
|
||||
// - 如果竞争者存在的情况下,会更新已有成绩,否则新增竞争者
|
||||
Competitor(competitorId CompetitorID, score Score)
|
||||
// CompetitorIncrease 积分增量的形式竞争排行榜
|
||||
// - 如果竞争者存在的情况下,会更新已有成绩为增加score后的成绩,否则新增竞争者
|
||||
CompetitorIncrease(competitorId CompetitorID, score Score)
|
||||
// RemoveCompetitor 删除特定竞争者
|
||||
RemoveCompetitor(competitorId CompetitorID)
|
||||
// GetRank 获取竞争者排名
|
||||
|
|
Loading…
Reference in New Issue