#ifndef AMAP_H #define AMAP_H /** Operations possible on the abstract map (setting with NULL should lead to getting NULL (can tombstone it though) */ enum AMAP_OP { AMAP_SET = 0, AMAP_GET = 1, AMAP_ERASE = 2 }; typedef enum AMAP_OP AMAP_OP; /** * Function-abstraction for an abstract map data type. * * 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_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. * @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); #endif /* AMAP_H */