From ff58a6100fb351883096902844091648632af600 Mon Sep 17 00:00:00 2001 From: David Given Date: Sun, 9 Oct 2016 22:03:44 +0200 Subject: [PATCH] Add pmap_remove(). --- modules/src/data/pmap.c | 18 ++++++++++++++++++ modules/src/data/pmap.h | 1 + 2 files changed, 19 insertions(+) diff --git a/modules/src/data/pmap.c b/modules/src/data/pmap.c index ae62af3c6..fffba7e90 100644 --- a/modules/src/data/pmap.c +++ b/modules/src/data/pmap.c @@ -1,5 +1,6 @@ #include #include +#include #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; icount; 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; diff --git a/modules/src/data/pmap.h b/modules/src/data/pmap.h index 8c06ec605..a7980a3a3 100644 --- a/modules/src/data/pmap.h +++ b/modules/src/data/pmap.h @@ -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);