1
2
3
4
5
6
7 package spec
8
9 import (
10 "fmt"
11 "strings"
12 )
13
14
15 func Len[E EltOrMask, W Width](x Vec[E, W]) int {
16 return x.len()
17 }
18
19
20
21
22 func GetElem[E Elt, W Width](x Vec[E, W], i uint8) (z E) {
23 return x[i]
24 }
25
26
27
28
29
30 func SetElem[E Elt, W Width](x Vec[E, W], i uint8, y E) (z Vec[E, W]) {
31 z = makeVec[E, W]()
32 copy(z, x)
33 z[i] = y
34 return z
35 }
36
37
38 func String[E Nums, W Width](x Vec[E, W]) string {
39 var buf strings.Builder
40 buf.WriteByte('{')
41 for i, val := range x {
42 if i > 0 {
43 buf.WriteByte(',')
44 }
45 fmt.Fprint(&buf, val)
46 }
47 buf.WriteByte('}')
48 return buf.String()
49 }
50
51
52
53
54
55 func StringMask[E MaskElt, W Width](x Vec[E, W]) string {
56 var buf strings.Builder
57 buf.WriteByte('{')
58 for i, val := range x {
59 if i > 0 {
60 buf.WriteByte(',')
61 }
62 if val == 0 {
63 buf.WriteByte('0')
64 } else {
65 buf.WriteByte('1')
66 }
67 }
68 buf.WriteByte('}')
69 return buf.String()
70 }
71
View as plain text