forked from richyen/walker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
priorityurl.go
36 lines (30 loc) · 977 Bytes
/
priorityurl.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
package cassandra
// PriorityURL is a heap of URLs, where the next element Pop'ed off the list
// points to the oldest (as measured by LastCrawled) element in the list. This
// class is designed to be used with the container/heap package. This type is
// currently only used in generateSegments
type PriorityURL []*LinkInfo
// Returns the length of this PriorityURL
func (pq PriorityURL) Len() int {
return len(pq)
}
// Return logical less-than between two items in this PriorityURL
func (pq PriorityURL) Less(i, j int) bool {
return pq[i].URL.LastCrawled.Before(pq[j].URL.LastCrawled)
}
// Swap two items in this PriorityURL
func (pq PriorityURL) Swap(i, j int) {
pq[i], pq[j] = pq[j], pq[i]
}
// Push an item onto this PriorityURL
func (pq *PriorityURL) Push(x interface{}) {
*pq = append(*pq, x.(*LinkInfo))
}
// Pop an item onto this PriorityURL
func (pq *PriorityURL) Pop() interface{} {
old := *pq
n := len(old)
x := old[n-1]
*pq = old[0 : n-1]
return x
}