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