Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement generic index types #19

Merged
merged 7 commits into from
Dec 18, 2022
Merged

Implement generic index types #19

merged 7 commits into from
Dec 18, 2022

Conversation

pnevyk
Copy link
Owner

@pnevyk pnevyk commented Oct 9, 2022

This is a version of generic index types that compiles, but it has still many rough edges. A few examples:

  • CustomIndexing trick in traits.rs, which is needed for impl ... for &G, because using just Self causes an (understandable) compilation error. If there is no other way, it should at least get a better name (DelegateIndexing?) and be private?
  • In many cases there is a "VertexRef::data type annotations needed" (VertexRef::data is just one example) error. This is very unergonomic and a solution must be found. This arises from the fact that plain tuples do not hold information about Ix: Indexing.
  • During the implementation, clones were deliberately added anywhere where needed to make code compile. They should be reviewed if some of them can be removed by changing an API (e.g., take something by reference) Checked all new clones and I didn't find any good opportunity to avoid a clone (it is either so cheap that it is not worthy to complicate the API or is in testing code).
  • UseIndex trait in visit::raw is quite an overkill. Maybe it's a necessary implementation detail (we need Ix: Indexing to avoid "Ix is not constrained by trait, Self type, ..." error), but it should not be visible outside of visit::raw.
  • Conversions from/to usize for NumIndexType are cumbersome right now as explicit NumIndexType::from_usize must be used instead of simple .into(). This should be improved as well.
  • Use Borrow trait for index arguments, so that both owned indexes and references to indexes can be used in API such as vertex(...) and add_edge(...). This will help ergonomics and aesthetics on the user side in majority of cases, when default index types are used as they are Copy.
  • Make IndexType: Debug

Following commits should resolve mentioned problems and polish the code in general.

This is a version of generic index types that compiles, but it has still
many rough edges. A few examples:

- `CustomIndexing` trick in traits.rs, which is needed for `impl ... for
  &G`, because using just `Self` causes an (understandable) compilation
  error. If there is no other way, it should at least get a better name
  (`DelegateIndexing`?) and be private?
- In many cases there is a "VertexRef::data type annotations needed"
  (`VertexRef::data` is just one example) error. This is very
  unergonomic and a solution must be found. This arises from the fact
  that plain tuples do not hold information about `Ix: Indexing`.
- During the implementation, clones were deliberately added anywhere
  where needed to make code compile. They should be reviewed if some of
  them can be removed by changing an API (e.g., take something by
  reference)
- `UseIndex` trait in `visit::raw` is quite an overkill. Maybe it's a
  necessary implementation detail (we need `Ix: Indexing` to avoid "Ix
  is not constrained by trait, Self type, ..." error), but it should not
  be visible outside of `visit::raw`.
- Conversions from/to usize for `NumIndexType` are cumbersome right now
  as explicit `NumIndexType::from_usize` must be used instead of simple
  `.into()`. This should be improved as well.

Following commits should resolve mentioned problems and polish the code
in general.
@pnevyk
Copy link
Owner Author

pnevyk commented Oct 9, 2022

Implements #17

This is just to be able to make a comment in the future about why this
workaround is needed (or make it easier to find all occurrences if a
better way is found).
This allows use of owned indices with high-level API for graphs from
`graph` module, if the index types are Copy, which they will be in the
vast maority of cases. Using owned indices is kind of a convention in
Rust's graph ecosystem.

This technique is not employed in the base traits as that would
complicate the overall interface and result in more code bloat during
monomorphization.
@pnevyk pnevyk merged commit baebf7b into main Dec 18, 2022
@pnevyk pnevyk deleted the generic-index-types branch December 19, 2022 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant