Codebase list golang-github-beorn7-perks / ee00b75
histogram: simplify remove Blake Mizerany 10 years ago
1 changed file(s) with 5 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
3636 }
3737
3838 func (bs *Bins) remove(n int) *Bin {
39 old := *bs
40 x := old[n]
41 h := old[0:n]
42 if n < len(old)-1 {
43 t := old[n+1:]
44 out := make([]*Bin, len(old)-1)
45 copy(out, h)
46 copy(out[len(h):], t)
47 *bs = out
48 } else {
49 *bs = h
39 a := *bs
40 if n < 0 || len(a) < n {
41 return nil
5042 }
43 x := a[n]
44 *bs = append(a[:n], a[n+1:]...)
5145 return x
5246 }
5347