* xmlHashCreate: * @size: initial size of the hash table * * Create a new hash table. Set size to zero if the number of entries * can't be estimated. * * Returns the newly created object, or NULL if a memory allocation failed. */
| 157 | * Returns the newly created object, or NULL if a memory allocation failed. |
| 158 | */ |
| 159 | xmlHashTablePtr |
| 160 | xmlHashCreate(int size) { |
| 161 | xmlHashTablePtr hash; |
| 162 | |
| 163 | xmlInitParser(); |
| 164 | |
| 165 | hash = xmlMalloc(sizeof(*hash)); |
| 166 | if (hash == NULL) |
| 167 | return(NULL); |
| 168 | hash->dict = NULL; |
| 169 | hash->size = 0; |
| 170 | hash->table = NULL; |
| 171 | hash->nbElems = 0; |
| 172 | hash->randomSeed = xmlRandom(); |
| 173 | #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION |
| 174 | hash->randomSeed = 0; |
| 175 | #endif |
| 176 | |
| 177 | /* |
| 178 | * Unless a larger size is passed, the backing table is created |
| 179 | * lazily with MIN_HASH_SIZE capacity. In practice, there are many |
| 180 | * hash tables which are never filled. |
| 181 | */ |
| 182 | if (size > MIN_HASH_SIZE) { |
| 183 | unsigned newSize = MIN_HASH_SIZE * 2; |
| 184 | |
| 185 | while ((newSize < (unsigned) size) && (newSize < MAX_HASH_SIZE)) |
| 186 | newSize *= 2; |
| 187 | |
| 188 | if (xmlHashGrow(hash, newSize) != 0) { |
| 189 | xmlFree(hash); |
| 190 | return(NULL); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | return(hash); |
| 195 | } |
| 196 | |
| 197 | /** |
| 198 | * xmlHashCreateDict: |