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
|
# frozen_string_literal: false
module Gem::Resolver::Molinillo
# A state that a {Resolution} can be in
# @attr [String] name
# @attr [Array<Object>] requirements
# @attr [DependencyGraph] activated
# @attr [Object] requirement
# @attr [Object] possibility
# @attr [Integer] depth
# @attr [Set<Object>] conflicts
ResolutionState = Struct.new(
:name,
:requirements,
:activated,
:requirement,
:possibilities,
:depth,
:conflicts
)
class ResolutionState
# Returns an empty resolution state
# @return [ResolutionState] an empty state
def self.empty
new(nil, [], DependencyGraph.new, nil, nil, 0, Set.new)
end
end
# A state that encapsulates a set of {#requirements} with an {Array} of
# possibilities
class DependencyState < ResolutionState
# Removes a possibility from `self`
# @return [PossibilityState] a state with a single possibility,
# the possibility that was removed from `self`
def pop_possibility_state
PossibilityState.new(
name,
requirements.dup,
activated.dup,
requirement,
[possibilities.pop],
depth + 1,
conflicts.dup
)
end
end
# A state that encapsulates a single possibility to fulfill the given
# {#requirement}
class PossibilityState < ResolutionState
end
end
|