-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinvidx.go
More file actions
76 lines (67 loc) · 1.56 KB
/
Copy pathinvidx.go
File metadata and controls
76 lines (67 loc) · 1.56 KB
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 main
type InvIdx struct {
inv_word_map map[string]map[string]uint
href_map map[string]struct {
title string
word_count uint
}
}
func NewInvIdx() *InvIdx {
return &InvIdx{
make(map[string]map[string]uint),
make(map[string]struct {
title string
word_count uint
}),
}
}
func (ii *InvIdx) GetAllDocs() (map[string]struct{}, error) {
docs := make(map[string]struct{})
for url := range ii.href_map {
docs[url] = struct{}{}
}
return docs, nil
}
func (ii *InvIdx) GetAllFreq(doc string) (map[string]uint, error) {
return ii.inv_word_map[doc], nil
}
func (ii *InvIdx) GetDocsWithWord(word string) (map[string]struct {
title string
word_count uint
freq uint
}, error) {
doc_map := make(map[string]struct {
title string
word_count uint
freq uint
})
for url, word_map := range ii.inv_word_map {
if freq, ok := word_map[word]; ok {
doc_map[url] = struct {
title string
word_count uint
freq uint
}{ii.href_map[url].title, ii.href_map[url].word_count, freq}
}
}
return doc_map, nil
}
func (ii *InvIdx) AddDocWithWords(title string, url string, wordcount uint, words map[string]uint) error {
ii.href_map[url] = struct {
title string
word_count uint
}{title, wordcount}
ii.inv_word_map[url] = words
return nil
}
func (ii *InvIdx) ContainsDoc(doc string) (bool, error) {
_, ok := ii.href_map[doc]
return ok, nil
}
func (ii *InvIdx) Size() (uint, error) {
return uint(len(ii.href_map)), nil
}
func (ii *InvIdx) DeleteDataBase() {
ii.inv_word_map = nil
ii.href_map = nil
}