Skip to content

IP comparison functions#15

Open
greatflyingsteve wants to merge 9 commits intoinkblot:masterfrom
greatflyingsteve:ip-comparison
Open

IP comparison functions#15
greatflyingsteve wants to merge 9 commits intoinkblot:masterfrom
greatflyingsteve:ip-comparison

Conversation

@greatflyingsteve
Copy link

This is based on the work already submitted in #14, and includes another update to the PDK templates (although unfortunately not very much of one, this time). This adds some usefull functions for comparing and equality-testing IP addresses, both with equivalent functions for traditional boolean-return comparisons (>, >=, ==, <=, and <), and for use with functions like Puppet's sort(), which execute a block and expect one of -1, 0, or 1 as return to indicate whether the left operand is smaller than, equal to, or greater than the right, and will perform arbitrarily elaborate sorts accordingly.

My specific need for this was the sort() case to put a list of IP addresses in sorted order to (hopefully) match the output of a certain popularly-unpopular network management tool, and the others were just simple enough at that point that there wasn't a good reason NOT to include them (or at least, that's what I thought until I started writing docs for all of them, heh).

greatflyingsteve and others added 8 commits January 24, 2022 17:48
Initial commit of implementation and tests for ip_compare(), designed
for use with Puppet's `sort()` to sort a series of IP addresses into
binary-numerical order, regardless of the human-readable representation
in which they were originally written.
Initial commit of greater_than, equal_or_greater_than, equal_to,
equal_or_less_than, and less_than comparator functions and their unit
tests.
Important realization that made me feel kinda dumb: if you want to
handle the case of comparing with-prefix form to no-prefix form, you
can't just key your normalization pass off of both values being one or
the other.  Normalize each value individually, which solves the problem
correctly.
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.

1 participant