From 4261744537e9d6bd356bf5d2b0e1f2882ed863de Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 8 Oct 2016 23:32:13 +0200 Subject: [PATCH] Replace pmap_get() with pmap_findleft() and pmap_findright(), to allow lookups in both directions. --- modules/src/data/pmap.c | 17 ++++++++++++++++- modules/src/data/pmap.h | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/src/data/pmap.c b/modules/src/data/pmap.c index 9ed2d9fed..ae62af3c6 100644 --- a/modules/src/data/pmap.c +++ b/modules/src/data/pmap.c @@ -56,7 +56,7 @@ void pmap_add(void* mapp, void* left, void* right) append(map, left, right); } -void* pmap_get(void* mapp, void* left) +void* pmap_findleft(void* mapp, void* left) { struct pmap* map = mapp; int i; @@ -71,4 +71,19 @@ void* pmap_get(void* mapp, void* left) return NULL; } +void* pmap_findright(void* mapp, void* right) +{ + struct pmap* map = mapp; + int i; + + for (i=0; icount; i++) + { + struct pmap_node* node = &map->item[i]; + if (node->right == right) + return node->left; + } + + return NULL; +} + diff --git a/modules/src/data/pmap.h b/modules/src/data/pmap.h index 19986fc12..8c06ec605 100644 --- a/modules/src/data/pmap.h +++ b/modules/src/data/pmap.h @@ -25,7 +25,8 @@ 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_get(void* map, void* left); +extern void* pmap_findleft(void* map, void* left); +extern void* pmap_findright(void* map, void* right); #endif