diff --git a/sweet_geometry.c b/sweet_geometry.c index afdfc35..efb461b 100644 --- a/sweet_geometry.c +++ b/sweet_geometry.c @@ -142,7 +142,13 @@ map_free (struct map * map) static struct item * map_get_item (struct map * map, unsigned int hash, unsigned int a, unsigned int b) { - struct item * item = map->items[hash % MAP_SIZE]; + unsigned int tmp; + struct item * item; + tmp = a; + a = tmp > b ? tmp : b; + b = tmp > b ? b : tmp; + + item = map->items[hash % MAP_SIZE]; while (item != NULL && item->a != a && item->b != b) { item = item->next; } return item; } @@ -158,8 +164,8 @@ map_add_item (struct map * map, unsigned int hash, unsigned int a, unsigned int item = malloc (sizeof (struct item)); if (item == NULL) { return -1; } - item->a = a; - item->b = b; + item->a = a > b ? a : b; + item->b = a < b ? a : b; item->next = next; item->id = id;