@@ -5,9 +5,7 @@ use std::{
5
5
hash:: Hash ,
6
6
} ;
7
7
8
- use crate :: completeness:: {
9
- Completeness , CriticalEdgeBasedCompleteness , ExplicitClose , UncheckedCompleteness ,
10
- } ;
8
+ use crate :: completeness:: { Completeness , UncheckedCompleteness } ;
11
9
12
10
/// Representation of scopes (nodes in the scope graph).
13
11
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
@@ -37,7 +35,7 @@ impl<LABEL, DATA> InnerScopeGraph<LABEL, DATA> {
37
35
38
36
/// Adds a new scope to the graph, with `data` as its associated data.
39
37
/// After this operation, all future calls to [`InnerScopeGraph::get_data`] on this scope will return the associated data.
40
- fn add_scope ( & mut self , data : DATA ) -> Scope {
38
+ pub ( super ) fn add_scope ( & mut self , data : DATA ) -> Scope {
41
39
let id = self . data . len ( ) ;
42
40
self . data . push ( data) ;
43
41
self . edges . push ( HashMap :: with_capacity ( 0 ) ) ;
@@ -91,8 +89,8 @@ impl<'a, LABEL: Hash + Eq, DATA> InnerScopeGraph<LABEL, DATA> {
91
89
/// In addition, there is no data type for edges, as edges should only be traversed, but never leak outside the scope graph structure.
92
90
/// Finally, although not made explicit, [`LABEL`] should be a finite, iterable set.
93
91
pub struct ScopeGraph < LABEL , DATA , CMPL > {
94
- inner_scope_graph : InnerScopeGraph < LABEL , DATA > ,
95
- completeness : RefCell < CMPL > ,
92
+ pub ( super ) inner_scope_graph : InnerScopeGraph < LABEL , DATA > ,
93
+ pub ( super ) completeness : RefCell < CMPL > ,
96
94
}
97
95
98
96
impl < LABEL , DATA , CMPL > ScopeGraph < LABEL , DATA , CMPL > {
@@ -181,130 +179,3 @@ where
181
179
self . add_scope ( DATA :: default ( ) )
182
180
}
183
181
}
184
-
185
- impl < LABEL : Hash + Eq , DATA , CMPL > ScopeGraph < LABEL , DATA , CMPL >
186
- where
187
- CMPL : CriticalEdgeBasedCompleteness < LABEL , DATA > ,
188
- {
189
- /// Adds a new scope with some open edges.
190
- pub fn add_scope_with < I > ( & mut self , data : DATA , open_edges : I ) -> Scope
191
- where
192
- I : IntoIterator < Item = LABEL > ,
193
- {
194
- let scope = self . inner_scope_graph . add_scope ( data) ;
195
- self . completeness
196
- . borrow_mut ( )
197
- . init_scope_with ( HashSet :: from_iter ( open_edges. into_iter ( ) ) ) ;
198
- scope
199
- }
200
-
201
- /// Adds a new scope with no open edges.
202
- pub fn add_scope_closed ( & mut self , data : DATA ) -> Scope {
203
- let scope = self . inner_scope_graph . add_scope ( data) ;
204
- self . completeness
205
- . borrow_mut ( )
206
- . init_scope_with ( HashSet :: new ( ) ) ;
207
- scope
208
- }
209
- }
210
-
211
- impl < LABEL : Hash + Eq , DATA , CMPL > ScopeGraph < LABEL , DATA , CMPL >
212
- where
213
- DATA : Default ,
214
- CMPL : CriticalEdgeBasedCompleteness < LABEL , DATA > ,
215
- {
216
- /// Adds a new scope with some open edges and default data.
217
- pub fn add_scope_default_with < I > ( & mut self , open_edges : I ) -> Scope
218
- where
219
- I : IntoIterator < Item = LABEL > ,
220
- {
221
- self . add_scope_with ( DATA :: default ( ) , open_edges)
222
- }
223
-
224
- /// Adds a new scope with no open edges and default data.
225
- pub fn add_scope_default_closed ( & mut self ) -> Scope {
226
- self . add_scope_with ( DATA :: default ( ) , HashSet :: new ( ) )
227
- }
228
- }
229
-
230
- impl < LABEL : Hash + Eq , DATA > ScopeGraph < LABEL , DATA , ExplicitClose < LABEL > > {
231
- /// Closes an edge, (i.e., prohibit future new
232
- ///
233
- /// For example, the following program will return an error.
234
- /// ```
235
- /// # use scopegraphs_lib::completeness::ExplicitClose;
236
- /// # use scopegraphs_lib::ScopeGraph;
237
- /// # use scopegraphs_macros::Label;
238
- /// # #[derive(Eq, Hash, PartialEq, Label)] enum Lbl { Def }
239
- /// # use Lbl::*;
240
- /// let mut sg = ScopeGraph::<Lbl, usize, _>::new(ExplicitClose::default());
241
- ///
242
- /// let s1 = sg.add_scope_with(0, [Def]);
243
- /// let s2 = sg.add_scope_closed(42);
244
- ///
245
- /// sg.close(s1, &Def);
246
- /// sg.add_edge(s1, Def, s2).expect_err("cannot add edge after closing edge");
247
- /// ```
248
- ///
249
- /// Closing is required to permit queries to traverse these edges:
250
- /// ```
251
- ///
252
- /// # use scopegraphs_lib::completeness::ExplicitClose;
253
- /// # use scopegraphs_lib::ScopeGraph;
254
- /// # use scopegraphs_lib::resolve::{DefaultDataEquiv, DefaultLabelOrder, EdgeOrData, Resolve};
255
- /// # use scopegraphs_macros::{compile_regex, Label};
256
- /// #
257
- /// # #[derive(Eq, Hash, PartialEq, Label, Debug, Copy, Clone)]
258
- /// # enum Lbl { Def }
259
- /// # use Lbl::*;
260
- /// # type LblD = EdgeOrData<Lbl>;
261
- /// #
262
- /// # compile_regex!(type Regex<Lbl> = Def);
263
- /// let mut sg = ScopeGraph::<Lbl, usize, _>::new(ExplicitClose::default());
264
- ///
265
- /// let s1 = sg.add_scope_with(0, [Def]);
266
- /// let s2 = sg.add_scope_closed(42);
267
- ///
268
- /// // Note: not calling `sg.close(s1, &Def)`
269
- ///
270
- /// let query_result = sg.query()
271
- /// .with_path_wellformedness(Regex::new()) // regex: `Def`
272
- /// .with_data_wellformedness(|x: &usize| *x == 42) // match `42`
273
- /// .resolve(s1);
274
- ///
275
- /// query_result.expect_err("require s1/Def to be closed");
276
- /// ```
277
- ///
278
- /// Closing allows queries to resolve:
279
- /// ```
280
- ///
281
- /// # use scopegraphs_lib::completeness::ExplicitClose;
282
- /// # use scopegraphs_lib::ScopeGraph;
283
- /// # use scopegraphs_lib::resolve::{DefaultDataEquiv, DefaultLabelOrder, EdgeOrData, Resolve};
284
- /// # use scopegraphs_macros::{compile_regex, Label};
285
- /// #
286
- /// # #[derive(Eq, Hash, PartialEq, Label, Debug, Copy, Clone)]
287
- /// # enum Lbl { Def }
288
- /// # use Lbl::*;
289
- /// # type LblD = EdgeOrData<Lbl>;
290
- /// #
291
- /// # compile_regex!(type Regex<Lbl> = Def);
292
- /// let mut sg = ScopeGraph::<Lbl, usize, _>::new(ExplicitClose::default());
293
- ///
294
- /// let s1 = sg.add_scope_with(0, [Def]);
295
- /// let s2 = sg.add_scope_closed(42);
296
- ///
297
- /// // Note: closing the edge *after* creating all edges, *before* doing the query
298
- /// sg.close(s1, &Def);
299
- ///
300
- /// let query_result = sg.query()
301
- /// .with_path_wellformedness(Regex::new()) // regex: `Def`
302
- /// .with_data_wellformedness(|x: &usize| *x == 42) // match `42`
303
- /// .resolve(s1);
304
- ///
305
- /// query_result.expect("query should return result");
306
- /// ```
307
- pub fn close ( & self , scope : Scope , label : & LABEL ) {
308
- self . completeness . borrow_mut ( ) . close ( scope, label)
309
- }
310
- }
0 commit comments