-
Notifications
You must be signed in to change notification settings - Fork 16
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
added pretty printing json, storing all chains, Chains type, module rename, go bump #28
added pretty printing json, storing all chains, Chains type, module rename, go bump #28
Conversation
Signed-off-by: RinkiyaKeDad <arshsharma461@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question which is not directly related to the PR but I think we should try to simplify the types there to make it more obvious for the readers if we absolutely don't need the performance of map there
cmd/cycles.go
Outdated
@@ -33,7 +33,7 @@ var cyclesCmd = &cobra.Command{ | |||
RunE: func(cmd *cobra.Command, args []string) error { | |||
depGraph, _, mainModule := getDepInfo() | |||
var cycleChains [][]string | |||
chains := make(map[int][]string) | |||
chains := make(map[int][][]string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am starting to feel like these types are becoming "too much". Can we introduce some structs at least for one level of the arrays?
Actually I am checking the code now, why are we even storing the chains in map and what is that map used for? Looks like we're only writing to it and never reading from it?
Line 51 in ae16034
chains[len(longestPath)] = longestPath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review @alenkacz!
Yeah, I totally forgot about using structs 😅 I'll update the PR replacing map[int][][]string
with a struct.
To answer your other question I think we will still need maps since once we have the length of the longest chain/s, maps make it easier to retrieve the actual chain/s like done here.
The way to do this without using maps would be to iterate the [][]string
and print each []string
which has a length equal to "the length of the longest chain/s". Maps felt a bit more convenient to me since now instead of printing a single longest chain we print all the longest chains.
If there is a better way of doing this please let me know 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you only need the longest one you can always have struct like:
type Chains struct {
chains []Chain
longestChainsLength int
longestChains []Chain
}
then we could have something like
type Chain struct {
length int
chain []string
}
Just a quick idea. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks perfect! Thanks for this. Will update the PR tomorrow :)
cmd/stats.go
Outdated
fmt.Println("Longest chain is: ") | ||
printChain(chains[maxDepth]) | ||
fmt.Println("Longest chain/s: ") | ||
for _, chain := range chains[maxDepth] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alenkacz here's the example where we read all the longest chains from the map.
Signed-off-by: RinkiyaKeDad <arshsharma461@gmail.com>
@alenkacz looks like you were right. We didn't at all need |
Signed-off-by: RinkiyaKeDad <arshsharma461@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alenkacz, RinkiyaKeDad The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: RinkiyaKeDad arshsharma461@gmail.com
Fixes #26, prerequisite for #24.
map[int][]string
but with this PR we will be storing all chains of a particular length in amap[int][][]string
. This is needed for create a graph that has all chains containing a specified dependency #24.Chain
type which is basically a[]string
.go.mod
file and import inmain.go
.