-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fixing missing case for handling root node for splitting #3983
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -413,7 +413,7 @@ func (n *Node) HSplit(bottom bool) uint64 { | |
| if !n.IsLeaf() { | ||
| return 0 | ||
| } | ||
| if n.Kind == STUndef { | ||
| if n.parent == nil { | ||
| n.Kind = STVert | ||
| } | ||
| if n.Kind == STVert { | ||
|
|
@@ -429,13 +429,13 @@ func (n *Node) VSplit(right bool) uint64 { | |
| if !n.IsLeaf() { | ||
| return 0 | ||
| } | ||
| if n.Kind == STUndef { | ||
| if n.parent == nil { | ||
| n.Kind = STHoriz | ||
| } | ||
| if n.Kind == STVert { | ||
| return n.vVSplit(right) | ||
| if n.Kind == STHoriz { | ||
| return n.hVSplit(0, right) | ||
| } | ||
| return n.hVSplit(0, right) | ||
| return n.vVSplit(right) | ||
| } | ||
|
|
||
| // unsplits the child of a split | ||
|
|
@@ -483,7 +483,17 @@ func (n *Node) Unsplit() bool { | |
| // flattens the tree by removing unnecessary intermediate parents that have only one child | ||
| // and handles the side effect of it | ||
| func (n *Node) flatten() { | ||
| if n.parent == nil || len(n.children) != 1 { | ||
| if len(n.children) != 1 { | ||
| return | ||
| } | ||
|
|
||
| // Special case for root node | ||
| if n.parent == nil { | ||
| *n = *n.children[0] | ||
| n.parent = nil | ||
|
Comment on lines
+492
to
+493
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes...right. We overwrite the root node with the last remaining children, by which it receives the Am I right that we should keep the fault in tab.go#L382 to identify that something went wrong, because
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
True. Forgot about that change when I made this change. Will add it back if we want to leave
Not sure what fault you are referring to.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But it can splits.go#L140 and this is intended, when the given ID isn't present at the related nodes.
I vote for keeping it too.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I am missing something but the given id should always be present for the node unless something is wrong no?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I vote for removing it :) since it's sole purpose is to identify root node and that can be done by just checking if parent exists or not. Just need @dmaluka 's vote or anyone else interested.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I vote for keeping it, so that we don't need to meaninglessly pass
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay got it. Added back the |
||
| for _, c := range n.children { | ||
| c.parent = n | ||
| } | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -531,11 +541,17 @@ func (n *Node) flatten() { | |
| func (n *Node) String() string { | ||
| var strf func(n *Node, ident int) string | ||
| strf = func(n *Node, ident int) string { | ||
| marker := "|" | ||
| marker := "/" | ||
| if n.Kind == STHoriz { | ||
| marker = "-" | ||
| } else if n.Kind == STVert { | ||
| marker = "|" | ||
| } | ||
| var parentId uint64 = 0 | ||
| if n.parent != nil { | ||
| parentId = n.parent.id | ||
| } | ||
| str := fmt.Sprint(strings.Repeat("\t", ident), marker, n.View, n.id) | ||
| str := fmt.Sprint(strings.Repeat("\t", ident), marker, n.View, n.id, parentId) | ||
| if n.IsLeaf() { | ||
| str += "🍁" | ||
| } | ||
|
|
||
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.
The next commit seems to make this change unneeded? I mean, if we guarantee that the root is always
STUndef, why not use it? Otherwise, if we don't useSTUndef, why do we even need it?And IMHO using
STUndefmakes the code a bit more readable.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.
Minor thing but I would think
n.parent == nilis more straightforward no? Since that is the definition of root node.A child node can be of type
STUndef(Although it is a bug), but a child node definite cannot have a node parent ofnilright?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.
Then, again, why need this
STUndefconstant at all?Although, after more thought, - ok, let's keep it (even though it is causing a bit of redundancy), just to let it reflect that it is indeed undefined whether it is horizontal or vertical.
Uh oh!
There was an error while loading. Please reload this page.
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.
Nah, we don't need it. Didn't do it cuz I only did minimal change just to fix the issue.
It doesn't matter if it is horizontal or not if it gets changed anyway. If we agree to remove it, I can do it :)