• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / arche / 7464066922

09 Jan 2024 04:37PM CUT coverage: 100.0%. Remained the same
7464066922

push

github

web-flow
Extend to a maximum of 256 component types (#313)

Rework `Mask` to hold an array of 4 x `uint64` to represent 256 bits. Everything else comes into place almost by itself.

Alternative to #312:

- `Filter.Match` takes a mask pointer as argument
- `Mask` is copied when using as a filter (is pointer receiver in #312)

Primarily avoids `All(ids...)` either returning a pointer, or requiring users to store the result (temporarily) to be able to get a pointer to it.

Performance remains unchanged, except that `MaskFilter` matches are about 3 times slower (i.e. filters with component inclusion and exclusion). Not sure why, as the mask functions used there are as fast as before.

## Commits

* Extend to a maximum of 256 component types
* fix IdMap for 265 possible IDs
* filters match against pointer to mask, to avoid copying
* minor optimization: check for zero mask at end of MaskFilter conditions
* make internal Mask representation private
* update changelog and readme

3835 of 3835 relevant lines covered (100.0%)

83072.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/ecs/bitset.go
1
package ecs
2

3
// Data structure for compact storage of booleans.
4
type bitSet struct {
5
        data []uint64
6
}
7

8
// Get a value.
9
func (b *bitSet) Get(bit eid) bool {
2,525,717✔
10
        chunk, bit := bit/wordSize, bit%wordSize
2,525,717✔
11
        mask := uint64(1 << bit)
2,525,717✔
12
        return b.data[chunk]&mask == mask
2,525,717✔
13
}
2,525,717✔
14

15
// Set a value.
16
func (b *bitSet) Set(bit eid, value bool) {
2,837,836✔
17
        chunk, bit := bit/wordSize, bit%wordSize
2,837,836✔
18
        if value {
2,867,908✔
19
                b.data[chunk] |= uint64(1 << bit)
30,072✔
20
        } else {
2,837,836✔
21
                b.data[chunk] &= uint64(^(1 << bit))
2,807,764✔
22
        }
2,807,764✔
23
}
24

25
// Reset all values.
26
func (b *bitSet) Reset() {
33✔
27
        for i := range b.data {
3,900✔
28
                b.data[i] = 0
3,867✔
29
        }
3,867✔
30
}
31

32
// Extend to hold at least the given bits.
33
func (b *bitSet) ExtendTo(length int) {
32,782✔
34
        chunks, bit := length/wordSize, length%wordSize
32,782✔
35
        if bit > 0 {
37,918✔
36
                chunks++
5,136✔
37
        }
5,136✔
38
        if len(b.data) >= chunks {
65,271✔
39
                return
32,489✔
40
        }
32,489✔
41

42
        old := b.data
293✔
43
        b.data = make([]uint64, chunks)
293✔
44

293✔
45
        copy(b.data, old)
293✔
46
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc