/*
   File:        occr_count.h
   Authors:     Kubica
   Created:     Mon April 7, 2003
   Description: Header for the a data structure that counts occurrences

   Copyright 2003, The Auton Lab
*/


#ifndef OCCR_COUNT_H
#define OCCR_COUNT_H

#include "hash.h"

typedef struct occr_count_item
{
  int item;
  int count;
} occr_count_item;


typedef struct occr_count
{
  hash_table *ht;
  int total_occurred;
  int num_items_occurred;

} occr_count;


typedef struct occr_count_callback
{
  ivec* items;
  ivec* counts;
  int curr;
} occr_count_callback;


/* -------- Memory (create/destroy) functions --------- */

occr_count_item* mk_occr_count_item(int item, int init_count);

occr_count_item* mk_zero_count_occr_count_item(int item);

occr_count_item* mk_copy_occr_count_item(occr_count_item* old);

void free_occr_count_item(occr_count_item* old);

occr_count* mk_empty_occr_count(void);

occr_count* mk_copy_occr_count(occr_count* old);

void* mk_copy_v_occr_count_item(void* v_old);

void free_occr_count(occr_count* oc);

void free_v_occr_count_item(void* old);


/* -------- Access Functions --------------------------- */

void occr_count_add_occurrence(occr_count* oc, int item);

void occr_count_add_occurrences(occr_count* oc, int item, int new_counts);

/* Add 1 to the count of each item in the ivec */
void occr_count_add_counts_for_ivec_items(occr_count* oc, ivec* items);

void occr_count_remove_occurrence(occr_count* oc, int item);

void occr_count_remove_occurrences(occr_count* oc, int item, int old_counts);

/* Remove 1 from the count of each item in the ivec */
void occr_count_remove_counts_for_ivec_items(occr_count* oc, ivec* items);


/* -------- Getter Functions --------------------------- */

/* The total number of occurrences */
int occr_count_total_occurred(occr_count* oc);

/* The number of unique items that have occurred */
int occr_count_total_items_occurred(occr_count* oc);

bool occr_count_occurred(occr_count* oc, int item);

int occr_count_times_occurred(occr_count* oc, int item);

ivec* mk_occr_count_items_occurred(occr_count* oc);

/* Returns a vector of length "number of unique items that have occurred"
   where item i is the number of times the time referenced in
   mk_occr_count_items_occurred has occurred
*/
ivec* mk_occr_count_items_num_times_occurred(occr_count* oc);



#endif 








