XrdOucHashVal.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                      X r d O u c H a s h V a l . c c                       */
00004 /*                                                                            */
00005 /* (c) 2004 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*       All Rights Reserved. See XrdInfo.cc for complete License Terms       */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010 
00011 //         $Id: XrdOucHashVal.cc 22437 2008-03-04 14:35:16Z rdm $ 
00012 
00013 const char *XrdOucHashValCVSID = "$Id: XrdOucHashVal.cc 22437 2008-03-04 14:35:16Z rdm $";
00014 
00015 #include "string.h"
00016 #ifndef WIN32
00017 #include "strings.h"
00018 #endif
00019 
00020 unsigned long XrdOucHashVal(const char *KeyVal)
00021          {extern unsigned long XrdOucHashVal2(const char *, int);
00022           return XrdOucHashVal2(KeyVal, strlen(KeyVal));
00023          }
00024 
00025 unsigned long XrdOucHashVal2(const char *KeyVal, int KeyLen)
00026 {  int j;
00027    unsigned long *lp, lword, hval = 0;
00028    int hl = sizeof(hval);
00029 
00030 // If name is shorter than the hash length, use the name.
00031 //
00032    if (KeyLen <= hl)
00033       {memcpy(&hval, KeyVal, (size_t)KeyLen);
00034        return hval;
00035       }
00036 
00037 // Compute the length of the name and develop starting hash.
00038 //
00039    hval = KeyLen;
00040    j = KeyLen % hl; KeyLen /= hl;
00041    if (j) 
00042       {memcpy(&lword, KeyVal, (size_t)hl);
00043        hval ^= lword;
00044       }
00045    lp = (unsigned long *)&KeyVal[j];
00046 
00047 // Compute and return the full hash.
00048 //
00049    while(KeyLen--)
00050         {memcpy(&lword, lp++, (size_t)hl);
00051          hval ^= lword;
00052         }
00053    return (hval ? hval : 1);
00054 }

Generated on Tue Jul 5 14:46:49 2011 for ROOT_528-00b_version by  doxygen 1.5.1