MCPcopy Create free account
hub / github.com/cogentcore/core / SetLen

Method SetLen

tensor/bitslice/bitslice.go:61–76  ·  view source on GitHub ↗

SetLen sets the length of the slice, copying values if a new allocation is required

(ln int)

Source from the content-addressed store, hash-verified

59
60// SetLen sets the length of the slice, copying values if a new allocation is required
61func (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
79func (bs *Slice) Set(idx int, val bool) {

Callers 3

SetShapeMethod · 0.80
SetNumRowsMethod · 0.80
CopySliceRobustFunction · 0.80

Calls 1

BitIndexFunction · 0.85

Tested by

no test coverage detected