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 DetectCycles to detect cycles in compared structs #78

Closed
wants to merge 1 commit into from

Conversation

posener
Copy link

@posener posener commented Mar 17, 2018

The current comparison fails on stack overflow when given a cyclic struct
(such as a cyclic linked list for example).

This fix adds a new option: DecetctCycles, which finds cycles by adding information
to the path stack, when iterating over pointers.

When a cycle is checked (every time a pointer kind is compared) the path stack
is iterated to find cycles. The comparison of cycles is by they length.

Fixes: #74

The current comparison fails on stack overflow when given a cyclic struct
(such as a cyclic linked list for example).

This fix adds a new option: DecetctCycles, which finds cycles by adding information
to the path stack, when iterating over pointers.

When a cycle is checked (every time a pointer kind is compared) the path stack
is iterated to find cycles. The comparison of cycles is by they length.

Fixes: google#74
@posener
Copy link
Author

posener commented Mar 18, 2018

@dsnet , I can improve this fix.
Instead of saving xAddr, and yAddr in the path stack, I can add a map to the cycleDetector struct that will map the pointer address to the stack length. - then the algorithm becomes O(1) time complexity.

If I make this improve, we can make the cycle detection enabled by default, cause it won't increase the time complexity of the algorithm, and the space complexity will be in the same order it was before.

What do you say?

@posener
Copy link
Author

posener commented Mar 18, 2018

I think that #79 is a better solution, but I'm leaving this one open for your decision.

@dsnet
Copy link
Collaborator

dsnet commented Mar 21, 2018

I'll comment on #79.

@dsnet dsnet closed this Mar 21, 2018
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.

proposal: support cyclic data structures
2 participants