typedef int element;
/* Print Elements */
void print_element (element *x,char *ignored)
{ printf("%d\n",*x); }
void print_collection (collection c)
{ MAP(c,print_element,NULL); }
/* Count Elements */
void increment_counter (element *x,char *n)
{ * ((int *) n) += 1; }
int size (collection c)
{ int n = 0; MAP(c,increment_counter,&n); return n; }
/* Double Each Element */
void double (element *x,char *ignored)
{ *x += *x; }
void double_everything (collection c)
{ MAP(c,double,NULL); }
/* Count Occurrences Of A Value */
typedef struct { element v; int n; } occurrence_data;
void increment_if_equal (element *x,char *data)
{ occurrence_data * odata = (occurrence_data *) data;
if (*x == odata->v) odata->n++; }
int number_of_occurrences (collection c,element v)
{ occurrence_data data; data.v = v; data.n = 0;
MAP(c,increment_if_equal,(char *) &data);
return data->n; }