SetLen sets the length of the slice, copying values if a new allocation is required
(ln int)
| 59 | |
| 60 | // SetLen sets the length of the slice, copying values if a new allocation is required |
| 61 | func (bs *Slice) SetLen(ln int) { |
| 62 | by, bi := BitIndex(ln) |
| 63 | bln := by |
| 64 | if bi != 0 { |
| 65 | bln++ |
| 66 | } |
| 67 | if cap(*bs) >= bln+1 { |
| 68 | *bs = (*bs)[0 : bln+1] |
| 69 | (*bs)[0] = byte(bi) |
| 70 | } else { |
| 71 | sl := make(Slice, bln+1) |
| 72 | sl[0] = byte(bi) |
| 73 | copy(sl, *bs) |
| 74 | *bs = sl |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // Set sets value of given bit index -- no extra range checking is performed -- will panic if out of range |
| 79 | func (bs *Slice) Set(idx int, val bool) { |
no test coverage detected