-
Notifications
You must be signed in to change notification settings - Fork 0
/
plist.go
60 lines (51 loc) · 812 Bytes
/
plist.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
package astar
import (
"fmt"
)
// PList ...
type PList []*Point
// NewPList ...
func NewPList(size int) PList {
l := make(PList, size)
return l
}
// Append ...
func (l *PList) Append(p *Point) {
*l = append(*l, p)
}
// Front ...
func (l *PList) Front(p *Point) {
*l = append(PList{p}, *l...)
}
// Remove ...
func (l *PList) Remove(p *Point) {
new := PList{}
for _, pt := range *l {
if pt.X == p.X && pt.Y == p.Y {
continue
}
new.Append(pt)
}
*l = new
}
// Clear ...
func (l *PList) Clear() {
*l = nil
}
// Find ...
func (l *PList) Find(p *Point) int {
for i, pt := range *l {
if pt.X == p.X && pt.Y == p.Y {
return i
}
}
return -1
}
// String ...
func (l PList) String() string {
var s string
for _, p := range l {
s += fmt.Sprintf("(%v, %v) ", p.X, p.Y)
}
return s
}