Bug in get_item.
This commit is contained in:
parent
582bc2d5e0
commit
d13e891219
@ -142,7 +142,13 @@ map_free (struct map * map)
|
|||||||
static struct item *
|
static struct item *
|
||||||
map_get_item (struct map * map, unsigned int hash, unsigned int a, unsigned int b)
|
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; }
|
while (item != NULL && item->a != a && item->b != b) { item = item->next; }
|
||||||
return item;
|
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));
|
item = malloc (sizeof (struct item));
|
||||||
if (item == NULL) { return -1; }
|
if (item == NULL) { return -1; }
|
||||||
|
|
||||||
item->a = a;
|
item->a = a > b ? a : b;
|
||||||
item->b = b;
|
item->b = a < b ? a : b;
|
||||||
item->next = next;
|
item->next = next;
|
||||||
item->id = id;
|
item->id = id;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user