-
Notifications
You must be signed in to change notification settings - Fork 0
/
interestsmap.go
46 lines (37 loc) · 961 Bytes
/
interestsmap.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
package main
import funk "github.com/thoas/go-funk"
type InterestsMap map[string][]int
func (m *InterestsMap) Append(accountId int, interests []string) {
for _, interest := range interests {
if _, ok := (*m)[interest]; !ok {
(*m)[interest] = make([]int, 0)
}
(*m)[interest] = append((*m)[interest], accountId)
}
}
func (m *InterestsMap) AccountsWithInterestsAny(interests []string) (ids []int) {
for _, interest := range interests {
if _, ok := (*m)[interest]; ok {
ids = append(ids, (*m)[interest]...)
}
}
ids = funk.UniqInt(ids)
return
}
func (m *InterestsMap) AccountsWithInterestsContains(interests []string) (ids []int) {
var result *[]int
for _, interest := range interests {
if news, ok := (*m)[interest]; ok {
if result == nil {
result = &[]int{}
*result = append(*result, news...)
} else {
*result = funk.Intersect(*result, news).([]int)
}
}
}
if result != nil {
ids = *result
}
return
}