| 194 | |
| 195 | |
| 196 | static char const * string_set_insert( string_set * set, char const * string, |
| 197 | int const size ) |
| 198 | { |
| 199 | unsigned hash = hash_keyval( string, size ); |
| 200 | unsigned pos = hash % set->num; |
| 201 | |
| 202 | struct hash_item * result; |
| 203 | |
| 204 | for ( result = set->data[ pos ]; result; result = result->header.next ) |
| 205 | if ( !strncmp( result->data, string, size ) && !result->data[ size ] ) |
| 206 | return result->data; |
| 207 | |
| 208 | if ( set->size >= set->num ) |
| 209 | { |
| 210 | string_set_resize( set ); |
| 211 | pos = hash % set->num; |
| 212 | } |
| 213 | |
| 214 | result = (struct hash_item *)allocate( sizeof( struct hash_header ) + size + |
| 215 | 1 ); |
| 216 | result->header.hash = hash; |
| 217 | result->header.next = set->data[ pos ]; |
| 218 | #ifndef NDEBUG |
| 219 | result->header.magic = OBJECT_MAGIC; |
| 220 | #endif |
| 221 | memcpy( result->data, string, size ); |
| 222 | result->data[ size ] = '\0'; |
| 223 | assert( hash_keyval( result->data, size ) == result->header.hash ); |
| 224 | set->data[ pos ] = result; |
| 225 | strtotal += size + 1; |
| 226 | ++set->size; |
| 227 | |
| 228 | return result->data; |
| 229 | } |
| 230 | |
| 231 | |
| 232 | static struct hash_item * object_get_item( OBJECT * obj ) |
no test coverage detected