#ifndef __ELEMENTS_H__
#define __ELEMENTS_H__
#include "global.h"

typedef struct element_list_p {
    struct element_list_p *next;
    int key;
    int value;
} element_list_t;

typedef struct {
    element_list_t* head;//the list of elements
    element_list_t* tail;//end of the list
    int max_size;//the maxium size of the element list,
    //when this is reached the element with the lowest value is removed
    int list_size;
} element_list_head_t;


//init the list, with a max size, zero means no max
void init_elements(element_list_head_t* list, int max_size);

//returns the value associated with the key in the list
int get_element(element_list_head_t* list, int key, int default_value);

//frees the list and all resources associated with it
void destroy_elements(element_list_head_t* list);

//add an element to the list, returns its new value
int set_element(element_list_head_t* list, int key, int value);

//adds `change` to the value (assumed to be zero if not there)
int add_element(element_list_head_t* list, int key, int change);

//add change to the value, assumed to be zero if not there, and will limit the value to +/- max
int add_element_max(element_list_head_t* list, int key, int change, int max);

void copy_element_list(element_list_head_t* dst, element_list_head_t* src);

//adds some randomness to the process, things change
void fuzz_elements(element_list_head_t* list);
#endif
