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

mlange-42 / arche / 4958046752

12 May 2023 10:55AM CUT coverage: 100.0%. Remained the same
4958046752

push

github

GitHub
Refine architecture section on entity relations (#294)

3782 of 3782 relevant lines covered (100.0%)

84279.69 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 archetypes.
4
type archetypes interface {
5
        Get(index int32) *archetype
6
        Len() int32
7
}
8

9
// Implementation of an archetype iterator for a single archetype.
10
// Implements [archetypes].
11
type singleArchetype struct {
12
        Archetype *archetype
13
}
14

15
// Get returns the value at the given index.
16
func (s singleArchetype) Get(index int32) *archetype {
100,576✔
17
        return s.Archetype
100,576✔
18
}
100,576✔
19

20
// Len returns the current number of items in the paged array.
21
func (s singleArchetype) Len() int32 {
100,108✔
22
        return 1
100,108✔
23
}
100,108✔
24

25
// Implementation of an archetype iterator for a single archetype and partial iteration.
26
// Implements [archetypes].
27
//
28
// Used for the [Query] returned by entity batch creation methods.
29
type batchArchetype struct {
30
        Archetype    *archetype
31
        StartIndex   uint32
32
        EndIndex     uint32
33
        OldArchetype *archetype
34
        Added        []ID
35
        Removed      []ID
36
}
37

38
// Get returns the value at the given index.
39
func (s *batchArchetype) Get(index int32) *archetype {
36✔
40
        return s.Archetype
36✔
41
}
36✔
42

43
// Len returns the current number of items in the paged array.
44
func (s *batchArchetype) Len() int32 {
1✔
45
        return 1
1✔
46
}
1✔
47

48
// Implementation of an archetype iterator for pointers.
49
// Implements [archetypes].
50
//
51
// Used for tracking filter archetypes in [Cache].
52
type pointers[T any] struct {
53
        pointers []*T
54
}
55

56
// Get returns the value at the given index.
57
func (a *pointers[T]) Get(index int32) *T {
9✔
58
        return a.pointers[index]
9✔
59
}
9✔
60

61
// Add an element.
62
func (a *pointers[T]) Add(elem *T) {
32✔
63
        a.pointers = append(a.pointers, elem)
32✔
64
}
32✔
65

66
// RemoveAt swap-removes an element at a given index.
67
//
68
// Returns whether it was a swap.
69
func (a *pointers[T]) RemoveAt(index int) bool {
9✔
70
        ln := len(a.pointers)
9✔
71
        if index == ln-1 {
13✔
72
                a.pointers[index] = nil
4✔
73
                a.pointers = a.pointers[:index]
4✔
74
                return false
4✔
75
        }
4✔
76
        a.pointers[index], a.pointers[ln-1] = a.pointers[ln-1], nil
5✔
77
        a.pointers = a.pointers[:ln-1]
5✔
78
        return true
5✔
79
}
80

81
// Len returns the current number of items in the paged array.
82
func (a *pointers[T]) Len() int32 {
20✔
83
        return int32(len(a.pointers))
20✔
84
}
20✔
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