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 func String[E Nums, W Width](x Vec[E, W]) string {
21 var buf strings.Builder
22 buf.WriteByte('{')
23 for i, val := range x {
24 if i > 0 {
25 buf.WriteByte(',')
26 }
27 fmt.Fprint(&buf, val)
28 }
29 buf.WriteByte('}')
30 return buf.String()
31 }
32
33
34
35
36
37 func StringMask[E MaskElt, W Width](x Vec[E, W]) string {
38 var buf strings.Builder
39 buf.WriteByte('{')
40 for i, val := range x {
41 if i > 0 {
42 buf.WriteByte(',')
43 }
44 if val == 0 {
45 buf.WriteByte('0')
46 } else {
47 buf.WriteByte('1')
48 }
49 }
50 buf.WriteByte('}')
51 return buf.String()
52 }
53
View as plain text