xref: /illumos-gate/usr/src/contrib/ast/src/lib/libast/astsa/hashkey.h (revision 28ab0ca48b3e331cbbb231b1c8325f9f24f9af95)
1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2012 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
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 /*
23  * Glenn Fowler
24  * AT&T Research
25  *
26  * 1-6 char lower-case keyword -> long hash
27  * digit args passed as HASHKEYN('2')
28  */
29 
30 #ifndef _HASHKEY_H
31 #define _HASHKEY_H			1
32 
33 #define HASHKEYMAX			6
34 #define HASHKEYBIT			5
35 #define HASHKEYOFF			('a'-1)
36 #define HASHKEYPART(h,c)		(((h)<<HASHKEYBIT)+HASHKEY1(c))
37 
38 #define HASHKEYN(n)			((n)-'0'+'z'+1)
39 
40 #define HASHKEY1(c1)			((c1)-HASHKEYOFF)
41 #define HASHKEY2(c1,c2)			HASHKEYPART(HASHKEY1(c1),c2)
42 #define HASHKEY3(c1,c2,c3)		HASHKEYPART(HASHKEY2(c1,c2),c3)
43 #define HASHKEY4(c1,c2,c3,c4)		HASHKEYPART(HASHKEY3(c1,c2,c3),c4)
44 #define HASHKEY5(c1,c2,c3,c4,c5)	HASHKEYPART(HASHKEY4(c1,c2,c3,c4),c5)
45 #define HASHKEY6(c1,c2,c3,c4,c5,c6)	HASHKEYPART(HASHKEY5(c1,c2,c3,c4,c5),c6)
46 
47 #define HASHNKEY1(n,c1)			HASHKEY2((n)+HASHKEYOFF,c1)
48 #define HASHNKEY2(n,c2,c1)		HASHKEY3((n)+HASHKEYOFF,c2,c1)
49 #define HASHNKEY3(n,c3,c2,c1)		HASHKEY4((n)+HASHKEYOFF,c3,c2,c1)
50 #define HASHNKEY4(n,c4,c3,c2,c1)	HASHKEY5((n)+'a',c4,c3,c2,c1)
51 #define HASHNKEY5(n,c5,c4,c3,c2,c1)	HASHKEY6((n)+'a',c5,c4,c3,c2,c1)
52 
53 #if _BLD_ast && defined(__EXPORT__)
54 #define extern		__EXPORT__
55 #endif
56 
57 extern long	strkey(const char*);
58 
59 #undef	extern
60 
61 #endif
62