/*
   File:        ihash.h
   Author(s):   Andrew Moore
   Created:     Tue Dec 10 18:02:17 EST 2002
   Description: Mapping ivecs to doubles
   Copyright (c) Carnegie Mellon University
*/

#ifndef ihash_H
#define ihash_H

#include "hash.h"
#include "amdmex.h"

/* A hash table that maps ivecs to doubles. The hash table consists
   of a set of

    (ivec,value)

   pairs

   and you can (in constant time) find out whether any given ivec is in
   the hash table, and if so, what value it's accociated with */
typedef struct ihash
{
  hash_table *h;
  ivec_array *elnum_to_ivec;
  dyv *elnum_to_value;
} ihash;

ihash *mk_empty_ihash(void);

void free_ihash(ihash *x);

int ihash_num_bytes(ihash *ih);

int ihash_size(ihash *ih);

/* elnum can be used to iterate over all pairs stored in the
   hash table. To do that, just do

    for ( elnum = 0 ; elnum < ihash_size(ih) ; elnum++ )
    {
      ivec *iv = ihash_elnum_to_ivec(ih,elnum);
      double value = ihash_elnum_to_value(ih,elnum);

           ....

    }
*/
ivec *ihash_elnum_to_ivec(ihash *ih,int elnum);

double ihash_elnum_to_value(ihash *ih,int elnum);

void fprintf_ihash(FILE *s,char *m1,ihash *x,char *m2);

void pihash(ihash *x);

ihash *mk_copy_ihash(ihash *old);

void add_to_ihash(ihash *ih,ivec *iv,double value);

double ihash_lookup(ihash *ih,ivec *iv,bool *r_exists);

#endif /* ifndef ihash_H */
