This commit is contained in:
aozhiwei 2024-04-09 18:03:58 +08:00
parent 114ab01a4a
commit eaf14d6b2d
3 changed files with 49 additions and 9 deletions

View File

@ -27,6 +27,7 @@ const (
const (
MAX_PACKET_LEN = 1024 * 64
MAX_GUILD_TOP = 50
)
const (

View File

@ -21,6 +21,7 @@ type guild struct {
maxMemberNum int32
createTime int32
modifyTime int32
totalStars int32
idHash map[string]*member
}

View File

@ -9,16 +9,11 @@ import (
"mt"
)
const (
LoadGuildFlag = iota
LoadGuildMemberFlag
LoadGuildReqFlag
LoadGuildLogFlag
)
type guildMgr struct {
idHash map[string]*guild
nameHash map[string]*guild
guildRankList []*guild
guildRankHash map[string]*guild
memberIdHash map[string]*member
usingNameHash map[string]int64
}
@ -26,6 +21,8 @@ type guildMgr struct {
func (this *guildMgr) Init() {
this.idHash = make(map[string]*guild)
this.nameHash = make(map[string]*guild)
this.guildRankList = []*guild{}
this.guildRankHash = make(map[string]*guild)
this.memberIdHash = make(map[string]*member)
this.usingNameHash = make(map[string]int64)
this.loadFromDB()
@ -834,10 +831,51 @@ func (this *guildMgr) asyncSetApplyStatus(accountId string, guildId string, stat
cb)
}
func (this *guildMgr) AsyncGetGuildRank(int32, func(int32, string, []string)) {
func (this *guildMgr) AsyncGetGuildRank(num int32, cb func(int32, string, []string)) {
guildIds := []string{}
this.rearrangement()
cb(0, "", guildIds)
}
func (this *guildMgr) AsyncGetRecommendGuild(int32, func(int32, string, []string)) {
}
func (this *guildMgr) rearrangement() {
this.guildRankList = []*guild{}
this.guildRankHash = make(map[string]*guild)
this.traverseGuild(
func (g *guild) bool {
this.updateGuildRank(g)
return true
})
}
func (this* guildMgr) updateGuildRank(guild *guild) {
if _, ok := this.guildRankHash[guild.guildId]; ok {
this.rankSort()
return
}
if len(this.guildRankList) < constant.MAX_GUILD_TOP {
q5.AppendSlice(&this.guildRankList, guild)
this.guildRankHash[guild.guildId] = guild
this.rankSort()
} else if guild.totalStars > this.guildRankList[len(this.guildRankList) - 1].totalStars {
lastGuild := this.guildRankList[len(this.guildRankList) - 1]
delete(this.guildRankHash, lastGuild.guildId)
this.guildRankList[len(this.guildRankList) - 1] = guild
this.rankSort()
}
}
func (this* guildMgr) rankSort() {
}
func (this* guildMgr) traverseGuild(cb func(*guild) bool) {
for _, g := range(this.idHash) {
if !cb(g) {
break
}
}
}