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