From 58fac53b7aab47b67c70cee8c7b16d820da12f8c Mon Sep 17 00:00:00 2001 From: Jonathan Schleifer Date: Thu, 3 May 2012 20:38:33 +0200 Subject: [PATCH] Implement equal, hash and copy for int. --- src/int.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/int.c b/src/int.c index 03a649e..179503b 100644 --- a/src/int.c +++ b/src/int.c @@ -42,6 +42,35 @@ ctor(void *ptr, va_list args) return true; } +static bool +equal(void *ptr1, void *ptr2) +{ + CFWObject *obj2 = ptr2; + CFWInt *int1, *int2; + + if (obj2->cls != cfw_int) + return false; + + int1 = ptr1; + int2 = ptr2; + + return (int1->value == int2->value); +} + +static uint32_t +hash(void *ptr) +{ + CFWInt *integer = ptr; + + return (uint32_t)integer->value; +} + +static void* +copy(void *ptr) +{ + return cfw_ref(ptr); +} + intmax_t cfw_int_value(CFWInt *integer) { @@ -51,6 +80,9 @@ cfw_int_value(CFWInt *integer) static CFWClass class = { .name = "CFWInt", .size = sizeof(CFWInt), - .ctor = ctor + .ctor = ctor, + .equal = equal, + .hash = hash, + .copy = copy }; CFWClass *cfw_int = &class;