diff options
author | Kevin Newton <[email protected]> | 2024-02-23 10:36:59 -0500 |
---|---|---|
committer | Kevin Newton <[email protected]> | 2024-02-23 13:25:31 -0500 |
commit | d1ce989829927a4215952983babadfd1df1b505f (patch) | |
tree | 83020fb1034046d58493328a235e5d77e8aa9e4a /prism/util/pm_integer.c | |
parent | 73dd3ce03e3a0a58a157607385418d7a3724752c (diff) |
[ruby/prism] Duplicated hash keys
https://github.com/ruby/prism/commit/3e10c46c14
Diffstat (limited to 'prism/util/pm_integer.c')
-rw-r--r-- | prism/util/pm_integer.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/prism/util/pm_integer.c b/prism/util/pm_integer.c index f08078356a..720dd60872 100644 --- a/prism/util/pm_integer.c +++ b/prism/util/pm_integer.c @@ -153,6 +153,29 @@ pm_integer_memsize(const pm_integer_t *integer) { } /** + * Compare two integers. This function returns -1 if the left integer is less + * than the right integer, 0 if they are equal, and 1 if the left integer is + * greater than the right integer. + */ +int +pm_integer_compare(const pm_integer_t *left, const pm_integer_t *right) { + if (left->length < right->length) return -1; + if (left->length > right->length) return 1; + + for ( + const pm_integer_word_t *left_word = &left->head, *right_word = &right->head; + left_word != NULL && right_word != NULL; + left_word = left_word->next, right_word = right_word->next + ) { + if (left_word->value < right_word->value) return -1; + if (left_word->value > right_word->value) return 1; + } + + return 0; + +} + +/** * Recursively destroy the linked list of an integer. */ static void |