5
5
package gc
6
6
7
7
const (
8
- WORDBITS = 32
9
- WORDMASK = WORDBITS - 1
10
- WORDSHIFT = 5
8
+ wordBits = 32
9
+ wordMask = wordBits - 1
10
+ wordShift = 5
11
11
)
12
12
13
13
// A bvec is a bit vector.
@@ -17,7 +17,7 @@ type bvec struct {
17
17
}
18
18
19
19
func bvalloc (n int32 ) bvec {
20
- nword := (n + WORDBITS - 1 ) / WORDBITS
20
+ nword := (n + wordBits - 1 ) / wordBits
21
21
return bvec {n , make ([]uint32 , nword )}
22
22
}
23
23
@@ -28,7 +28,7 @@ type bulkBvec struct {
28
28
}
29
29
30
30
func bvbulkalloc (nbit int32 , count int32 ) bulkBvec {
31
- nword := (nbit + WORDBITS - 1 ) / WORDBITS
31
+ nword := (nbit + wordBits - 1 ) / wordBits
32
32
size := int64 (nword ) * int64 (count )
33
33
if int64 (int32 (size * 4 )) != size * 4 {
34
34
Fatalf ("bvbulkalloc too big: nbit=%d count=%d nword=%d size=%d" , nbit , count , nword , size )
@@ -66,24 +66,24 @@ func (bv bvec) Get(i int32) bool {
66
66
if i < 0 || i >= bv .n {
67
67
Fatalf ("bvget: index %d is out of bounds with length %d\n " , i , bv .n )
68
68
}
69
- mask := uint32 (1 << uint (i % WORDBITS ))
70
- return bv .b [i >> WORDSHIFT ]& mask != 0
69
+ mask := uint32 (1 << uint (i % wordBits ))
70
+ return bv .b [i >> wordShift ]& mask != 0
71
71
}
72
72
73
73
func (bv bvec ) Set (i int32 ) {
74
74
if i < 0 || i >= bv .n {
75
75
Fatalf ("bvset: index %d is out of bounds with length %d\n " , i , bv .n )
76
76
}
77
- mask := uint32 (1 << uint (i % WORDBITS ))
78
- bv .b [i / WORDBITS ] |= mask
77
+ mask := uint32 (1 << uint (i % wordBits ))
78
+ bv .b [i / wordBits ] |= mask
79
79
}
80
80
81
81
func (bv bvec ) Unset (i int32 ) {
82
82
if i < 0 || i >= bv .n {
83
83
Fatalf ("bvunset: index %d is out of bounds with length %d\n " , i , bv .n )
84
84
}
85
- mask := uint32 (1 << uint (i % WORDBITS ))
86
- bv .b [i / WORDBITS ] &^= mask
85
+ mask := uint32 (1 << uint (i % wordBits ))
86
+ bv .b [i / wordBits ] &^= mask
87
87
}
88
88
89
89
// bvnext returns the smallest index >= i for which bvget(bv, i) == 1.
@@ -94,11 +94,11 @@ func (bv bvec) Next(i int32) int32 {
94
94
}
95
95
96
96
// Jump i ahead to next word with bits.
97
- if bv .b [i >> WORDSHIFT ]>> uint (i & WORDMASK ) == 0 {
98
- i &^= WORDMASK
99
- i += WORDBITS
100
- for i < bv .n && bv .b [i >> WORDSHIFT ] == 0 {
101
- i += WORDBITS
97
+ if bv .b [i >> wordShift ]>> uint (i & wordMask ) == 0 {
98
+ i &^= wordMask
99
+ i += wordBits
100
+ for i < bv .n && bv .b [i >> wordShift ] == 0 {
101
+ i += wordBits
102
102
}
103
103
}
104
104
@@ -107,7 +107,7 @@ func (bv bvec) Next(i int32) int32 {
107
107
}
108
108
109
109
// Find 1 bit.
110
- w := bv .b [i >> WORDSHIFT ] >> uint (i & WORDMASK )
110
+ w := bv .b [i >> wordShift ] >> uint (i & wordMask )
111
111
112
112
for w & 1 == 0 {
113
113
w >>= 1
@@ -118,8 +118,8 @@ func (bv bvec) Next(i int32) int32 {
118
118
}
119
119
120
120
func (bv bvec ) IsEmpty () bool {
121
- for i := int32 (0 ); i < bv .n ; i += WORDBITS {
122
- if bv .b [i >> WORDSHIFT ] != 0 {
121
+ for i := int32 (0 ); i < bv .n ; i += wordBits {
122
+ if bv .b [i >> wordShift ] != 0 {
123
123
return false
124
124
}
125
125
}
@@ -129,7 +129,7 @@ func (bv bvec) IsEmpty() bool {
129
129
func (bv bvec ) Not () {
130
130
i := int32 (0 )
131
131
w := int32 (0 )
132
- for ; i < bv .n ; i , w = i + WORDBITS , w + 1 {
132
+ for ; i < bv .n ; i , w = i + wordBits , w + 1 {
133
133
bv .b [w ] = ^ bv .b [w ]
134
134
}
135
135
}
0 commit comments