Compare commits

..

No commits in common. "35de7aa57d6f02d53a3cb6b8583a20d31a1ea6da" and "4b272786a583029b022177c0e007e73a2b9698c8" have entirely different histories.

3 changed files with 6 additions and 14 deletions

4
amap.h
View File

@ -11,13 +11,13 @@ typedef enum AMAP_OP AMAP_OP;
* Operations:
*
* AMAP_SET Saves a mapping from key->ptr in map. ptr==NULL "tombstones" the mapping to return NULL. Returns null on error!
* AMAP_GET Gets the symbol at key (the ptr parameter is unused). Returns "ptr" if there is no data for the key.
* AMAP_GET Gets the symbol at key (the ptr parameter is unused). Returns NULL if there is no ptr for the key.
* AMAP_ERASE Erases the symbol table so it becomes empty again. Can never fail, returns NULL.
*
* @param amap_instance The instance we operate upon.
* @param op Defines which operation the caller wants.
* @param key The key (both for SET and GET). This pointer can get easily invalidated so you might need a copy or you do Trie, etc.
* @param ptr When adding a ptr (data) to the map / table, the key will point to this ptr. Also the nt-found ptr to return in case of GET.
* @param ptr When adding a ptr (data) to the map / table, the key will point to this ptr.
* @returns The ptr / data stored for the key, or NULL on tombstone or when not stored yet or op is SET and there was an error.
*/
typedef void* (*amap)(void *amap_instance, AMAP_OP op, const char *key, void *ptr);

View File

@ -1,16 +1,8 @@
#include <cstdio>
#include <cassert>
#include "amap.h"
#include "simap.h"
void test_basics(amap mapdo, void *map) {
assert(NULL == mapdo(map, AMAP_GET, "asdf", NULL));
}
int main() {
/* test simap */
simap_instance si = simap_create();
test_basics(simap, &si);
return 0;
}

View File

@ -219,13 +219,13 @@ static inline void *simap_force_add_internal(simap_instance *map, const char *ke
* Operations:
*
* AMAP_SET Saves a mapping from key->ptr in map. ptr==NULL "tombstones" the mapping to return NULL.
* AMAP_GET Gets the symbol at key (the ptr parameter is unused). Returns "ptr" if there is no data for the key.
* AMAP_GET Gets the symbol at key (the ptr parameter is unused). Returns NULL if there is no ptr for the key.
* AMAP_ERASE Erases the symbol table so it becomes empty again. Can never fail, returns NULL.
*
* @param amap_instance The instance we operate upon.
* @param op Defines which operation the caller wants.
* @param key The key (both for SET and GET). This pointer can get easily invalidated so you might need a copy or you do Trie, etc.
* @param ptr When adding a ptr (data) to the map / table, the key will point to this ptr and the "nt found" ptr to return in get...
* @param ptr When adding a ptr (data) to the map / table, the key will point to this ptr.
* @returns The ptr / data stored for the key, or NULL on tombstone or when not stored yet or op is SET and there was an error.
*/
static inline void* simap(void *amap_instance, AMAP_OP op, const char *key, void *ptr) {
@ -240,7 +240,7 @@ static inline void* simap(void *amap_instance, AMAP_OP op, const char *key, void
simap_ptr64 *found = simap_search_internal(map, key);
if(op == AMAP_GET) {
return found ? found->ptr : ptr;
return found->ptr;
} else {
assert(op == AMAP_SET);
@ -254,7 +254,7 @@ static inline void* simap(void *amap_instance, AMAP_OP op, const char *key, void
}
assert(false); /* should be unreachable */
return ptr;
return NULL;
}
#endif /* SIMAP_H */