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

mlange-42 / arche / 4903779843

06 May 2023 09:50PM CUT coverage: 100.0%. Remained the same
4903779843

push

github

GitHub
Optimize archetype iteration (#272)

38 of 38 new or added lines in 3 files covered. (100.0%)

3719 of 3719 relevant lines covered (100.0%)

85808.07 hits per line

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

100.0
/ecs/archetypes.go
1
package ecs
2

3
// Interface for an iterator over multiple archetypes.
4
type nodes interface {
5
        Get(index int32) *archNode
6
        Len() int32
7
}
8

9
// Interface for an iterator over archetypes.
10
type archetypes interface {
11
        Get(index int32) *archetype
12
        Len() int32
13
}
14

15
// Implementation of an archetype iterator for a single archetype.
16
// Implements [archetypes].
17
type singleArchetype struct {
18
        Archetype *archetype
19
}
20

21
// Get returns the value at the given index.
22
func (s singleArchetype) Get(index int32) *archetype {
100,568✔
23
        return s.Archetype
100,568✔
24
}
100,568✔
25

26
// Len returns the current number of items in the paged array.
27
func (s singleArchetype) Len() int32 {
100,568✔
28
        return 1
100,568✔
29
}
100,568✔
30

31
// Implementation of an archetype iterator for a single archetype and partial iteration.
32
// Implements [archetypes].
33
//
34
// Used for the [Query] returned by entity batch creation methods.
35
type batchArchetype struct {
36
        Archetype    *archetype
37
        StartIndex   uint32
38
        EndIndex     uint32
39
        OldArchetype *archetype
40
        Added        []ID
41
        Removed      []ID
42
}
43

44
// Get returns the value at the given index.
45
func (s *batchArchetype) Get(index int32) *archetype {
35✔
46
        return s.Archetype
35✔
47
}
35✔
48

49
// Len returns the current number of items in the paged array.
50
func (s *batchArchetype) Len() int32 {
76✔
51
        return 1
76✔
52
}
76✔
53

54
// Implementation of an archetype iterator for pointers.
55
// Implements [archetypes].
56
//
57
// Used for tracking filter archetypes in [Cache].
58
type archetypePointers struct {
59
        pointers []*archetype
60
}
61

62
// Get returns the value at the given index.
63
func (a *archetypePointers) Get(index int32) *archetype {
25,104✔
64
        return a.pointers[index]
25,104✔
65
}
25,104✔
66

67
// Add an element.
68
func (a *archetypePointers) Add(arch *archetype) {
22✔
69
        a.pointers = append(a.pointers, arch)
22✔
70
}
22✔
71

72
// Remove an element.
73
func (a *archetypePointers) Remove(arch *archetype) {
2✔
74
        ln := len(a.pointers)
2✔
75
        for i := 0; i < ln; i++ {
5✔
76
                arch2 := a.pointers[i]
3✔
77
                if arch == arch2 {
5✔
78
                        a.pointers[i], a.pointers[ln-1] = a.pointers[ln-1], nil
2✔
79
                        a.pointers = a.pointers[:ln-1]
2✔
80
                        return
2✔
81
                }
2✔
82
        }
83
}
84

85
// Len returns the current number of items in the paged array.
86
func (a *archetypePointers) Len() int32 {
25,059✔
87
        return int32(len(a.pointers))
25,059✔
88
}
25,059✔
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