-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add priority queue for repository cloning (#40)
* Add priority queue for repository cloning * Update dependencies in go.mod files and docker compose
- Loading branch information
1 parent
a1b7e56
commit 84477ea
Showing
11 changed files
with
150 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import "container/heap" | ||
|
||
/// Based on the example from https://pkg.go.dev/container/heap#example-package-PriorityQueue | ||
|
||
type Item struct { | ||
Repository | ||
order int | ||
index int | ||
} | ||
|
||
type PriorityQueue []*Item | ||
|
||
func (pq PriorityQueue) Len() int { return len(pq) } | ||
|
||
func (pq PriorityQueue) Less(i, j int) bool { | ||
// We want Pop to give us the lowest order number | ||
return pq[i].order < pq[j].order | ||
} | ||
|
||
func (pq PriorityQueue) Swap(i, j int) { | ||
pq[i], pq[j] = pq[j], pq[i] | ||
pq[i].index = i | ||
pq[j].index = j | ||
} | ||
|
||
func (pq *PriorityQueue) Push(x any) { | ||
n := len(*pq) | ||
item := x.(*Item) | ||
item.index = n | ||
*pq = append(*pq, item) | ||
} | ||
|
||
func (pq *PriorityQueue) Pop() any { | ||
old := *pq | ||
n := len(old) | ||
item := old[n-1] | ||
old[n-1] = nil // avoid memory leak | ||
item.index = -1 // for safety | ||
*pq = old[0 : n-1] | ||
return item | ||
} | ||
|
||
// update modifies the priority and value of an Item in the queue. | ||
func (pq *PriorityQueue) update(item *Item, value Repository, order int) { | ||
item.Repository = value | ||
item.order = order | ||
heap.Fix(pq, item.index) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
type Repository struct { | ||
URL string | ||
Username string | ||
Password string | ||
Branch string | ||
Path string | ||
} | ||
|
||
func FromMap(m map[string]string) Repository { | ||
return Repository{ | ||
URL: m["URL"], | ||
Username: m["USERNAME"], | ||
Password: m["PASSWORD"], | ||
Branch: m["BRANCH"], | ||
Path: m["PATH"], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.