瀏覽代碼

etcdserver: switch to proper int64Slice for sorting

Jonathan Boulle 11 年之前
父節點
當前提交
e18b8c12be
共有 1 個文件被更改,包括 10 次插入4 次删除
  1. 10 4
      etcdserver/etcdhttp/peers_test.go

+ 10 - 4
etcdserver/etcdhttp/peers_test.go

@@ -63,14 +63,20 @@ func TestPeers(t *testing.T) {
 	}
 	}
 }
 }
 
 
+type int64Slice []int64
+
+func (p int64Slice) Len() int           { return len(p) }
+func (p int64Slice) Less(i, j int) bool { return p[i] < p[j] }
+func (p int64Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }
+
 func sortint64(list []int64) {
 func sortint64(list []int64) {
-	sorted := make(sort.IntSlice, len(list))
+	sorted := make(int64Slice, len(list))
 	for i, j := range list {
 	for i, j := range list {
-		sorted[i] = int(j)
+		sorted[i] = j
 	}
 	}
-	sorted.Sort()
+	sort.Sort(sorted)
 	for i, j := range sorted {
 	for i, j := range sorted {
-		list[i] = int64(j)
+		list[i] = j
 	}
 	}
 }
 }