-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathannotationSet.go
More file actions
46 lines (38 loc) · 826 Bytes
/
annotationSet.go
File metadata and controls
46 lines (38 loc) · 826 Bytes
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
package lingo
import (
"sort"
"unsafe"
"github.com/xtgo/set"
)
type AnnotationSet []*Annotation
func (as AnnotationSet) Len() int { return len(as) }
func (as AnnotationSet) Swap(i, j int) { as[i], as[j] = as[j], as[i] }
func (as AnnotationSet) Less(i, j int) bool {
return uintptr(unsafe.Pointer(as[i])) < uintptr(unsafe.Pointer(as[j]))
}
func (as AnnotationSet) Set() AnnotationSet {
sort.Sort(as)
n := set.Uniq(as)
return as[:n]
}
func (as AnnotationSet) Contains(a *Annotation) bool {
if as.Index(a) == len(as) {
return false
}
return true
}
func (as AnnotationSet) Index(a *Annotation) int {
for i, an := range as {
if an == a {
return i
}
}
return len(as)
}
func (as AnnotationSet) Add(a *Annotation) AnnotationSet {
if as.Contains(a) {
return as
}
as = append(as, a)
return as
}