我正在阅读mysql的gen_lex_hash.cc,但我不知道解释:
给出算法的思想见Donald E. Knuth第3卷“排序和搜索”中的“计算机编程艺术”(第6.3章“数字搜索”-章节名称和编号从俄文版本返回)
as illustration of data structures, imagine next table:
static SYMBOL symbols[] = {
{ "ADD", SYM(ADD),0,0},
{ "AND", SYM(AND),0,0},
{ "DAY", SYM(DAY_SYM),0,0},
};
for this structure, presented program generate next searching-structure:
+-----------+-+-+-+
| len |1|2|3|
+-----------+-+-+-+
|first_char |0|0|a|
|last_char |0|0|d|
|link |0|0|+|
|
V
+----------+-+-+-+--+
| 1 char|a|b|c|d |
+----------+-+-+-+--+
|first_char|d|0|0|0 |
|last_char |n|0|0|-1|
|link |+|0|0|+ |
| |
| V
| symbols[2] ( "DAY" )
V
+----------+--+-+-+-+-+-+-+-+-+-+--+
| 2 char|d |e|f|j|h|i|j|k|l|m|n |
+----------+--+-+-+-+-+-+-+-+-+-+--+
|first_char|0 |0|0|0|0|0|0|0|0|0|0 |
|last_char |-1|0|0|0|0|0|0|0|0|0|-1|
|link |+ |0|0|0|0|0|0|0|0|0|+ |
| |
V V
symbols[0] ( "ADD" ) symbols[1] ( "AND" )
for optimization, link is the 16-bit index in 'symbols'
or search-array..从上面的流程中,我无法理解细节,也找不到任何详细的解释。
为了理解这一点,我调试了程序gen_lex_hash,但是它没有任何帮助,例如:
0,-1是什么意思?如有任何建议,将不胜感激!
发布于 2017-08-17 04:36:37
这似乎是从计算机编程艺术,第3卷:排序和搜索唐纳德Knuth,第6.3章(从第492页开始)的"trie搜索“算法的实现。
它似乎用于有效地识别查询中的SQL关键字。
https://stackoverflow.com/questions/45734389
复制相似问题