@@ -82,33 +82,38 @@ func SortSliceByValue(slice interface{}, hash uint64) {
8282 return
8383 }
8484
85- switch slice := slice .(type ) {
86- case [] int :
85+ switch val . Index ( 0 ). Interface () .(type ) {
86+ case int :
8787 var key = make ([]byte , 16 )
88+ slice := slice .([]int )
89+
8890 for i := 0 ; i < length ; i ++ {
8991 binary .BigEndian .PutUint64 (key , uint64 (slice [i ]))
9092 rule = append (rule , weight (Hash (key ), hash ))
9193 }
92- case [] int32 :
94+ case int32 :
9395 var key = make ([]byte , 16 )
96+ slice := slice .([]int32 )
97+
9498 for i := 0 ; i < length ; i ++ {
9599 binary .BigEndian .PutUint32 (key , uint32 (slice [i ]))
96100 rule = append (rule , weight (Hash (key ), hash ))
97101 }
98- case []string :
102+ case string :
103+ slice := slice .([]string )
104+
99105 for i := 0 ; i < length ; i ++ {
100106 rule = append (rule , weight (hash ,
101107 Hash ([]byte (slice [i ]))))
102108 }
103- default :
104- if _ , ok := val .Index (0 ).Interface ().(Hasher ); ! ok {
105- return
106- }
107-
109+ case Hasher :
108110 for i := 0 ; i < length ; i ++ {
109111 h := val .Index (i ).Interface ().(Hasher )
110112 rule = append (rule , weight (hash , h .Hash ()))
111113 }
114+
115+ default :
116+ return
112117 }
113118
114119 rule = SortByWeight (rule , hash )
0 commit comments