package data import ( json "github.com/json-iterator/go" "github.com/oylshe1314/framework/util" ) type FunctionOpen struct { Id int `json:"id"` FuncMod int `json:"func_mod"` FuncType int `json:"func_type"` FuncId int `json:"func_id"` UnlockType []int `json:"unlock_type"` UnlockArgs []int `json:"unlock_args"` Show bool `json:"show"` TipMsg string `json:"tip_msg"` } type FunctionOpenTable struct { l []*FunctionOpen m1 map[uint64][]*FunctionOpen m2 map[uint64]map[int]*FunctionOpen } func (this *FunctionOpenTable) load(buf []byte) error { var err = json.Unmarshal(buf, &this.l) if err != nil { return err } this.m1 = make(map[uint64][]*FunctionOpen) this.m2 = make(map[uint64]map[int]*FunctionOpen) for i := range this.l { var key = util.Compose2uint32(uint32(this.l[i].FuncMod), uint32(this.l[i].FuncType)) this.m1[key] = append(this.m1[key], this.l[i]) var sm = this.m2[key] if sm == nil { sm = make(map[int]*FunctionOpen) this.m2[key] = sm } sm[this.l[i].FuncId] = this.l[i] } return nil } func (this *FunctionOpenTable) Find1(funcMod, funcType int) []*FunctionOpen { return this.m1[util.Compose2uint32(uint32(funcMod), uint32(funcType))] } func (this *FunctionOpenTable) Find2(funcMod, funcType, funcId int) *FunctionOpen { var sm = this.m1[util.Compose2uint32(uint32(funcMod), uint32(funcType))] if sm == nil { return nil } return sm[funcId] }