#ifndef BUCKETLIST_H
#define BUCKETLIST_H

struct s_bucketlistnode {
  int key;	/* integer key that inserted node into this list */
  int val;	/* value of integer */
  struct s_bucketlistnode * next;
  struct s_bucketlistnode * last;
};
typedef struct s_bucketlistnode bucketlistnode;

struct s_bucketlist {
  bucketlistnode * head;
  bucketlistnode * tail;
  int size;
};
typedef struct s_bucketlist bucketlist;

struct s_bucketlistreturnval {
  int success; /* 1 if successful, 0 if not */
  int key;     /* key of node */
  int val;     /* node value */
};
typedef struct s_bucketlistreturnval bucketlistreturnval;

/* initialize the list */
void bl_init(bucketlist* list);

/* put a value at the back of the list
 * return 0 for failure, !0 for success
 * 1 = key is a new key
 * 2 = key already existed, older val replaced
 */
int bl_pushBack(bucketlist* list, int key, int val);

/* return a status and node value given a lookup index into list 
 * assume lists are ordered array-style (0 is index of first element)
 * (if big problems, return NULL)
 */
bucketlistreturnval* bl_getNodeAt(bucketlist list, int index);
bucketlistreturnval* bl_findNodeWithKey(bucketlist list, int key);

/* return 1 if deleted, 0 if unable to delete
 * assume lists are ordered array-style (0 is index of first element)
 */
int bl_deleteNodeAt(bucketlist* list, int index);
int bl_deleteNodeWithKey(bucketlist* list, int key);

#endif
