// hashmap_private.h - private declarations for the simple hashmap

#ifndef __hashmap_private_h__
#define __hashmap_private_h__

//------------------------------------------------------------
// error handling stuff

void unrecoverableError(int error_type,void *special);
void hashmapInternalError(int error_type,void *special);

// Macros for error handling to make code at least
// a little easier to read

#define HANDLE_POSSIBLE_UNRECOVERABLE_PTR \
{ \
  if (unrecoverable_error_)\
  {\
     unrecoverable_error_handler_ = NULL; \
     unrecoverable_error_ = 0; \
     return(NULL); \
  }\
}

#define HANDLE_POSSIBLE_UNRECOVERABLE_VOID \
{ \
  if (unrecoverable_error_)\
  {\
     unrecoverable_error_handler_ = NULL;\
     unrecoverable_error_ = 0; \
     return;\
  }\
}

//------------------------------------------------------------
// struct that represents one entry of a hashmap and
// access functions for it
struct _HashmapEntry_
{
  void *key;
  void *value;
  void (*key_destructor)(void *key,
                         void (*err_handler)(int err_type,
                                             void *special));
  void (*value_destructor)(void *value,
                           void (*err_handler)(int err_type,
                                               void *special));

  HashmapEntry *next;
};

HashmapEntry *newHashmapEntry(
  void *key,
  void *value,
  void (*key_destructor)(void *key,
                         void (*err_handler)(int err_type,
                                             void *special)),
  void (*value_destructor)(void *value,
                           void (*err_handler)(int err_type,
                                               void *special)),
  void (*error_handler)(int error_type,void *special));

void deleteHashmapEntry(HashmapEntry *entry,
                        void (*error_handler)(int error_type,
                                              void *special));

void *getKeyFromHashmapEntry(HashmapEntry *entry,
                             void (*error_handler)(int error_type,
                                                   void *special));

void *getValueFromHashmapEntry(HashmapEntry *entry,
                               void (*error_handler)(int error_type,
                                                     void *special));

void *getNextFromHashmapEntry(HashmapEntry *entry,
                              void (*error_handler)(int error_type,
                                                    void *special));

void setNextInHashmapEntry(HashmapEntry *entry,
                           HashmapEntry *next,
                           void (*error_handler)(int error_type,
                                                 void *special));

#endif // __hashmap_private_h__

