summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--registry/index.go26
-rw-r--r--registry/query.go21
-rw-r--r--registry/types.go19
3 files changed, 46 insertions, 20 deletions
diff --git a/registry/index.go b/registry/index.go
index c3ea178..c5f8d2c 100644
--- a/registry/index.go
+++ b/registry/index.go
@@ -5,11 +5,6 @@ import (
 	"time"
 )
 
-// NewUserIndex returns a new instance of a user index
-func NewUserIndex() *UserIndex {
-	return &UserIndex{}
-}
-
 // AddUser inserts a new user into the index. The *Data struct
 // contains the nickname and the time the user was added.
 func (index UserIndex) AddUser(nick string, url string) {
@@ -28,3 +23,24 @@ func (index UserIndex) DelUser(url string) {
 	delete(index, url)
 	imutex.Unlock()
 }
+
+// GetUserStatuses returns a TimeMap containing a user's statuses
+func (index UserIndex) GetUserStatuses(url string) TimeMap {
+	imutex.RLock()
+	status := index[url].Status
+	imutex.RUnlock()
+	return status
+}
+
+// GetStatuses returns a TimeMap containing all statuses
+func (index UserIndex) GetStatuses() TimeMap {
+	statuses := NewTimeMap()
+	imutex.RLock()
+	for _, v := range index {
+		for a, b := range v.Status {
+			statuses[a] = b
+		}
+	}
+	imutex.RUnlock()
+	return statuses
+}
diff --git a/registry/query.go b/registry/query.go
index 32f5c6c..ce22ab4 100644
--- a/registry/query.go
+++ b/registry/query.go
@@ -3,15 +3,14 @@ package registry
 import (
 	"sort"
 	"strings"
-	"time"
 )
 
 // QueryUser checks the user index for nicknames that contain the
 // nickname provided as an argument. Entries are returned sorted
 // by the date they were added to the index.
 func (index UserIndex) QueryUser(name string) []string {
-	var timekey = map[time.Time]string{}
-	var keys TimeSlice
+	timekey := NewTimeMap()
+	keys := make(TimeSlice, 0)
 	var users []string
 	imutex.RLock()
 	for k, v := range index {
@@ -32,7 +31,7 @@ func (index UserIndex) QueryUser(name string) []string {
 // QueryTag returns all the known statuses that
 // contain the provided tag.
 func (index UserIndex) QueryTag(tag string) []string {
-	var statusmap TimeMapSlice
+	statusmap := NewTimeMapSlice()
 	i := 0
 	imutex.RLock()
 	for _, v := range index {
@@ -47,7 +46,7 @@ func (index UserIndex) QueryTag(tag string) []string {
 // FindTag takes a user's tweets and looks for a given tag.
 // Returns the tweets with the tag as a []string.
 func (userdata *Data) FindTag(tag string) TimeMap {
-	var statuses TimeMap
+	statuses := NewTimeMap()
 	for k, e := range userdata.Status {
 		parts := strings.Split(e, "\t")
 		statusslice := strings.Split(parts[3], " ")
@@ -65,8 +64,8 @@ func (userdata *Data) FindTag(tag string) TimeMap {
 // SortByTime returns a string slice of the query results
 // sorted by time.Time
 func (tm TimeMapSlice) SortByTime() []string {
-	var unionmap TimeMap
-	var times TimeSlice
+	var unionmap = NewTimeMap()
+	var times = make(TimeSlice, 0)
 	var data []string
 	for _, e := range tm {
 		for k, v := range e {
@@ -83,11 +82,3 @@ func (tm TimeMapSlice) SortByTime() []string {
 
 	return data
 }
-
-// GetStatuses returns the string slice containing a user's statuses
-func (index UserIndex) GetStatuses(url string) TimeMap {
-	imutex.RLock()
-	status := index[url].Status
-	imutex.RUnlock()
-	return status
-}
diff --git a/registry/types.go b/registry/types.go
index 429c55c..6e8e7b1 100644
--- a/registry/types.go
+++ b/registry/types.go
@@ -9,6 +9,10 @@ import (
 type Indexer interface {
 	AddUser(string, string)
 	DelUser(string)
+	GetUserStatuses() TimeMap
+	GetStatuses() TimeMap
+	QueryUser(string) []string
+	QueryTag(string) []string
 }
 
 // UserIndex provides an index of users by URL
@@ -39,6 +43,21 @@ var imutex = sync.RWMutex{}
 // TimeSlice is used for sorting by timestamp.
 type TimeSlice []time.Time
 
+// NewUserIndex returns a new instance of a user index
+func NewUserIndex() *UserIndex {
+	return &UserIndex{}
+}
+
+// NewTimeMap returns an initialized TimeMap.
+func NewTimeMap() TimeMap {
+	return make(TimeMap)
+}
+
+// NewTimeMapSlice returns an initialized slice of TimeMaps with zero length.
+func NewTimeMapSlice() TimeMapSlice {
+	return make(TimeMapSlice, 0)
+}
+
 // Len returns the length of the slice to be sorted.
 // This helps satisfy sort.Interface with respect to TimeSlice.
 func (t TimeSlice) Len() int {
ss='oid'>a232af2f ^
6acea762 ^
a232af2f ^


79cb6ea5 ^


e35c2d68 ^
79cb6ea5 ^
e35c2d68 ^




79cb6ea5 ^


a232af2f ^
eed2f30e ^
22d93b76 ^
46a3b11c ^

22d93b76 ^
a232af2f ^
6acea762 ^
a232af2f ^



20037b7c ^
e35c2d68 ^

20037b7c ^


3315a7d3 ^
a232af2f ^

e35c2d68 ^
a232af2f ^

e35c2d68 ^
a232af2f ^



6acea762 ^
a232af2f ^

6acea762 ^
a232af2f ^

6acea762 ^
a232af2f ^


38b80618 ^
a232af2f ^




e35c2d68 ^

6acea762 ^

89fd0bf2 ^


e3a53f3a ^

46a3b11c ^
89fd0bf2 ^
48f6d48a ^
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148