Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hash_table.cpp File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hash_table.h"
Include dependency graph for hash_table.cpp:

Go to the source code of this file.

Macros

#define DEBUGF(x)   /*printf x;*/
 
#define copyKey(dest, src)   memcpy(dest,src,layout.keySize())
 
#define copyObj(dest, src)   memcpy(dest,src,layout.objectSize())
 
#define copyEntry(dest, src)   memcpy(dest,src,layout.entrySize())
 
#define e2i(entry)   (((entry)-table)/layout.entrySize())
 
#define CDECL   extern "C"
 

Functions

void CmiAbort (const char *msg)
 
CkHashCode CkHashFunction_default (const void *keyData, size_t keyLen)
 
CkHashCode CkHashFunction_string (const void *keyData, size_t keyLen)
 
int CkHashCompare_default (const void *key1, const void *key2, size_t keyLen)
 
int CkHashCompare_string (const void *key1, const void *key2, size_t keyLen)
 
static unsigned int primeLargerThan (unsigned int x)
 
CDECL CkHashtable_c CkCreateHashtable_int (int objBytes, int initSize)
 
CDECL CkHashtable_c CkCreateHashtable_string (int objBytes, int initSize)
 
CDECL void CkDeleteHashtable (CkHashtable_c h)
 
CDECL void * CkHashtablePut (CkHashtable_c h, const void *atKey)
 
CDECL void * CkHashtableGet (CkHashtable_c h, const void *fromKey)
 
CDECL void CkHashtableRemove (CkHashtable_c h, const void *doomedKey)
 

Variables

static const unsigned int doublingPrimes []
 

Macro Definition Documentation

#define CDECL   extern "C"

Definition at line 418 of file hash_table.cpp.

#define copyEntry (   dest,
  src 
)    memcpy(dest,src,layout.entrySize())

Definition at line 128 of file hash_table.cpp.

#define copyKey (   dest,
  src 
)    memcpy(dest,src,layout.keySize())

Definition at line 126 of file hash_table.cpp.

#define copyObj (   dest,
  src 
)    memcpy(dest,src,layout.objectSize())

Definition at line 127 of file hash_table.cpp.

#define DEBUGF (   x)    /*printf x;*/
#define e2i (   entry)    (((entry)-table)/layout.entrySize())

Function Documentation

CDECL CkHashtable_c CkCreateHashtable_int ( int  objBytes,
int  initSize 
)

Definition at line 421 of file hash_table.cpp.

422 {
423  int objStart=2*sizeof(int);
424  CkHashtableLayout layout(sizeof(int),sizeof(int),
425  objStart,objBytes,objStart+objBytes);
426  return (CkHashtable_c)new CkHashtable(layout,initSize,0.5,
427  CkHashFunction_int,CkHashCompare_int);
428 }
void * CkHashtable_c
Definition: hash_table.h:81
CDECL CkHashtable_c CkCreateHashtable_string ( int  objBytes,
int  initSize 
)

Definition at line 430 of file hash_table.cpp.

References CkHashCompare_string(), and CkHashFunction_string().

