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 unique_list function #185
Conversation
Can one of the admins verify this patch? |
pan/functions.pan
Outdated
to_dict[escape(itemid)] = 1; | ||
}; | ||
}; | ||
return(to_list); |
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.
remove the return, it makes an extra copy, (to_list;
is enough)
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.
Did not know that, will update.
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.
Fixed :)
pan/functions.pan
Outdated
@@ -218,3 +218,19 @@ function full_hostname_from_object = { | |||
return (OBJECT); | |||
}; | |||
|
|||
|
|||
@documentation{ | |||
desc = Function to deduplicate the content of a list, only the first occurence of each element in the list will be kept in the final list returned to the caller |
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.
line too long?
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.
Same as for the other one. How do line break works for the desc
field in @documentation
?
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.
Fixed :)
pan/functions.pan
Outdated
@documentation{ | ||
desc = Function to deduplicate the content of a list, only the first occurence of each element in the list will be kept in the final list returned to the caller | ||
} | ||
function unique_list = { |
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.
how often is this used? or how performance sensitive is this? the code below does a lot of copying and casting; if needed we can add this to panc (eg via supporting sets if you don't need the ordering)
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 aim is to deduplicate a list of strings / long when generating the profile of a host, to manage a new entitlement structure (to be submitted later). The ordering is not important for us, so if this can be done a better & faster way, I'm all for it!
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 are up to it and if it is worth it, following doc sand example PR can show you what is needed: https://www.quattor.org/development/panc-internals-overview.html#adding-functionality (and example quattor/pan#118).
but just to be clear, i have no issue with getting this merged 😉
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.
Not sure it will be worth the trouble... Maybe if this starts getting used heavily and becomes the bottleneck, but not sure this will! It's true that in Java it would just be a matter of doing a collection copy from the list to a set, and returning it as a list.
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.
Plus you would have to wait for a new panc release before you could use it, which would slow things down.
The unique_list function takes a list as parameter, and returns a list without any duplicated elements. The order of the elements is maintained (i.e. if the first occurrence of an element appears in the list before the first occurrence of another, the former will precede the latter in the final list).
@hpcugentbot test this please |
Seems that the commit failure comes from something else than my patch, looking at the test logs... |
@hpcugentbot please test this please |
The unique_list function takes a list as parameter, and returns
a list without any duplicated elements. The order of the elements
is maintained (i.e. if the first occurrence of an element appears in
the list before the first occurrence of another, the former will
precede the latter in the final list).