Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit a5a732f

Browse files
author
Hendrik van Antwerpen
committed
Rename Index to ToAppendable and move to stitching module
1 parent 8b6da40 commit a5a732f

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

stack-graphs/src/cycles.rs

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::partial::PartialPath;
4343
use crate::partial::PartialPaths;
4444
use crate::paths::PathResolutionError;
4545
use crate::stitching::Appendable;
46-
use crate::stitching::Database;
46+
use crate::stitching::ToAppendable;
4747

4848
/// Helps detect similar paths in the path-finding algorithm.
4949
pub struct SimilarPathDetector<P> {
@@ -128,25 +128,6 @@ where
128128
// ----------------------------------------------------------------------------
129129
// Cycle detector
130130

131-
pub trait Index<H, A>
132-
where
133-
A: Appendable,
134-
{
135-
fn get<'a>(&'a self, handle: &'a H) -> &'a A;
136-
}
137-
138-
impl Index<Handle<PartialPath>, PartialPath> for Database {
139-
fn get<'a>(&'a self, handle: &'a Handle<PartialPath>) -> &'a PartialPath {
140-
&self[*handle]
141-
}
142-
}
143-
144-
impl<A: Appendable + Clone> Index<A, A> for () {
145-
fn get<'a>(&'a self, value: &'a A) -> &'a A {
146-
value
147-
}
148-
}
149-
150131
pub struct Appendables<H>(pub(crate) ListArena<PathOrAppendable<H>>);
151132

152133
impl<H> Appendables<H> {
@@ -174,33 +155,33 @@ where
174155
) -> Result<(), PathResolutionError>
175156
where
176157
A: Appendable + 'a,
177-
Db: Index<H, A>,
158+
Db: ToAppendable<H, A>,
178159
{
179160
match self {
180161
Self::Path(other) => other.append_to(graph, partials, path),
181-
Self::Handle(h) => db.get(h).append_to(graph, partials, path),
162+
Self::Handle(h) => db.get_appendable(h).append_to(graph, partials, path),
182163
}
183164
}
184165

185166
fn start_node<'a, A, Db>(&self, db: &'a Db) -> Handle<Node>
186167
where
187168
A: Appendable + 'a,
188-
Db: Index<H, A>,
169+
Db: ToAppendable<H, A>,
189170
{
190171
match self {
191172
Self::Path(path) => path.start_node,
192-
Self::Handle(h) => db.get(h).start_node(),
173+
Self::Handle(h) => db.get_appendable(h).start_node(),
193174
}
194175
}
195176

196177
fn end_node<'a, A, Db>(&self, db: &'a Db) -> Handle<Node>
197178
where
198179
A: Appendable + 'a,
199-
Db: Index<H, A>,
180+
Db: ToAppendable<H, A>,
200181
{
201182
match self {
202183
Self::Path(path) => path.end_node,
203-
Self::Handle(h) => db.get(h).end_node(),
184+
Self::Handle(h) => db.get_appendable(h).end_node(),
204185
}
205186
}
206187
}
@@ -246,7 +227,7 @@ where
246227
) -> Result<EnumSet<Cyclicity>, PathResolutionError>
247228
where
248229
A: Appendable + 'a,
249-
Db: Index<H, A>,
230+
Db: ToAppendable<H, A>,
250231
{
251232
let mut cycles = EnumSet::new();
252233

stack-graphs/src/stitching.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use std::collections::HashMap;
3939
use std::collections::VecDeque;
4040
#[cfg(feature = "copious-debugging")]
4141
use std::fmt::Display;
42-
use std::ops::Index;
4342

4443
use crate::arena::Arena;
4544
use crate::arena::Handle;
@@ -153,6 +152,28 @@ impl Appendable for PartialPath {
153152
}
154153
}
155154

155+
//-------------------------------------------------------------------------------------------------
156+
// ToAppendable
157+
158+
pub trait ToAppendable<H, A>
159+
where
160+
A: Appendable,
161+
{
162+
fn get_appendable<'a>(&'a self, handle: &'a H) -> &'a A;
163+
}
164+
165+
impl ToAppendable<Handle<PartialPath>, PartialPath> for Database {
166+
fn get_appendable<'a>(&'a self, handle: &'a Handle<PartialPath>) -> &'a PartialPath {
167+
&self[*handle]
168+
}
169+
}
170+
171+
impl<A: Appendable + Clone> ToAppendable<A, A> for () {
172+
fn get_appendable<'a>(&'a self, value: &'a A) -> &'a A {
173+
value
174+
}
175+
}
176+
156177
//-------------------------------------------------------------------------------------------------
157178
// Candidates
158179

@@ -440,7 +461,7 @@ impl Database {
440461
}
441462
}
442463

443-
impl Index<Handle<PartialPath>> for Database {
464+
impl std::ops::Index<Handle<PartialPath>> for Database {
444465
type Output = PartialPath;
445466
#[inline(always)]
446467
fn index(&self, handle: Handle<PartialPath>) -> &PartialPath {
@@ -734,7 +755,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
734755
) -> usize
735756
where
736757
A: Appendable + 'a,
737-
Db: Candidates<H> + crate::cycles::Index<H, A>,
758+
Db: Candidates<H> + ToAppendable<H, A>,
738759
{
739760
self.candidates.clear();
740761
db.find_candidates(graph, partials, partial_path, &mut self.candidates);
@@ -743,7 +764,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
743764
self.next_iteration.0.reserve(extension_count);
744765
self.next_iteration.1.reserve(extension_count);
745766
for extension in &self.candidates {
746-
let extension_path = db.get(extension);
767+
let extension_path = db.get_appendable(extension);
747768
copious_debugging!(" Extend {}", partial_path.display(graph, partials));
748769
copious_debugging!(" with {}", extension_path.display(graph, partials));
749770

@@ -809,7 +830,7 @@ impl<H: Clone> ForwardPartialPathStitcher<H> {
809830
db: &mut Db,
810831
) where
811832
A: Appendable + 'a,
812-
Db: Candidates<H> + crate::cycles::Index<H, A>,
833+
Db: Candidates<H> + ToAppendable<H, A>,
813834
{
814835
copious_debugging!("==> Start phase {}", self.phase_number);
815836
self.queue.extend(

0 commit comments

Comments
 (0)