typeInterfaceinterface{// Len is the number of elements in the collection.
Len()int// Less reports whether the element with
// index i should sort before the element with index j.
Less(i,jint)bool// Swap swaps the elements with indexes i and j.
Swap(i,jint)}
func(table*CacheTable)MostAccessed(countint64)[]*CacheItem{table.RLock()defertable.RUnlock()p:=make(CacheItemPairList,len(table.items))i:=0fork,v:=rangetable.items{p[i]=CacheItemPair{k,v.accessCount}i++}sort.Sort(p)varr[]*CacheItemc:=int64(0)// p经过排序后,通过遍历构造新的items list
for_,v:=rangep{ifc>=count{break}item,ok:=table.items[v.Key]ifok{r=append(r,item)}c++}returnr}