Change the (machine-generated) keywordhash.h file to increase the scope of the

tables used for keyword matching, so that the tables are accessible to
functions other then keywordCode().

FossilOrigin-Name: c5ed5ebdf660501fde7cc8aefaaaeae2a68e5899a64ac93f26684842a235281d
This commit is contained in:
drh 2017-07-06 16:33:14 +00:00
parent 9d8e401c2d
commit a0c3927510
3 changed files with 57 additions and 47 deletions

View File

@ -1,5 +1,5 @@
C More\scompact\simplementation\sof\sthe\stypeof()\sSQL\sfunction.
D 2017-07-06T13:51:50.091
C Change\sthe\s(machine-generated)\skeywordhash.h\sfile\sto\sincrease\sthe\sscope\sof\sthe\ntables\sused\sfor\skeyword\smatching,\sso\sthat\sthe\stables\sare\saccessible\sto\nfunctions\sother\sthen\skeywordCode().
D 2017-07-06T16:33:14.765
F Makefile.in 081e48dfe7f995d57ce1a88ddf4d2917b4349158648a6cd45b42beae30de3a12
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 4ebb1d257cac7fb1bcb4ba59278416d410ff1c4bf59447a9c37a415f3516056a
@ -1561,7 +1561,7 @@ F tool/logest.c 11346aa019e2e77a00902aa7d0cabd27bd2e8cca
F tool/max-limits.c cbb635fbb37ae4d05f240bfb5b5270bb63c54439
F tool/mkautoconfamal.sh e855df211ecbcc7131dee817110ff386cfb112f7
F tool/mkctimec.tcl dd183b73ae1c28249669741c250525f0407e579a70482371668fd5f130d9feb3
F tool/mkkeywordhash.c f7f3b342211ac6a14258b9726d5b97cf4f548f22
F tool/mkkeywordhash.c 2e852ac0dfdc5af18886dc1ce7e9676d11714ae3df0a282dc7d90b3a0fe2033c
F tool/mkmsvcmin.tcl cbd93f1cfa3a0a9ae56fc958510aa3fc3ac65e29cb111716199e3d0e66eefaa4
F tool/mkopcodec.tcl d1b6362bd3aa80d5520d4d6f3765badf01f6c43c
F tool/mkopcodeh.tcl a01d2c1d8a6205b03fc635adf3735b4c523befd3
@ -1628,7 +1628,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 06269257647db51fbc9f8cda88abac5db28b6f917a509768af7686dfa2b94511
R 8d88458ca1178062a686c7622fab862c
P efb4aab0caa4145732a5438cc2a193bc12c455b4007220564d240e75900ea8ad
R 77ecc187246c1c337a58790c9818d2e8
U drh
Z 16d02781d00f9c4bbd9708369c77eae3
Z a448086e00aa693e2477a7bd0d12a0df

View File

@ -1 +1 @@
efb4aab0caa4145732a5438cc2a193bc12c455b4007220564d240e75900ea8ad
c5ed5ebdf660501fde7cc8aefaaaeae2a68e5899a64ac93f26684842a235281d

View File

