histogram: simplify remove
Blake Mizerany
10 years ago
36 | 36 | } |
37 | 37 | |
38 | 38 | 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 | |
50 | 42 | } |
43 | x := a[n] | |
44 | *bs = append(a[:n], a[n+1:]...) | |
51 | 45 | return x |
52 | 46 | } |
53 | 47 |