Add pmap_remove().

This commit is contained in:
David Given 2016-10-09 22:03:44 +02:00
parent 23c3575f0f
commit ff58a6100f
2 changed files with 19 additions and 0 deletions

View file

@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "pmap.h"
static void append(void* mapp, void* left, void* right)
@ -56,6 +57,23 @@ void pmap_add(void* mapp, void* left, void* right)
append(map, left, right);
}
void pmap_remove(void* mapp, void* left, void* right)
{
struct pmap* map = mapp;
int i;
for (i=0; i<map->count; i++)
{
struct pmap_node* node = &map->item[i];
if ((node->left == left) && (node->right == right))
{
memmove(node, node+1, sizeof(*node) * (map->count - i - 1));
map->count--;
return;
}
}
}
void* pmap_findleft(void* mapp, void* left)
{
struct pmap* map = mapp;

View file

@ -25,6 +25,7 @@ struct pmap
extern void pmap_put(void* map, void* left, void* right);
extern void pmap_add(void* map, void* left, void* right);
extern void pmap_remove(void* map, void* left, void* right);
extern void* pmap_findleft(void* map, void* left);
extern void* pmap_findright(void* map, void* right);