From 52651c5f2c777b90371ac644bb0f59c9cd3884d4 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Thu, 11 Aug 2022 11:38:27 +0100 Subject: [PATCH] Tweaked dictionary hashing to not hash null keys --- source/literal.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/source/literal.c b/source/literal.c index 46b3222..595b7cf 100644 --- a/source/literal.c +++ b/source/literal.c @@ -222,6 +222,8 @@ bool literalsAreEqual(Literal lhs, Literal rhs) { } return !strncmp(AS_STRING(lhs), AS_STRING(rhs), STRLEN(lhs)); + //TODO: literal array and literal dictionary equality checks + case LITERAL_IDENTIFIER: if (STRLEN_I(lhs) != STRLEN_I(rhs)) { return false; @@ -230,7 +232,7 @@ bool literalsAreEqual(Literal lhs, Literal rhs) { default: //should never bee seen - fprintf(stderr, "[internal] Unrecognized literal type: %d\n", lhs.type); + fprintf(stderr, "[Internal] Unrecognized literal type in equality: %d\n", lhs.type); return false; } } @@ -282,8 +284,10 @@ int hashLiteral(Literal lit) { case LITERAL_DICTIONARY: { unsigned int res = 0; for (int i = 0; i < AS_DICTIONARY(lit)->count; i++) { - res += hashLiteral(AS_DICTIONARY(lit)->entries[i].key); - res += hashLiteral(AS_DICTIONARY(lit)->entries[i].value); + if (!IS_NULL(AS_DICTIONARY(lit)->entries[i].key)) { //only hash non-null keys + res += hashLiteral(AS_DICTIONARY(lit)->entries[i].key); + res += hashLiteral(AS_DICTIONARY(lit)->entries[i].value); + } } return hash(res); }