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 a routine to merge two GNode n_ary trees together #92

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

gcampbell512
Copy link
Contributor

The input trees need to be highly overlapping. This function is used by netconf to merge two GNode trees which are generated from filling in a search tree with added default values and from the initial search query with added default values.

The _sch_traverse_nodes routine has been slightly modified to allow netconf to add defaults for an input tree that is a query.

schema.c Outdated
char *data = NULL;

if (src)
data = g_strdup (src);
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI - g_strdup works with NULL pointers too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK - I will change the code

schema.c Outdated
@@ -4096,6 +4107,55 @@ sch_traverse_tree (sch_instance * instance, sch_node * schema, GNode * node, int
return rc;
}

static void
Copy link
Contributor

Choose a reason for hiding this comment

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

I think comments would be helpful here - I am a bit puzzled that you are doing recursive descent and deep copying?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is happening is that tree2 is being merged into tree1. The deep copying instead on moving nodes between the trees means it is much cleaner to delete tree2 when the merge is complete. I will add a comment.

@carlgsmith
Copy link
Contributor

I was going to ask you to move the routine to apteryx.h .... oops
https://github.com/alliedtelesis/apteryx/blob/master/apteryx.h#L385

@gcampbell512
Copy link
Contributor Author

The routine _sch_merge_gnode_nodes is different from apteryx_merge_tree in that it handles trees with ../* elements. This often occurs in a query (tree) which is the second tree passed to this routine.

The _sch_traverse_nodes routine has been slightly modified to test for
an exact match at depth -1. This allows netconf to test for defaults
on an exact path when report-all is set.
@carlgsmith carlgsmith merged commit 6c9e39c into alliedtelesis:master Jan 31, 2024
1 check passed
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.

3 participants