AcePerl

 view release on metacpan or  search on metacpan

acelib/dict.c  view on Meta::CPAN

/*  File: dict.c
 *  Author: Richard Durbin (rd@sanger.ac.uk)
 *  Copyright (C) J Thierry-Mieg and R Durbin, 1995
 *-------------------------------------------------------------------
 * This file is part of the ACEDB genome database package, written by
 * 	Richard Durbin (MRC LMB, UK) rd@mrc-lmb.cam.ac.uk, and
 *	Jean Thierry-Mieg (CRBM du CNRS, France) mieg@kaa.cnrs-mop.fr
 *
 * Description: 
 * Exported functions:
 * HISTORY:
 * Last edited: Sep 16 23:43 1997 (rd)
 * Created: Tue Jan 17 17:33:44 1995 (rd)
 *-------------------------------------------------------------------
 */

/* $Id: dict.c,v 1.1 2002/11/14 20:00:06 lstein Exp $ */

#include "dict.h"

/************* standard utility from Jean *************/

static int hashString (char *cp, int n, BOOL isDiff)
{
  register int i ;
  register unsigned int j, x = 0 ;
  register int rotate = isDiff ? 21 : 13 ;
  register int leftover = 8*sizeof(int) - rotate ;

  while (*cp)
    x = freeupper (*cp++) ^ (( x >> leftover) | (x << rotate)) ; 

				/* compress down to n bits */
  for (j = x, i = n ; i < sizeof(int) ; i += n)
    j ^= (x >> i) ;
  j &= (1 << n) - 1 ;

  if (isDiff)			/* return odd number */
    j |= 1 ;

  return j ;
}

#ifdef DAZ
static int hashString (char *cp, int n, BOOL isDiff)
{
  register int x;
  register int mask = (1 << n) - 1 ;

  x = 0;
  if (isDiff)	
    { for (;*cp;*cp++) { x = ((x * 5) + *cp) & mask ; }
      x |= 1 ;                   /* return odd number */
    }
  else
    for (;*cp;*cp++) { x = ((x * 3) + *cp) & mask ; }

  return x ;
}
#endif

/******************************************************/

static void dictFinalise (void *x) ;

DICT *dictHandleCreate (int size, STORE_HANDLE handle)
{
  DICT *dict = (DICT*) halloc (sizeof (DICT), handle) ;

  blockSetFinalise (dict, dictFinalise) ;
  for (dict->dim = 6, dict->max = 64 ; 
       dict->max < size ; 



( run in 1.116 second using v1.01-cache-2.11-cpan-99c4e6809bf )