xref: /titanic_50/usr/src/lib/libast/common/include/hashkey.h (revision df14233e629298598736976c5bfcf4a31873745f)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *           Copyright (c) 1985-2007 AT&T Knowledge Ventures            *
5 *                      and is licensed under the                       *
6 *                  Common Public License, Version 1.0                  *
7 *                      by AT&T Knowledge Ventures                      *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *            http://www.opensource.org/licenses/cpl1.0.txt             *
11 *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * Glenn Fowler
25  * AT&T Research
26  *
27  * 1-6 char lower-case keyword -> long hash
28  * digit args passed as HASHKEYN('2')
29  */
30 
31 #ifndef _HASHKEY_H
32 #define _HASHKEY_H
33 
34 #define HASHKEYMAX			6
35 #define HASHKEYBIT			5
36 #define HASHKEYOFF			('a'-1)
37 #define HASHKEYPART(h,c)		(((h)<<HASHKEYBIT)+HASHKEY1(c))
38 
39 #define HASHKEYN(n)			((n)-'0'+'z'+1)
40 
41 #define HASHKEY1(c1)			((c1)-HASHKEYOFF)
42 #define HASHKEY2(c1,c2)			HASHKEYPART(HASHKEY1(c1),c2)
43 #define HASHKEY3(c1,c2,c3)		HASHKEYPART(HASHKEY2(c1,c2),c3)
44 #define HASHKEY4(c1,c2,c3,c4)		HASHKEYPART(HASHKEY3(c1,c2,c3),c4)
45 #define HASHKEY5(c1,c2,c3,c4,c5)	HASHKEYPART(HASHKEY4(c1,c2,c3,c4),c5)
46 #define HASHKEY6(c1,c2,c3,c4,c5,c6)	HASHKEYPART(HASHKEY5(c1,c2,c3,c4,c5),c6)
47 
48 #define HASHNKEY1(n,c1)			HASHKEY2((n)+HASHKEYOFF,c1)
49 #define HASHNKEY2(n,c2,c1)		HASHKEY3((n)+HASHKEYOFF,c2,c1)
50 #define HASHNKEY3(n,c3,c2,c1)		HASHKEY4((n)+HASHKEYOFF,c3,c2,c1)
51 #define HASHNKEY4(n,c4,c3,c2,c1)	HASHKEY5((n)+'a',c4,c3,c2,c1)
52 #define HASHNKEY5(n,c5,c4,c3,c2,c1)	HASHKEY6((n)+'a',c5,c4,c3,c2,c1)
53 
54 #if _BLD_ast && defined(__EXPORT__)
55 #define extern		__EXPORT__
56 #endif
57 
58 extern long	strkey(const char*);
59 
60 #undef	extern
61 
62 #endif
63