Annotation of coherent/g/usr/lib/ncurses/comp_hash.c, revision 1.1

1.1     ! root        1: /*********************************************************************
        !             2: *                         COPYRIGHT NOTICE                           *
        !             3: **********************************************************************
        !             4: *        This software is copyright (C) 1982 by Pavel Curtis         *
        !             5: *                                                                    *
        !             6: *        Permission is granted to reproduce and distribute           *
        !             7: *        this file by any means so long as no fee is charged         *
        !             8: *        above a nominal handling fee and so long as this            *
        !             9: *        notice is always included in the copies.                    *
        !            10: *                                                                    *
        !            11: *        Other rights are reserved except as explicitly granted      *
        !            12: *        by written permission of the author.                        *
        !            13: *                Pavel Curtis                                        *
        !            14: *                Computer Science Dept.                              *
        !            15: *                405 Upson Hall                                      *
        !            16: *                Cornell University                                  *
        !            17: *                Ithaca, NY 14853                                    *
        !            18: *                                                                    *
        !            19: *                Ph- (607) 256-4934                                  *
        !            20: *                                                                    *
        !            21: *                Pavel.Cornell@Udel-Relay   (ARPAnet)                *
        !            22: *                decvax!cornell!pavel       (UUCPnet)                *
        !            23: *********************************************************************/
        !            24: 
        !            25: /*
        !            26:  *     comp_hash.c --- Routines to deal with the hashtable of capability
        !            27:  *                     names.
        !            28:  *
        !            29:  *  $Log:      comp_hash.c,v $
        !            30:  * Revision 1.8  93/04/12  14:12:58  bin
        !            31:  * Udo: third color update
        !            32:  * 
        !            33:  * Revision 1.2  92/04/13  14:36:14  bin
        !            34:  * update by vlad
        !            35:  * 
        !            36:  * Revision 2.1  82/10/25  14:45:34  pavel
        !            37:  * Added Copyright Notice
        !            38:  * 
        !            39:  * Revision 2.0  82/10/24  15:16:34  pavel
        !            40:  * Beta-one Test Release
        !            41:  * 
        !            42:  * Revision 1.3  82/08/23  22:29:33  pavel
        !            43:  * The REAL Alpha-one Release Version
        !            44:  * 
        !            45:  * Revision 1.2  82/08/19  19:09:46  pavel
        !            46:  * Alpha Test Release One
        !            47:  * 
        !            48:  * Revision 1.1  82/08/12  18:36:23  pavel
        !            49:  * Initial revision
        !            50:  * 
        !            51:  *
        !            52:  */
        !            53: 
        !            54: #ifdef RCSHDR
        !            55: static char RCSid[] =
        !            56:        "$Header: /src386/usr/lib/ncurses/RCS/comp_hash.c,v 1.8 93/04/12 14:12:58 bin Exp Locker: bin $";
        !            57: #endif
        !            58: 
        !            59: #include "compiler.h"
        !            60: #include "term.h"
        !            61: 
        !            62: 
        !            63: /*
        !            64:  *     make_hash_table()
        !            65:  *
        !            66:  *     Takes the entries in cap_table[] and hashes them into cap_hash_table[]
        !            67:  *     by name.  There are Captabsize entries in cap_table[] and Hashtabsize
        !            68:  *     slots in cap_hash_table[].
        !            69:  *
        !            70:  */
        !            71: 
        !            72: make_hash_table()
        !            73: {
        !            74:        int     i;
        !            75:        int     hashvalue;
        !            76:        int     collisions = 0;
        !            77: 
        !            78:        for (i=0; i < Captabsize; i++)
        !            79:        {
        !            80:            hashvalue = hash_function(cap_table[i].nte_name);       
        !            81:            DEBUG(9, "%d\n", hashvalue);
        !            82: 
        !            83:            if (cap_hash_table[hashvalue] != (struct name_table_entry *) 0)
        !            84:                collisions++;
        !            85: 
        !            86:            cap_table[i].nte_link = cap_hash_table[hashvalue];
        !            87:            cap_hash_table[hashvalue] = &cap_table[i];
        !            88:        }
        !            89: 
        !            90:        DEBUG(3, "Hash table complete\n%d collisions ", collisions);
        !            91:        DEBUG(3, "out of %d entries\n", Captabsize);
        !            92: }
        !            93: 
        !            94: 
        !            95: /*
        !            96:  *     int hash_function(string)
        !            97:  *
        !            98:  *     Computes the hashing function on the given string.
        !            99:  *
        !           100:  *     The current hash function is the sum of each consectutive pair
        !           101:  *     of characters, taken as two-byte integers, mod Hashtabsize.
        !           102:  *
        !           103:  */
        !           104: 
        !           105: static
        !           106: int
        !           107: hash_function(string)
        !           108: char   *string;
        !           109: {
        !           110:        long    sum = 0;
        !           111: 
        !           112:        while (*string)
        !           113:        {
        !           114:            sum += *string + (*(string + 1) << 8);
        !           115:            string++;
        !           116:        }
        !           117: 
        !           118:        return (sum % Hashtabsize);
        !           119: }
        !           120: 
        !           121: 
        !           122: /*
        !           123:  *     struct name_table_entry *
        !           124:  *     find_entry(string)
        !           125:  *
        !           126:  *     Finds the entry for the given string in the hash table if present.
        !           127:  *     Returns a pointer to the entry in the table or 0 if not found.
        !           128:  *
        !           129:  */
        !           130: 
        !           131: struct name_table_entry *
        !           132: find_entry(string)
        !           133: char   *string;
        !           134: {
        !           135:        int     hashvalue;
        !           136:        struct name_table_entry *ptr;
        !           137: 
        !           138:        hashvalue = hash_function(string);
        !           139: 
        !           140:        ptr = cap_hash_table[hashvalue];
        !           141: 
        !           142:        while (ptr != (struct name_table_entry *) 0  &&
        !           143:                                           strcmp(ptr->nte_name, string) != 0)
        !           144:            ptr = ptr->nte_link;
        !           145: 
        !           146:        return (ptr);
        !           147: }

unix.superglobalmegacorp.com

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