| 147 | /* debug_htable_enter - enter (key, value) pair */ |
| 148 | |
| 149 | DEBUG_HTABLE_INFO *debug_htable_enter(DEBUG_HTABLE *table, const char *key, char *value) |
| 150 | { |
| 151 | DEBUG_HTABLE_INFO *ht; |
| 152 | int ret; |
| 153 | unsigned n; |
| 154 | |
| 155 | n = table->hash_fn(key, strlen(key)); |
| 156 | |
| 157 | if (table->used >= table->size) { |
| 158 | ret = debug_htable_grow(table); |
| 159 | if(ret < 0) { |
| 160 | return(NULL); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | n = n % table->size; |
| 165 | |
| 166 | for (ht = table->data[n]; ht; ht = ht->next) { |
| 167 | if (STREQ(key, ht->key)) { |
| 168 | return (ht); |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | ht = (DEBUG_HTABLE_INFO *) MALLOC(sizeof(DEBUG_HTABLE_INFO)); |
| 173 | if (ht == NULL) { |
| 174 | return(NULL); |
| 175 | } |
| 176 | |
| 177 | ht->key = SANE_STRDUP(key); |
| 178 | if (ht->key == NULL) { |
| 179 | FREE(ht); |
| 180 | return(NULL); |
| 181 | } |
| 182 | |
| 183 | ht->value = value; |
| 184 | debug_htable_link(table, ht, n); |
| 185 | |
| 186 | return (ht); |
| 187 | } |
| 188 | |
| 189 | /* debug_htable_find - lookup value */ |
| 190 |
no test coverage detected
searching dependent graphs…