Logo Search packages:      
Sourcecode: xcin version File versions  Download package

eval_hash.c

//#define DEBUG
#include "hash.h"
#include "global.h"
#include <stdio.h>
#include <string.h>

const int MAX_BUF_LEN = 512 ;
int count[HASH_TABLE_SIZE] ;

void Statistics()
{
  int mincount, maxcount, i ;

  maxcount = mincount = count[0] ;
  for(i=1; i<HASH_TABLE_SIZE; i++) {
    if(maxcount < count[i]) maxcount = count[i] ;
    if(mincount > count[i]) mincount = count[i] ;
    printf("%d\n", count[i]) ;
  }
  //  printf("\n") ;
  //printf("maxcount = %d , mincount = %d\n", maxcount, mincount) ;
}

static int HashFunc(uint16 phoneSeq[])
{
  int i, value=0, len ;

  for(len=0; phoneSeq[len]; len++) ;

  if(len > 4) {
    for(i=0; i<len; i+=2)
      value ^= phoneSeq[i] ;
  }
  else {
    for(i=0; i<len; i++)
      value ^= phoneSeq[i] ;
  }
  return value ;
}

int main()
{
  FILE *tsi_file ;
  char buf[MAX_BUF_LEN], *p1, *p2, *p ;
  uint16 phoneSeq[MAX_PHONE_SEQ_LEN] ;
  int len, i ;


  tsi_file = fopen("tsi.src", "r") ;
  while(fgets(buf, MAX_BUF_LEN, tsi_file) ) {
    p1 = strtok(buf," ") ;
    p2 = strtok(NULL," ") ;
    len = strlen(p1) / 2 ;
    for(i=0; i<len; i++) {
      p = strtok(NULL, " \n") ;
#ifdef DEBUG
      printf("%s, Len:%d ", p, strlen(p)) ;
#endif
      phoneSeq[i] = PhoneBg2Uint(p) ;
#ifdef DEBUG
      printf(",%hu\n", phoneSeq[i]) ;
#endif
    }
    phoneSeq[len] = 0 ;
    count[HashFunc(phoneSeq)]++ ;
  }
  fclose(tsi_file) ;

  Statistics() ;
  return 0 ;
}

Generated by  Doxygen 1.6.0   Back to index