github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/core/container/slice.go (about) 1 package container 2 3 type Slice[V comparable] []V 4 5 func (s *Slice[V]) Len() int { return len(*s) } 6 7 func (s *Slice[V]) Cap() int { return cap(*s) } 8 9 func (s *Slice[V]) Unique() { 10 mark := make(map[V]struct{}, len(*s)) 11 var count int 12 for _, v := range *s { 13 if _, ok := mark[v]; !ok { 14 (*s)[count] = v 15 mark[v] = struct{}{} 16 count++ 17 } 18 } 19 *s = (*s)[:count] 20 } 21 22 func (s *Slice[V]) AppendSingle(v V) { 23 *s = append(*s, v) 24 } 25 26 func (s *Slice[V]) Append(v []V) { 27 *s = append(*s, v...) 28 } 29 30 func (s *Slice[V]) AppendS(vs ...V) { 31 *s = append(*s, vs...) 32 } 33 34 func (s *Slice[V]) Available() bool { 35 return s != nil && len(*s) > 0 36 } 37 38 func (s *Slice[V]) Reset() { 39 *s = (*s)[:0] 40 }