431 {
432  int objStart=2*sizeof(char *);
433  CkHashtableLayout layout(sizeof(char *),sizeof(char *),
434  objStart,objBytes,objStart+objBytes);
435  return (CkHashtable_c)new CkHashtable(layout,initSize,0.5,
437 }
void * CkHashtable_c
Definition: hash_table.h:81
int CkHashCompare_string(const void *key1, const void *key2, size_t keyLen)
Definition: hash_table.cpp:112
CkHashCode CkHashFunction_string(const void *keyData, size_t keyLen)
Definition: hash_table.cpp:88

Here is the call graph for this function:

CDECL void CkDeleteHashtable ( CkHashtable_c  h)

Definition at line 438 of file hash_table.cpp.

439 {
440  delete (CkHashtable *)h;
441 }
int CkHashCompare_default ( const void *  key1,
const void *  key2,
size_t  keyLen 
)

Definition at line 102 of file hash_table.cpp.

References DEBUGF, and i.

103 {
104  DEBUGF((" comparing %d-byte keys--",keyLen))
105  const char *a=(const char *)key1;
106  const char *b=(const char *)key2;
107  for (unsigned int i=0;i<keyLen;i++)
108  if (a[i]!=b[i]) {DEBUGF(("different\n")) return 0;}
109  DEBUGF(("equal\n"))
110  return 1;
111 }
if(dy > dx)
const unsigned int key2
Definition: CImg.h:2686
blockLoc i
Definition: read.cpp:79
const NT & n
static bool equal(const Bbox_3 &b1, const Bbox_3 &b2, Real tol_r)
Definition: Overlay_1d.C:87
#define DEBUGF(x)
Definition: hash_table.cpp:72
for(;;)
const unsigned int key1
Definition: CImg.h:2685
int CkHashCompare_string ( const void *  key1,
const void *  key2,
size_t  keyLen 
)

Definition at line 112 of file hash_table.cpp.

References DEBUGF.

Referenced by CkCreateHashtable_string().

113 {
114  const char *a=*(const char **)key1;
115  const char *b=*(const char **)key2;
116  DEBUGF((" comparing '%s' and '%s'--",a,b))
117  while (*a && *b)
118  if (*a++!=*b++) {DEBUGF(("different\n")) return 0;}
119  DEBUGF(("equal\n"))
120  return 1;
121 }
if(dy > dx)
const unsigned int key2
Definition: CImg.h:2686
const NT & n
static bool equal(const Bbox_3 &b1, const Bbox_3 &b2, Real tol_r)
Definition: Overlay_1d.C:87
#define DEBUGF(x)
Definition: hash_table.cpp:72
const unsigned int key1
Definition: CImg.h:2685

Here is the caller graph for this function:

CkHashCode CkHashFunction_default ( const void *  keyData,
size_t  keyLen 
)

Definition at line 76 of file hash_table.cpp.

References d, DEBUGF, and i.

77 {
78  const unsigned char *d=(const unsigned char *)keyData;
79  CkHashCode ret=0;
80  for (unsigned int i=0;i<keyLen;i++) {
81  int shift1=((5*i)%16)+0;
82  int shift2=((6*i)%16)+8;
83  ret+=((0xa5^d[i])<<shift2)+(d[i]<<shift1);
84  }
85  DEBUGF((" hashing %d-byte key to %08x\n",keyLen,ret))
86  return ret;
87 }
const NT & d
blockLoc i
Definition: read.cpp:79
#define DEBUGF(x)
Definition: hash_table.cpp:72
CkHashCode CkHashFunction_string ( const void *  keyData,
size_t  keyLen 
)

Definition at line 88 of file hash_table.cpp.

References d, DEBUGF, and i.

Referenced by CkCreateHashtable_string().

89 {
90  const char *d=*(const char **)keyData;
91  CkHashCode ret=0;
92  for (int i=0;d[i]!=0;i++) {
93  int shift1=((5*i)%16)+0;
94  int shift2=((6*i)%16)+8;
95  ret+=((0xa5^d[i])<<shift2)+(d[i]<<shift1);
96  }
97  DEBUGF((" hashed key '%s' to %08x\n",d,ret))
98  return ret;
99 }
const NT & d
blockLoc i
Definition: read.cpp:79
#define DEBUGF(x)
Definition: hash_table.cpp:72

Here is the caller graph for this function:

CDECL void* CkHashtableGet ( CkHashtable_c  h,
const void *  fromKey 
)

Definition at line 449 of file hash_table.cpp.

450 {
451  return ((CkHashtable *)h)->get(fromKey);
452 }
CDECL void* CkHashtablePut ( CkHashtable_c  h,
const void *  atKey 
)

Definition at line 443 of file hash_table.cpp.

444 {
445  return ((CkHashtable *)h)->put(atKey);
446 }
CDECL void CkHashtableRemove ( CkHashtable_c  h,
const void *  doomedKey 
)

Definition at line 454 of file hash_table.cpp.

455 {
456  ((CkHashtable *)h)->remove(doomedKey);
457 }
void CmiAbort ( const char *  msg)

Definition at line 68 of file hash_table.cpp.

68  {
69  fprintf(stderr,"FATAL ERROR> %s\n",msg);
70  abort();
71 }
static unsigned int primeLargerThan ( unsigned int  x)
static

Definition at line 409 of file hash_table.cpp.

References i.

410 {
411  int i=0;
412  while (doublingPrimes[i]<=x)
413  i++;
414  return doublingPrimes[i];
415 }
blockLoc i
Definition: read.cpp:79
static const unsigned int doublingPrimes[]
Definition: hash_table.cpp:345
void int int REAL * x
Definition: read.cpp:74

Variable Documentation

const unsigned int doublingPrimes[]
static

Definition at line 345 of file hash_table.cpp.