hash_tables.c revision 145971
1/* 2 * DO NOT EDIT 3 * $FreeBSD: head/usr.bin/make/hash_tables.c 145971 2005-05-06 18:30:06Z harti $ 4 * auto-generated from FreeBSD: src/usr.bin/make/parse.c,v 1.100 2005/04/29 15:15:28 harti Exp 5 * DO NOT EDIT 6 */ 7#include <sys/types.h> 8 9#include "hash_tables.h" 10 11/* 12 * d=2 13 * n=38 14 * m=18 15 * c=2.09 16 * maxlen=1 17 * minklen=2 18 * maxklen=9 19 * minchar=97 20 * maxchar=119 21 * loop=0 22 * numiter=2 23 * seed= 24 */ 25 26static const signed char directive_g[] = { 27 16, 0, -1, 14, 5, 2, 2, -1, 0, 0, 28 -1, -1, 16, 11, -1, 15, -1, 14, 7, -1, 29 8, 6, 1, -1, -1, 0, 4, 6, -1, 0, 30 0, 2, 0, 13, -1, 14, -1, 0, 31}; 32 33static const u_char directive_T0[] = { 34 11, 25, 14, 30, 14, 26, 23, 15, 9, 37, 35 27, 32, 27, 1, 17, 27, 35, 13, 8, 22, 36 8, 28, 7, 37}; 38 39static const u_char directive_T1[] = { 40 19, 20, 31, 17, 29, 2, 7, 12, 1, 31, 41 11, 18, 11, 20, 10, 2, 15, 19, 4, 10, 42 13, 36, 3, 43}; 44 45 46int 47directive_hash(const u_char *key, size_t len) 48{ 49 unsigned f0, f1; 50 const u_char *kp = key; 51 52 if (len < 2 || len > 9) 53 return -1; 54 55 for (f0=f1=0; kp < key + len; ++kp) { 56 if (*kp < 97 || *kp > 119) 57 return -1; 58 f0 += directive_T0[-97 + *kp]; 59 f1 += directive_T1[-97 + *kp]; 60 } 61 62 f0 %= 38; 63 f1 %= 38; 64 65 return (directive_g[f0] + directive_g[f1]) % 18; 66} 67/* 68 * d=2 69 * n=72 70 * m=34 71 * c=2.09 72 * maxlen=1 73 * minklen=4 74 * maxklen=12 75 * minchar=46 76 * maxchar=95 77 * loop=0 78 * numiter=4 79 * seed= 80 */ 81 82static const signed char keyword_g[] = { 83 8, 15, -1, 25, 22, 20, -1, 33, 16, -1, 84 21, 31, 0, 0, 0, 29, 30, 8, -1, 0, 85 -1, 21, -1, 0, -1, -1, -1, -1, -1, 4, 86 -1, -1, 25, 28, -1, 27, 11, 23, 0, 0, 87 24, -1, -1, 0, 3, 0, -1, 24, 0, 0, 88 -1, 28, 12, -1, 20, 13, -1, 5, -1, 1, 89 0, 0, -1, 0, 10, 19, 13, 9, -1, 2, 90 -1, -1, 91}; 92 93static const u_char keyword_T0[] = { 94 32, 10, 54, 61, 2, 35, 62, 50, 52, 53, 95 70, 7, 62, 18, 24, 30, 31, 66, 10, 61, 96 52, 71, 56, 56, 28, 6, 33, 67, 12, 41, 97 39, 45, 51, 21, 34, 53, 56, 40, 47, 52, 98 21, 61, 60, 12, 7, 28, 42, 38, 38, 52, 99}; 100 101static const u_char keyword_T1[] = { 102 0, 39, 65, 48, 13, 62, 46, 42, 5, 50, 103 69, 69, 69, 43, 2, 46, 12, 6, 11, 9, 104 24, 10, 25, 64, 68, 13, 57, 55, 17, 33, 105 1, 18, 0, 67, 10, 14, 57, 56, 0, 6, 106 50, 13, 3, 47, 56, 22, 37, 13, 28, 48, 107}; 108 109 110int 111keyword_hash(const u_char *key, size_t len) 112{ 113 unsigned f0, f1; 114 const u_char *kp = key; 115 116 if (len < 4 || len > 12) 117 return -1; 118 119 for (f0=f1=0; *kp; ++kp) { 120 if (*kp < 46 || *kp > 95) 121 return -1; 122 f0 += keyword_T0[-46 + *kp]; 123 f1 += keyword_T1[-46 + *kp]; 124 } 125 126 f0 %= 72; 127 f1 %= 72; 128 129 return (keyword_g[f0] + keyword_g[f1]) % 34; 130} 131