-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpoolSync.go
76 lines (63 loc) · 1.17 KB
/
poolSync.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package evoli
import "sync"
type poolSync struct {
pool
sync.RWMutex
}
// NewPoolSync creates a sync implementation of Pool
func NewPoolSync(length int) Pool {
return &poolSync{
*NewPool(length).(*pool),
sync.RWMutex{},
}
}
func (p *poolSync) Add(e Evolution) {
p.Lock()
defer p.Unlock()
p.pool.Add(e)
}
func (p *poolSync) Delete(e Evolution) {
p.Lock()
defer p.Unlock()
p.pool.Delete(e)
}
func (p *poolSync) Has(e Evolution) bool {
p.RLock()
defer p.RUnlock()
return p.pool.Has(e)
}
func (p *poolSync) Evolutions() []Evolution {
p.RLock()
defer p.RUnlock()
return p.pool.Evolutions()
}
func (p *poolSync) Populations() []Population {
p.RLock()
defer p.RUnlock()
return p.pool.Populations()
}
func (p *poolSync) Individuals() []Individual {
p.RLock()
defer p.RUnlock()
return p.pool.Individuals()
}
func (p *poolSync) Alpha() Individual {
p.RLock()
defer p.RUnlock()
return p.pool.Alpha()
}
func (p *poolSync) Shuffle() {
p.Lock()
defer p.Unlock()
p.pool.Shuffle()
}
func (p *poolSync) Next() error {
p.Lock()
defer p.Unlock()
return p.pool.Next()
}
func (p *poolSync) NextAsync() error {
p.Lock()
defer p.Unlock()
return p.pool.NextAsync()
}