Browse Source

etcdserver: move int64Slice into pkg/types/

Yicheng Qin 11 years ago
parent
commit
c15c3eab4c
3 changed files with 13 additions and 16 deletions
  1. 4 8
      etcdserver/cluster_test.go
  2. 1 8
      etcdserver/server.go
  3. 8 0
      pkg/types/slice.go

+ 4 - 8
etcdserver/cluster_test.go

@@ -4,6 +4,8 @@ import (
 	"reflect"
 	"sort"
 	"testing"
+
+	"github.com/coreos/etcd/pkg/types"
 )
 
 func TestClusterAddSlice(t *testing.T) {
@@ -201,12 +203,6 @@ func TestClusterSetBad(t *testing.T) {
 	}
 }
 
-type int64slice []int64
-
-func (a int64slice) Len() int           { return len(a) }
-func (a int64slice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
-func (a int64slice) Less(i, j int) bool { return a[i] < a[j] }
-
 func TestClusterIDs(t *testing.T) {
 	cs := Cluster{}
 	cs.AddSlice([]Member{
@@ -214,8 +210,8 @@ func TestClusterIDs(t *testing.T) {
 		{ID: 4},
 		{ID: 100},
 	})
-	w := int64slice([]int64{1, 4, 100})
-	g := int64slice(cs.IDs())
+	w := types.Int64Slice([]int64{1, 4, 100})
+	g := types.Int64Slice(cs.IDs())
 	sort.Sort(g)
 	if !reflect.DeepEqual(w, g) {
 		t.Errorf("IDs=%+v, want %+v", g, w)

+ 1 - 8
etcdserver/server.go

@@ -131,7 +131,7 @@ func NewServer(cfg *ServerConfig) *EtcdServer {
 			log.Fatal(err)
 		}
 		ids := cfg.Cluster.IDs()
-		sort.Sort(int64Slice(ids))
+		sort.Sort(types.Int64Slice(ids))
 		ccs := make([]raftpb.ConfChange, len(ids))
 		for i, id := range ids {
 			// TODO: add context for PeerURLs
@@ -560,10 +560,3 @@ func getBool(v *bool) (vv bool, set bool) {
 	}
 	return *v, true
 }
-
-// int64Slice implements sort interface
-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] }

+ 8 - 0
pkg/types/slice.go

@@ -0,0 +1,8 @@
+package types
+
+// Int64Slice implements sort interface
+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] }