Annotation of researchv10no/cmd/cfront/ooptcfront/hash.h, revision 1.1

1.1     ! root        1: /* Compiler interface to hash tables from odi library. */
        !             2: /*
        !             3:        $Source: /usr3/lang/benson/work/stripped_cfront/RCS/hash.h,v $ $RCSfile: hash.h,v $
        !             4:        $Revision: 1.1 $                $Date: 89/11/20 08:50:36 $
        !             5:        $Author: benson $               $Locker:  $
        !             6:        $State: Exp $
        !             7: */
        !             8: 
        !             9: #include <hash.H>
        !            10: #include <string.h>
        !            11: 
        !            12: inline int pointer_hasheq (int a, int b)
        !            13: {
        !            14:     return a == b;
        !            15: };
        !            16: 
        !            17: inline unsigned int pointer_hash_fcn (int x)
        !            18: {
        !            19:     unsigned X = (unsigned) x;
        !            20:     return ((X << 16) | (X >> 16)) ^ x;
        !            21: }
        !            22: 
        !            23: 
        !            24: class pointer_hash : public Hash {
        !            25:   public:
        !            26:     pointer_hash (int sz = 0) : Hash (sz) {
        !            27:        key_hash_function = pointer_hash_fcn;
        !            28:        key_key_equality_function = pointer_hasheq;
        !            29:     }
        !            30: 
        !            31:     pointer_hash (pointer_hash& h) : Hash (h) {};
        !            32: };
        !            33: 
        !            34: inline int string_hasheq (int a, int b)
        !            35: {
        !            36:     return !strcmp((char *)a, (char *) b);
        !            37: };
        !            38: 
        !            39: static unsigned int string_hash_fcn (int x)
        !            40: {
        !            41:     char * str = (char *)x;
        !            42:     int l = strlen(str);
        !            43:        
        !            44:     if(x <= 4) return str[0];
        !            45:     else {
        !            46:        unsigned int * f4 = (unsigned int *) str;
        !            47:        if (l < 8) return ((*f4 << 16) | (*f4 >> 16)) ^ *f4;
        !            48:        else {
        !            49:            unsigned int * s4 = f4 ++;
        !            50:            return ((*f4 << 16) | (*f4 >> 16)) ^ *s4;
        !            51:        }
        !            52:     }
        !            53: };
        !            54: 
        !            55: 
        !            56: class string_hash : public Hash {
        !            57:     public:
        !            58: 
        !            59:     string_hash (int sz = 0) : Hash (sz) {
        !            60:        key_hash_function = string_hash_fcn;
        !            61:        key_key_equality_function = string_hasheq;
        !            62:     };
        !            63: 
        !            64:     string_hash (string_hash& h) : Hash (h) {};
        !            65: };
        !            66: 
        !            67: 
        !            68: /*
        !            69:    $Log:       hash.h,v $
        !            70:  * Revision 1.1  89/11/20  08:50:36  benson
        !            71:  * Initial revision
        !            72:  * 
        !            73:  * Revision 1.1  89/09/26  10:11:51  benson
        !            74:  * Initial revision
        !            75:  * 
        !            76: 
        !            77: 
        !            78:    end_log
        !            79: */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.