| 146 | */ |
| 147 | |
| 148 | HASHDATA * hash_insert( struct hash * hp, OBJECT * key, int * found ) |
| 149 | { |
| 150 | ITEM * i; |
| 151 | unsigned int keyval = hash_keyval( key ); |
| 152 | |
| 153 | #ifdef HASH_DEBUG_PROFILE |
| 154 | profile_frame prof[ 1 ]; |
| 155 | if ( DEBUG_PROFILE ) |
| 156 | profile_enter( 0, prof ); |
| 157 | #endif |
| 158 | |
| 159 | if ( !hp->items.more ) |
| 160 | hashrehash( hp ); |
| 161 | |
| 162 | i = hash_search( hp, keyval, key, 0 ); |
| 163 | if ( i ) |
| 164 | *found = 1; |
| 165 | else |
| 166 | { |
| 167 | ITEM * * base = hash_bucket( hp, keyval ); |
| 168 | |
| 169 | /* Try to grab one from the free list. */ |
| 170 | if ( hp->items.free ) |
| 171 | { |
| 172 | i = hp->items.free; |
| 173 | hp->items.free = i->next; |
| 174 | assert( !hash_item_key( i ) ); |
| 175 | } |
| 176 | else |
| 177 | { |
| 178 | i = (ITEM *)hp->items.next; |
| 179 | hp->items.next += hp->items.size; |
| 180 | } |
| 181 | --hp->items.more; |
| 182 | i->next = *base; |
| 183 | *base = i; |
| 184 | *found = 0; |
| 185 | } |
| 186 | |
| 187 | #ifdef HASH_DEBUG_PROFILE |
| 188 | if ( DEBUG_PROFILE ) |
| 189 | profile_exit( prof ); |
| 190 | #endif |
| 191 | |
| 192 | return hash_item_data( i ); |
| 193 | } |
| 194 | |
| 195 | |
| 196 | /* |
no test coverage detected