@@ -26,10 +26,7 @@ pub struct Memory<P: Package, V: Version> {
26
26
#[ derive( Clone ) ]
27
27
enum PackageAssignments < V : Version > {
28
28
Decision ( ( V , Term < V > ) ) ,
29
- Derivations {
30
- intersected : Term < V > ,
31
- not_intersected_yet : Vec < Term < V > > ,
32
- } ,
29
+ Derivations ( Term < V > ) ,
33
30
}
34
31
35
32
impl < P : Package , V : Version > Memory < P , V > {
@@ -46,9 +43,9 @@ impl<P: Package, V: Version> Memory<P, V> {
46
43
}
47
44
48
45
/// Retrieve intersection of terms in memory related to package.
49
- pub fn term_intersection_for_package ( & mut self , package : & P ) -> Option < & Term < V > > {
46
+ pub fn term_intersection_for_package ( & self , package : & P ) -> Option < & Term < V > > {
50
47
self . assignments
51
- . get_mut ( package)
48
+ . get ( package)
52
49
. map ( |pa| pa. assignment_intersection ( ) )
53
50
}
54
51
@@ -93,18 +90,12 @@ impl<P: Package, V: Version> Memory<P, V> {
93
90
Entry :: Occupied ( mut o) => match o. get_mut ( ) {
94
91
// Check that add_derivation is never called in the wrong context.
95
92
PackageAssignments :: Decision ( _) => debug_assert ! ( false ) ,
96
- PackageAssignments :: Derivations {
97
- intersected : _,
98
- not_intersected_yet,
99
- } => {
100
- not_intersected_yet. push ( term) ;
93
+ PackageAssignments :: Derivations ( t) => {
94
+ * t = t. intersection ( & term) ;
101
95
}
102
96
} ,
103
97
Entry :: Vacant ( v) => {
104
- v. insert ( PackageAssignments :: Derivations {
105
- intersected : term,
106
- not_intersected_yet : Vec :: new ( ) ,
107
- } ) ;
98
+ v. insert ( PackageAssignments :: Derivations ( term) ) ;
108
99
}
109
100
}
110
101
}
@@ -115,9 +106,9 @@ impl<P: Package, V: Version> Memory<P, V> {
115
106
/// selected version (no "decision")
116
107
/// and if it contains at least one positive derivation term
117
108
/// in the partial solution.
118
- pub fn potential_packages ( & mut self ) -> impl Iterator < Item = ( & P , & Range < V > ) > {
109
+ pub fn potential_packages ( & self ) -> impl Iterator < Item = ( & P , & Range < V > ) > {
119
110
self . assignments
120
- . iter_mut ( )
111
+ . iter ( )
121
112
. filter_map ( |( p, pa) | pa. potential_package_filter ( p) )
122
113
}
123
114
@@ -131,13 +122,8 @@ impl<P: Package, V: Version> Memory<P, V> {
131
122
PackageAssignments :: Decision ( ( v, _) ) => {
132
123
solution. insert ( p. clone ( ) , v. clone ( ) ) ;
133
124
}
134
- PackageAssignments :: Derivations {
135
- intersected,
136
- not_intersected_yet,
137
- } => {
138
- if intersected. is_positive ( )
139
- || not_intersected_yet. iter ( ) . any ( |t| t. is_positive ( ) )
140
- {
125
+ PackageAssignments :: Derivations ( intersected) => {
126
+ if intersected. is_positive ( ) {
141
127
return None ;
142
128
}
143
129
}
@@ -149,20 +135,10 @@ impl<P: Package, V: Version> Memory<P, V> {
149
135
150
136
impl < V : Version > PackageAssignments < V > {
151
137
/// Returns intersection of all assignments (decision included).
152
- /// Mutates itself to store the intersection result.
153
- fn assignment_intersection ( & mut self ) -> & Term < V > {
138
+ fn assignment_intersection ( & self ) -> & Term < V > {
154
139
match self {
155
140
PackageAssignments :: Decision ( ( _, term) ) => term,
156
- PackageAssignments :: Derivations {
157
- intersected,
158
- not_intersected_yet,
159
- } => {
160
- for derivation in not_intersected_yet. iter ( ) {
161
- * intersected = intersected. intersection ( & derivation) ;
162
- }
163
- not_intersected_yet. clear ( ) ;
164
- intersected
165
- }
141
+ PackageAssignments :: Derivations ( term) => term,
166
142
}
167
143
}
168
144
@@ -171,17 +147,13 @@ impl<V: Version> PackageAssignments<V> {
171
147
/// and if it contains at least one positive derivation term
172
148
/// in the partial solution.
173
149
fn potential_package_filter < ' a , P : Package > (
174
- & ' a mut self ,
150
+ & ' a self ,
175
151
package : & ' a P ,
176
152
) -> Option < ( & ' a P , & ' a Range < V > ) > {
177
153
match self {
178
154
PackageAssignments :: Decision ( _) => None ,
179
- PackageAssignments :: Derivations {
180
- intersected,
181
- not_intersected_yet,
182
- } => {
183
- if intersected. is_positive ( ) || not_intersected_yet. iter ( ) . any ( |t| t. is_positive ( ) )
184
- {
155
+ PackageAssignments :: Derivations ( intersected) => {
156
+ if intersected. is_positive ( ) {
185
157
Some ( ( package, self . assignment_intersection ( ) . unwrap_positive ( ) ) )
186
158
} else {
187
159
None
0 commit comments