etcdserver: move int64Slice into pkg/types/

This commit is contained in:
Yicheng Qin 2014-10-06 15:12:02 -07:00
parent 314d425718
commit c15c3eab4c
3 changed files with 13 additions and 16 deletions

View File

@ -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)

View File

@ -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
pkg/types/slice.go Normal file
View File

@ -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] }