| 107 | // |
| 108 | |
| 109 | void HSH_insert( gpre_sym* symbol) |
| 110 | { |
| 111 | const int h = hash(symbol->sym_string); |
| 112 | |
| 113 | for (gpre_sym** next = &hash_table[h]; *next; next = &(*next)->sym_collision) |
| 114 | { |
| 115 | for (const gpre_sym* ptr = *next; ptr; ptr = ptr->sym_homonym) |
| 116 | { |
| 117 | if (ptr == symbol) |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | if (scompare(symbol->sym_string, (*next)->sym_string)) |
| 122 | { |
| 123 | // insert in most recently seen order; |
| 124 | // This is important for alias resolution in subqueries. |
| 125 | // BUT insert tokens AFTER keyword! |
| 126 | // In a lookup, keyword should be found first. |
| 127 | // This assumes that KEYWORDS are inserted before any other token. |
| 128 | // No one should be using a keywords as an alias anyway. |
| 129 | |
| 130 | if ((*next)->sym_type == SYM_keyword) |
| 131 | { |
| 132 | symbol->sym_homonym = (*next)->sym_homonym; |
| 133 | symbol->sym_collision = NULL; |
| 134 | (*next)->sym_homonym = symbol; |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | symbol->sym_homonym = *next; |
| 139 | symbol->sym_collision = (*next)->sym_collision; |
| 140 | (*next)->sym_collision = NULL; |
| 141 | *next = symbol; |
| 142 | } |
| 143 | return; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | symbol->sym_collision = hash_table[h]; |
| 148 | hash_table[h] = symbol; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | //____________________________________________________________ |
no test coverage detected