Skip to content

Commit

Permalink
Renamed Archive -> Resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Nov 21, 2023
1 parent 9f1049e commit 8711f89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,36 @@ func (set Releases[R, D]) SortDescent() {
})
}

// Archive contains all Releases set to consider for dependency resolution
type Archive[R Release[D], D Dependency] struct {
// Resolver is a container with references to all Releases to consider for
// dependency resolution
type Resolver[R Release[D], D Dependency] struct {
releases map[string]Releases[R, D]
}

// NewArchive creates a new archive
func NewArchive[R Release[D], D Dependency]() *Archive[R, D] {
return &Archive[R, D]{
// NewResolver creates a new archive
func NewResolver[R Release[D], D Dependency]() *Resolver[R, D] {
return &Resolver[R, D]{
releases: map[string]Releases[R, D]{},
}
}

// AddRelease adds a release to this archive
func (ar *Archive[R, D]) AddRelease(rel R) {
func (ar *Resolver[R, D]) AddRelease(rel R) {
relName := rel.GetName()
ar.releases[relName] = append(ar.releases[relName], rel)
}

// AddReleases adds all the releases to this archive
func (ar *Archive[R, D]) AddReleases(rels ...R) {
func (ar *Resolver[R, D]) AddReleases(rels ...R) {
for _, rel := range rels {
relName := rel.GetName()
ar.releases[relName] = append(ar.releases[relName], rel)
}
}

// Resolve will try to depp-resolve dependencies from the Release passed as
// arguent using a backtracking algorithm.
func (ar *Archive[R, D]) Resolve(release R) Releases[R, D] {
// arguent using a backtracking algorithm. This function is NOT thread-safe.
func (ar *Resolver[R, D]) Resolve(release R) Releases[R, D] {
// Initial empty state of the resolver
solution := map[string]R{}
depsToProcess := []D{}
Expand All @@ -96,7 +97,7 @@ func hashDependency[D Dependency](dep D) dependencyHash {
return dependencyHash(dep.GetName() + "/" + dep.GetConstraint().String())
}

func (ar *Archive[R, D]) resolve(solution map[string]R, depsToProcess []D, problematicDeps map[dependencyHash]int) Releases[R, D] {
func (ar *Resolver[R, D]) resolve(solution map[string]R, depsToProcess []D, problematicDeps map[dependencyHash]int) Releases[R, D] {
debug("deps to process: %s", depsToProcess)
if len(depsToProcess) == 0 {
debug("All dependencies have been resolved.")
Expand Down
2 changes: 1 addition & 1 deletion resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestResolver(t *testing.T) {
i160 := rel("I", "1.6.0", deps())
i170 := rel("I", "1.7.0", deps())
i180 := rel("I", "1.8.0", deps())
arch := NewArchive[*customRel, *customDep]()
arch := NewResolver[*customRel, *customDep]()
arch.AddReleases(
a100, a110, a111, a120, a121,
b131, b130, b121, b120, b111, b110, b100,
Expand Down

0 comments on commit 8711f89

Please sign in to comment.