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

Add "serde-1" support to GraphMap #341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

schulzch
Copy link

This PR propagates serde-1 to indexmap and implements a custom serializer for (N, N) tuples, i.e., edges ([Source, Target, Weight] array format). The custom serializer is required for serde_json to work (tuples are not allowed as object keys). Also tested using bincode.

@XVilka XVilka added this to the 0.5.2 milestone Apr 9, 2020
@bluss
Copy link
Member

bluss commented Apr 12, 2020

Don't you think we need to look at the whole picture and make this serialize in a format identical to or as similar as possible to, what Graph and StableGraph use?

@@ -75,6 +143,7 @@ impl<N> NodeTrait for N where N: Copy + Ord + Hash {}

// non-repr(usize) version of Direction
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde-1", derive(Serialize, Deserialize))]
enum CompactDirection {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enum is internal so it would be good to not expose it in serialization

deserialize = "N: serde::Deserialize<'de>, E: serde::Deserialize<'de>"
))
)]
pub struct GraphMap<N, E, Ty> where N: Eq + Hash {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation details - which fields are used, of graph map are internal, so it would be good to not expose them. Otherwise make clear in documentation, that serialization of GraphMap in particular, is not stable across semver incompatible versions of the library. Thanks. See other comments, a more deliberate serialization format - not derived - could be appropriate.

@schulzch
Copy link
Author

Don't you think we need to look at the whole picture and make this serialize in a format identical to or as similar as possible to, what Graph and StableGraph use?

You are right - I didn't care much about that up until now. Is there some documation or issue that discusses the format of those? Seems like yet another reason to have a graph trait across all types of containers.

OT: I do not like Graph/StableGraph as standard at all. Its a fake-good and misleading default choice due to non O(1) complexities---took me a week to replace all instances with GraphMap in my code. A LinearScan-, List-, or Slow- in its name would help ;).

@XVilka
Copy link
Member

XVilka commented Aug 10, 2020

@schulzch do you have any updates regarding the comments?

@schulzch
Copy link
Author

The project I'm using petgraph for is currently on hold (but not dead), and I haven't had time to work on a generalizable solution, yet.

@symphorien
Copy link
Contributor

Maybe serialize should be implemented on Visitable+Data or something like that.

@XVilka XVilka modified the milestones: 0.5.2, 0.6 Aug 26, 2020
@ABorgna ABorgna modified the milestones: 0.6, 0.6.1 Jul 4, 2021
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.

5 participants