-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeatures.go
More file actions
37 lines (35 loc) · 838 Bytes
/
features.go
File metadata and controls
37 lines (35 loc) · 838 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
package arcp
// IntersectFeatures returns the set of feature flags present in both a
// and b, in the order they appear in a. Used at handshake to compute
// the effective negotiated feature set.
func IntersectFeatures(a, b []string) []string {
if len(a) == 0 || len(b) == 0 {
return nil
}
want := make(map[string]struct{}, len(b))
for _, x := range b {
want[x] = struct{}{}
}
out := make([]string, 0, len(a))
seen := make(map[string]struct{}, len(a))
for _, x := range a {
if _, ok := want[x]; !ok {
continue
}
if _, dup := seen[x]; dup {
continue
}
seen[x] = struct{}{}
out = append(out, x)
}
return out
}
// HasFeature reports whether name appears in features.
func HasFeature(features []string, name string) bool {
for _, f := range features {
if f == name {
return true
}
}
return false
}