@ -336,8 +336,8 @@ int main(int argc, char **argv){
int count;
int nChar;
int totalLen = 0;
int aHash[1000]; /* 1000 is much bigger than nKeyword */
char zText[2000];
int aKWHash[1000]; /* 1000 is much bigger than nKeyword */
char zKWText[2000];
/* Remove entries from the list of keywords that have mask==0 */
for(i=j=0; i<nKeyword; i++){
@ -441,13 +441,13 @@ int main(int argc, char **argv){
bestSize = nKeyword;
bestCount = nKeyword*nKeyword;
for(i=nKeyword/2; i<=2*nKeyword; i++){
for(j=0; j<i; j++) aHash[j] = 0;
for(j=0; j<i; j++) aKWHash[j] = 0;
for(j=0; j<nKeyword; j++){
h = aKeywordTable[j].hash % i;
aHash[h] *= 2;
aHash[h]++;
aKWHash[h] *= 2;
aKWHash[h]++;
}
for(j=count=0; j<i; j++) count += aHash[j];
for(j=count=0; j<i; j++) count += aKWHash[j];
if( count<bestCount ){
bestCount = count;
bestSize = i;
@ -455,30 +455,29 @@ int main(int argc, char **argv){
}
/* Compute the hash */
for(i=0; i<bestSize; i++) aHash[i] = 0;
for(i=0; i<bestSize; i++) aKWHash[i] = 0;
for(i=0; i<nKeyword; i++){
h = aKeywordTable[i].hash % bestSize;
aKeywordTable[i].iNext = aHash[h];
aHash[h] = i+1;
aKeywordTable[i].iNext = aKWHash[h];
aKWHash[h] = i+1;
}
/* Begin generating code */
printf("%s", zHdr);
printf("/* Hash score: %d */\n", bestCount);
printf("static int keywordCode(const char *z, int n, int *pType){\n");
printf(" /* zText[] encodes %d bytes of keywords in %d bytes */\n",
printf("/* zKWText[] encodes %d bytes of keyword text in %d bytes */\n",
totalLen + nKeyword, nChar+1 );
for(i=j=k=0; i<nKeyword; i++){
Keyword *p = &aKeywordTable[i];
if( p->substrId ) continue;
memcpy(&zText[k], p->zName, p->len);
memcpy(&zKWText[k], p->zName, p->len);
k += p->len;
if( j+p->len>70 ){
printf("%*s */\n", 74-j, "");
j = 0;
}
if( j==0 ){
printf(" /* ");
printf("/* ");
j = 8;
}
printf("%s", p->zName);
@ -487,16 +486,16 @@ int main(int argc, char **argv){
if( j>0 ){
printf("%*s */\n", 74-j, "");
}
printf(" static const char zText[%d] = {\n", nChar);
zText[nChar] = 0;
printf("static const char zKWText[%d] = {\n", nChar);
zKWText[nChar] = 0;
for(i=j=0; i<k; i++){
if( j==0 ){
printf(" ");
printf(" ");
}
if( zText[i]==0 ){
if( zKWText[i]==0 ){
printf("0");
}else{
printf("'%c',", zText[i]);
printf("'%c',", zKWText[i]);
}
j += 4;
if( j>68 ){
@ -505,23 +504,27 @@ int main(int argc, char **argv){
}
}
if( j>0 ) printf("\n");
printf(" };\n");
printf("};\n");
printf(" static const unsigned char aHash[%d] = {\n", bestSize);
printf("/* aKWHash[i] is the hash value for the i-th keyword */\n");
printf("static const unsigned char aKWHash[%d] = {\n", bestSize);
for(i=j=0; i<bestSize; i++){
if( j==0 ) printf(" ");
printf(" %3d,", aHash[i]);
if( j==0 ) printf(" ");
printf(" %3d,", aKWHash[i]);
j++;
if( j>12 ){
printf("\n");
j = 0;
}
}
printf("%s };\n", j==0 ? "" : "\n");
printf("%s};\n", j==0 ? "" : "\n");
printf(" static const unsigned char aNext[%d] = {\n", nKeyword);
printf("/* aKWNext[] forms the hash collision chain. If aKWHash[i]==0\n");
printf("** then the i-th keyword has no more hash collisions. Otherwise,\n");
printf("** the next keyword with the same hash is aKWHash[i]-1. */\n");
printf("static const unsigned char aKWNext[%d] = {\n", nKeyword);
for(i=j=0; i<nKeyword; i++){
if( j==0 ) printf(" ");
if( j==0 ) printf(" ");
printf(" %3d,", aKeywordTable[i].iNext);
j++;
if( j>12 ){
@ -529,11 +532,12 @@ int main(int argc, char **argv){
j = 0;
}
}
printf("%s };\n", j==0 ? "" : "\n");
printf("%s};\n", j==0 ? "" : "\n");
printf(" static const unsigned char aLen[%d] = {\n", nKeyword);
printf("/* aKWLen[i] is the length (in bytes) of the i-th keyword */\n");
printf("static const unsigned char aKWLen[%d] = {\n", nKeyword);
for(i=j=0; i<nKeyword; i++){
if( j==0 ) printf(" ");
if( j==0 ) printf(" ");
printf(" %3d,", aKeywordTable[i].len+aKeywordTable[i].prefix);
j++;
if( j>12 ){
@ -541,11 +545,13 @@ int main(int argc, char **argv){
j = 0;
}
}
printf("%s };\n", j==0 ? "" : "\n");
printf("%s};\n", j==0 ? "" : "\n");
printf(" static const unsigned short int aOffset[%d] = {\n", nKeyword);
printf("/* aKWOffset[i] is the index into zKWText[] of the start of\n");
printf("** the text for the i-th keyword. */\n");
printf("static const unsigned short int aKWOffset[%d] = {\n", nKeyword);
for(i=j=0; i<nKeyword; i++){
if( j==0 ) printf(" ");
if( j==0 ) printf(" ");
printf(" %3d,", aKeywordTable[i].offset);
j++;
if( j>12 ){
@ -553,12 +559,13 @@ int main(int argc, char **argv){
j = 0;
}
}
printf("%s };\n", j==0 ? "" : "\n");
printf("%s};\n", j==0 ? "" : "\n");
printf(" static const unsigned char aCode[%d] = {\n", nKeyword);
printf("/* aKWCode[i] is the parser symbol code for the i-th keyword */\n");
printf("static const unsigned char aKWCode[%d] = {\n", nKeyword);
for(i=j=0; i<nKeyword; i++){
char *zToken = aKeywordTable[i].zTokenType;
if( j==0 ) printf(" ");
if( j==0 ) printf(" ");
printf("%s,%*s", zToken, (int)(14-strlen(zToken)), "");
j++;
if( j>=5 ){
@ -566,17 +573,20 @@ int main(int argc, char **argv){
j = 0;
}
}
printf("%s };\n", j==0 ? "" : "\n");
printf("%s};\n", j==0 ? "" : "\n");
printf("/* Check to see if z[0..n-1] is a keyword. If it is, write the\n");
printf("** parser symbol code for that keyword into *pType. Always\n");
printf("** return the integer n (the length of the token). */\n");
printf("static int keywordCode(const char *z, int n, int *pType){\n");
printf(" int i, j;\n");
printf(" const char *zKW;\n");
printf(" if( n>=2 ){\n");
printf(" i = ((charMap(z[0])*4) ^ (charMap(z[n-1])*3) ^ n) %% %d;\n",
bestSize);
printf(" for(i=((int)aHash[i])-1; i>=0; i=((int)aNext[i])-1){\n");
printf(" if( aLen[i]!=n ) continue;\n");
printf(" for(i=((int)aKWHash[i])-1; i>=0; i=((int)aKWNext[i])-1){\n");
printf(" if( aKWLen[i]!=n ) continue;\n");
printf(" j = 0;\n");
printf(" zKW = &zText[aOffset[i]];\n");
printf(" zKW = &zKWText[aKWOffset[i]];\n");
printf("#ifdef SQLITE_ASCII\n");
printf(" while( j<n && (z[j]&~0x20)==zKW[j] ){ j++; }\n");
printf("#endif\n");
@ -588,7 +598,7 @@ int main(int argc, char **argv){
printf(" testcase( i==%d ); /* %s */\n",
i, aKeywordTable[i].zOrigName);
}
printf(" *pType = aCode[i];\n");
printf(" *pType = aKWCode[i];\n");
printf(" break;\n");
printf(" }\n");
printf(" }\n");