| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | #include "magick/studio.h" |
|---|
| 46 | #include "magick/exception.h" |
|---|
| 47 | #include "magick/exception-private.h" |
|---|
| 48 | #include "magick/hashmap.h" |
|---|
| 49 | #include "magick/memory_.h" |
|---|
| 50 | #include "magick/semaphore.h" |
|---|
| 51 | #include "magick/signature.h" |
|---|
| 52 | #include "magick/string_.h" |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | typedef struct _ElementInfo |
|---|
| 58 | { |
|---|
| 59 | void |
|---|
| 60 | *value; |
|---|
| 61 | |
|---|
| 62 | struct _ElementInfo |
|---|
| 63 | *next; |
|---|
| 64 | } ElementInfo; |
|---|
| 65 | |
|---|
| 66 | typedef struct _EntryInfo |
|---|
| 67 | { |
|---|
| 68 | size_t |
|---|
| 69 | hash; |
|---|
| 70 | |
|---|
| 71 | void |
|---|
| 72 | *key, |
|---|
| 73 | *value; |
|---|
| 74 | } EntryInfo; |
|---|
| 75 | |
|---|
| 76 | struct _LinkedListInfo |
|---|
| 77 | { |
|---|
| 78 | unsigned long |
|---|
| 79 | capacity, |
|---|
| 80 | elements; |
|---|
| 81 | |
|---|
| 82 | ElementInfo |
|---|
| 83 | *head, |
|---|
| 84 | *tail, |
|---|
| 85 | *next; |
|---|
| 86 | |
|---|
| 87 | MagickBooleanType |
|---|
| 88 | debug; |
|---|
| 89 | |
|---|
| 90 | SemaphoreInfo |
|---|
| 91 | *semaphore; |
|---|
| 92 | |
|---|
| 93 | unsigned long |
|---|
| 94 | signature; |
|---|
| 95 | }; |
|---|
| 96 | |
|---|
| 97 | struct _HashmapInfo |
|---|
| 98 | { |
|---|
| 99 | size_t |
|---|
| 100 | (*hash)(const void *); |
|---|
| 101 | |
|---|
| 102 | MagickBooleanType |
|---|
| 103 | (*compare)(const void *,const void *); |
|---|
| 104 | |
|---|
| 105 | void |
|---|
| 106 | *(*relinquish_key)(void *), |
|---|
| 107 | *(*relinquish_value)(void *); |
|---|
| 108 | |
|---|
| 109 | unsigned long |
|---|
| 110 | capacity, |
|---|
| 111 | entries, |
|---|
| 112 | next; |
|---|
| 113 | |
|---|
| 114 | MagickBooleanType |
|---|
| 115 | head_of_list; |
|---|
| 116 | |
|---|
| 117 | LinkedListInfo |
|---|
| 118 | **map; |
|---|
| 119 | |
|---|
| 120 | MagickBooleanType |
|---|
| 121 | debug; |
|---|
| 122 | |
|---|
| 123 | SemaphoreInfo |
|---|
| 124 | *semaphore; |
|---|
| 125 | |
|---|
| 126 | unsigned long |
|---|
| 127 | signature; |
|---|
| 128 | }; |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | MagickExport MagickBooleanType AppendValueToLinkedList( |
|---|
| 156 | LinkedListInfo *list_info,const void *value) |
|---|
| 157 | { |
|---|
| 158 | register ElementInfo |
|---|
| 159 | *next; |
|---|
| 160 | |
|---|
| 161 | assert(list_info != (LinkedListInfo *) NULL); |
|---|
| 162 | assert(list_info->signature == MagickSignature); |
|---|
| 163 | list_info->debug=IsEventLogging(); |
|---|
| 164 | if (list_info->debug != MagickFalse) |
|---|
| 165 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 166 | if (list_info->elements == list_info->capacity) |
|---|
| 167 | return(MagickFalse); |
|---|
| 168 | next=(ElementInfo *) AcquireMagickMemory(sizeof(*next)); |
|---|
| 169 | if (next == (ElementInfo *) NULL) |
|---|
| 170 | return(MagickFalse); |
|---|
| 171 | next->value=(void *) value; |
|---|
| 172 | next->next=(ElementInfo *) NULL; |
|---|
| 173 | AcquireSemaphoreInfo(&list_info->semaphore); |
|---|
| 174 | if (list_info->next == (ElementInfo *) NULL) |
|---|
| 175 | list_info->next=next; |
|---|
| 176 | if (list_info->elements == 0) |
|---|
| 177 | list_info->head=next; |
|---|
| 178 | else |
|---|
| 179 | list_info->tail->next=next; |
|---|
| 180 | list_info->tail=next; |
|---|
| 181 | list_info->elements++; |
|---|
| 182 | RelinquishSemaphoreInfo(list_info->semaphore); |
|---|
| 183 | return(MagickTrue); |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | |
|---|
| 211 | |
|---|
| 212 | MagickExport void ClearLinkedList(LinkedListInfo *list_info, |
|---|
| 213 | void *(*relinquish_value)(void *)) |
|---|
| 214 | { |
|---|
| 215 | ElementInfo |
|---|
| 216 | *element; |
|---|
| 217 | |
|---|
| 218 | register ElementInfo |
|---|
| 219 | *next; |
|---|
| 220 | |
|---|
| 221 | assert(list_info != (LinkedListInfo *) NULL); |
|---|
| 222 | assert(list_info->signature == MagickSignature); |
|---|
| 223 | if (list_info->debug != MagickFalse) |
|---|
| 224 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 225 | AcquireSemaphoreInfo(&list_info->semaphore); |
|---|
| 226 | next=list_info->head; |
|---|
| 227 | while (next != (ElementInfo *) NULL) |
|---|
| 228 | { |
|---|
| 229 | if (relinquish_value != (void *(*)(void *)) NULL) |
|---|
| 230 | next->value=relinquish_value(next->value); |
|---|
| 231 | element=next; |
|---|
| 232 | next=next->next; |
|---|
| 233 | element=(ElementInfo *) RelinquishMagickMemory(element); |
|---|
| 234 | } |
|---|
| 235 | list_info->head=(ElementInfo *) NULL; |
|---|
| 236 | list_info->tail=(ElementInfo *) NULL; |
|---|
| 237 | list_info->next=(ElementInfo *) NULL; |
|---|
| 238 | list_info->elements=0; |
|---|
| 239 | RelinquishSemaphoreInfo(list_info->semaphore); |
|---|
| 240 | } |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | MagickExport MagickBooleanType CompareHashmapString(const void *target, |
|---|
| 269 | const void *source) |
|---|
| 270 | { |
|---|
| 271 | const char |
|---|
| 272 | *p, |
|---|
| 273 | *q; |
|---|
| 274 | |
|---|
| 275 | p=(const char *) target; |
|---|
| 276 | q=(const char *) source; |
|---|
| 277 | return(LocaleCompare(p,q) == 0 ? MagickTrue : MagickFalse); |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | MagickExport MagickBooleanType CompareHashmapStringInfo(const void *target, |
|---|
| 307 | const void *source) |
|---|
| 308 | { |
|---|
| 309 | const StringInfo |
|---|
| 310 | *p, |
|---|
| 311 | *q; |
|---|
| 312 | |
|---|
| 313 | p=(const StringInfo *) target; |
|---|
| 314 | q=(const StringInfo *) source; |
|---|
| 315 | return(CompareStringInfo(p,q) == 0 ? MagickTrue : MagickFalse); |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | MagickExport HashmapInfo *DestroyHashmap(HashmapInfo *hashmap_info) |
|---|
| 341 | { |
|---|
| 342 | LinkedListInfo |
|---|
| 343 | *list_info; |
|---|
| 344 | |
|---|
| 345 | register EntryInfo |
|---|
| 346 | *entry; |
|---|
| 347 | |
|---|
| 348 | register long |
|---|
| 349 | i; |
|---|
| 350 | |
|---|
| 351 | assert(hashmap_info != (HashmapInfo *) NULL); |
|---|
| 352 | assert(hashmap_info->signature == MagickSignature); |
|---|
| 353 | if (hashmap_info->debug != MagickFalse) |
|---|
| 354 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 355 | AcquireSemaphoreInfo(&hashmap_info->semaphore); |
|---|
| 356 | for (i=0; i < (long) hashmap_info->capacity; i++) |
|---|
| 357 | { |
|---|
| 358 | list_info=hashmap_info->map[i]; |
|---|
| 359 | if (list_info != (LinkedListInfo *) NULL) |
|---|
| 360 | { |
|---|
| 361 | list_info->next=list_info->head; |
|---|
| 362 | entry=(EntryInfo *) GetNextValueInLinkedList(list_info); |
|---|
| 363 | while (entry != (EntryInfo *) NULL) |
|---|
| 364 | { |
|---|
| 365 | if (hashmap_info->relinquish_key != (void *(*)(void *)) NULL) |
|---|
| 366 | entry->key=hashmap_info->relinquish_key(entry->key); |
|---|
| 367 | if (hashmap_info->relinquish_value != (void *(*)(void *)) NULL) |
|---|
| 368 | entry->value=hashmap_info->relinquish_value(entry->value); |
|---|
| 369 | entry=(EntryInfo *) GetNextValueInLinkedList(list_info); |
|---|
| 370 | } |
|---|
| 371 | } |
|---|
| 372 | if (list_info != (LinkedListInfo *) NULL) |
|---|
| 373 | list_info=DestroyLinkedList(list_info,RelinquishMagickMemory); |
|---|
| 374 | } |
|---|
| 375 | hashmap_info->map=(LinkedListInfo **) RelinquishMagickMemory( |
|---|
| 376 | hashmap_info->map); |
|---|
| 377 | hashmap_info->signature=(~MagickSignature); |
|---|
| 378 | RelinquishSemaphoreInfo(hashmap_info->semaphore); |
|---|
| 379 | hashmap_info->semaphore=DestroySemaphoreInfo(hashmap_info->semaphore); |
|---|
| 380 | hashmap_info=(HashmapInfo *) RelinquishMagickMemory(hashmap_info); |
|---|
| 381 | return(hashmap_info); |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | |
|---|
| 387 | |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | |
|---|
| 403 | |
|---|
| 404 | |
|---|
| 405 | |
|---|
| 406 | |
|---|
| 407 | |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | MagickExport LinkedListInfo *DestroyLinkedList(LinkedListInfo *list_info, |
|---|
| 411 | void *(*relinquish_value)(void *)) |
|---|
| 412 | { |
|---|
| 413 | ElementInfo |
|---|
| 414 | *entry; |
|---|
| 415 | |
|---|
| 416 | register ElementInfo |
|---|
| 417 | *next; |
|---|
| 418 | |
|---|
| 419 | assert(list_info != (LinkedListInfo *) NULL); |
|---|
| 420 | assert(list_info->signature == MagickSignature); |
|---|
| 421 | if (list_info->debug != MagickFalse) |
|---|
| 422 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 423 | AcquireSemaphoreInfo(&list_info->semaphore); |
|---|
| 424 | for (next=list_info->head; next != (ElementInfo *) NULL; ) |
|---|
| 425 | { |
|---|
| 426 | if (relinquish_value != (void *(*)(void *)) NULL) |
|---|
| 427 | next->value=relinquish_value(next->value); |
|---|
| 428 | entry=next; |
|---|
| 429 | next=next->next; |
|---|
| 430 | entry=(ElementInfo *) RelinquishMagickMemory(entry); |
|---|
| 431 | } |
|---|
| 432 | list_info->signature=(~MagickSignature); |
|---|
| 433 | RelinquishSemaphoreInfo(list_info->semaphore); |
|---|
| 434 | list_info->semaphore=DestroySemaphoreInfo(list_info->semaphore); |
|---|
| 435 | list_info=(LinkedListInfo *) RelinquishMagickMemory(list_info); |
|---|
| 436 | return(list_info); |
|---|
| 437 | } |
|---|
| 438 | |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | |
|---|
| 444 | |
|---|
| 445 | |
|---|
| 446 | |
|---|
| 447 | |
|---|
| 448 | |
|---|
| 449 | |
|---|
| 450 | |
|---|
| 451 | |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | |
|---|
| 459 | |
|---|
| 460 | |
|---|
| 461 | MagickExport void *GetLastValueInLinkedList(LinkedListInfo *list_info) |
|---|
| 462 | { |
|---|
| 463 | void |
|---|
| 464 | *value; |
|---|
| 465 | |
|---|
| 466 | assert(list_info != (LinkedListInfo *) NULL); |
|---|
| 467 | assert(list_info->signature == MagickSignature); |
|---|
| 468 | if (list_info->debug != MagickFalse) |
|---|
| 469 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 470 | if (list_info->elements == 0) |
|---|
| 471 | return((void *) NULL); |
|---|
| 472 | AcquireSemaphoreInfo(&list_info->semaphore); |
|---|
| 473 | value=list_info->tail->value; |
|---|
| 474 | RelinquishSemaphoreInfo(list_info->semaphore); |
|---|
| 475 | return(value); |
|---|
| 476 | } |
|---|
| 477 | |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | |
|---|
| 484 | |
|---|
| 485 | |
|---|
| 486 | |
|---|
| 487 | |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | |
|---|
| 491 | |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | MagickExport void *GetNextKeyInHashmap(HashmapInfo *hashmap_info) |
|---|
| 501 | { |
|---|
| 502 | LinkedListInfo |
|---|
| 503 | *list_info; |
|---|
| 504 | |
|---|
| 505 | register EntryInfo |
|---|
| 506 | *entry; |
|---|
| 507 | |
|---|
| 508 | void |
|---|
| 509 | *key; |
|---|
| 510 | |
|---|
| 511 | assert(hashmap_info != (HashmapInfo *) NULL); |
|---|
| 512 | assert(hashmap_info->signature == MagickSignature); |
|---|
| 513 | if (hashmap_info->debug != MagickFalse) |
|---|
| 514 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 515 | AcquireSemaphoreInfo(&hashmap_info->semaphore); |
|---|
| 516 | while (hashmap_info->next < hashmap_info->capacity) |
|---|
| 517 | { |
|---|
| 518 | list_info=hashmap_info->map[hashmap_info->next]; |
|---|
| 519 | if (list_info != (LinkedListInfo *) NULL) |
|---|
| 520 | { |
|---|
| 521 | if (hashmap_info->head_of_list == MagickFalse) |
|---|
| 522 | { |
|---|
| 523 | list_info->next=list_info->head; |
|---|
| 524 | hashmap_info->head_of_list=MagickTrue; |
|---|
| 525 | } |
|---|
| 526 | entry=(EntryInfo *) GetNextValueInLinkedList(list_info); |
|---|
| 527 | if (entry != (EntryInfo *) NULL) |
|---|
| 528 | { |
|---|
| 529 | key=entry->key; |
|---|
| 530 | RelinquishSemaphoreInfo(hashmap_info->semaphore); |
|---|
| 531 | return(key); |
|---|
| 532 | } |
|---|
| 533 | hashmap_info->head_of_list=MagickFalse; |
|---|
| 534 | } |
|---|
| 535 | hashmap_info->next++; |
|---|
| 536 | } |
|---|
| 537 | RelinquishSemaphoreInfo(hashmap_info->semaphore); |
|---|
| 538 | return((void *) NULL); |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | |
|---|
| 542 | |
|---|
| 543 | |
|---|
| 544 | |
|---|
| 545 | |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | |
|---|
| 549 | |
|---|
| 550 | |
|---|
| 551 | |
|---|
| 552 | |
|---|
| 553 | |
|---|
| 554 | |
|---|
| 555 | |
|---|
| 556 | |
|---|
| 557 | |
|---|
| 558 | |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | |
|---|
| 563 | MagickExport void *GetNextValueInHashmap(HashmapInfo *hashmap_info) |
|---|
| 564 | { |
|---|
| 565 | LinkedListInfo |
|---|
| 566 | *list_info; |
|---|
| 567 | |
|---|
| 568 | register EntryInfo |
|---|
| 569 | *entry; |
|---|
| 570 | |
|---|
| 571 | void |
|---|
| 572 | *value; |
|---|
| 573 | |
|---|
| 574 | assert(hashmap_info != (HashmapInfo *) NULL); |
|---|
| 575 | assert(hashmap_info->signature == MagickSignature); |
|---|
| 576 | if (hashmap_info->debug != MagickFalse) |
|---|
| 577 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 578 | AcquireSemaphoreInfo(&hashmap_info->semaphore); |
|---|
| 579 | while (hashmap_info->next < hashmap_info->capacity) |
|---|
| 580 | { |
|---|
| 581 | list_info=hashmap_info->map[hashmap_info->next]; |
|---|
| 582 | if (list_info != (LinkedListInfo *) NULL) |
|---|
| 583 | { |
|---|
| 584 | if (hashmap_info->head_of_list == MagickFalse) |
|---|
| 585 | { |
|---|
| 586 | list_info->next=list_info->head; |
|---|
| 587 | hashmap_info->head_of_list=MagickTrue; |
|---|
| 588 | } |
|---|
| 589 | entry=(EntryInfo *) GetNextValueInLinkedList(list_info); |
|---|
| 590 | if (entry != (EntryInfo *) NULL) |
|---|
| 591 | { |
|---|
| 592 | value=entry->value; |
|---|
| 593 | RelinquishSemaphoreInfo(hashmap_info->semaphore); |
|---|
| 594 | return(value); |
|---|
| 595 | } |
|---|
| 596 | hashmap_info->head_of_list=MagickFalse; |
|---|
| 597 | } |
|---|
| 598 | hashmap_info->next++; |
|---|
| 599 | } |
|---|
| 600 | RelinquishSemaphoreInfo(hashmap_info->semaphore); |
|---|
| 601 | return((void *) NULL); |
|---|
| 602 | } |
|---|
| 603 | |
|---|
| 604 | |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | |
|---|
| 608 | |
|---|
| 609 | |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | |
|---|
| 616 | |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | |
|---|
| 620 | |
|---|
| 621 | |
|---|
| 622 | |
|---|
| 623 | |
|---|
| 624 | |
|---|
| 625 | |
|---|
| 626 | MagickExport void *GetNextValueInLinkedList(LinkedListInfo *list_info) |
|---|
| 627 | { |
|---|
| 628 | void |
|---|
| 629 | *value; |
|---|
| 630 | |
|---|
| 631 | assert(list_info != (LinkedListInfo *) NULL); |
|---|
| 632 | assert(list_info->signature == MagickSignature); |
|---|
| 633 | if (list_info->debug != MagickFalse) |
|---|
| 634 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 635 | if (list_info->next == (ElementInfo *) NULL) |
|---|
| 636 | return((void *) NULL); |
|---|
| 637 | AcquireSemaphoreInfo(&list_info->semaphore); |
|---|
| 638 | value=list_info->next->value; |
|---|
| 639 | list_info->next=list_info->next->next; |
|---|
| 640 | RelinquishSemaphoreInfo(list_info->semaphore); |
|---|
| 641 | return(value); |
|---|
| 642 | } |
|---|
| 643 | |
|---|
| 644 | |
|---|
| 645 | |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | |
|---|
| 649 | |
|---|
| 650 | |
|---|
| 651 | |
|---|
| 652 | |
|---|
| 653 | |
|---|
| 654 | |
|---|
| 655 | |
|---|
| 656 | |
|---|
| 657 | |
|---|
| 658 | |
|---|
| 659 | |
|---|
| 660 | |
|---|
| 661 | |
|---|
| 662 | |
|---|
| 663 | |
|---|
| 664 | |
|---|
| 665 | |
|---|
| 666 | MagickExport unsigned long GetNumberOfEntriesInHashmap( |
|---|
| 667 | const HashmapInfo *hashmap_info) |
|---|
| 668 | { |
|---|
| 669 | assert(hashmap_info != (HashmapInfo *) NULL); |
|---|
| 670 | assert(hashmap_info->signature == MagickSignature); |
|---|
| 671 | if (hashmap_info->debug != MagickFalse) |
|---|
| 672 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 673 | return(hashmap_info->entries); |
|---|
| 674 | } |
|---|
| 675 | |
|---|
| 676 | |
|---|
| 677 | |
|---|
| 678 | |
|---|
| 679 | |
|---|
| 680 | |
|---|
| 681 | |
|---|
| 682 | |
|---|
| 683 | |
|---|
| 684 | |
|---|
| 685 | |
|---|
| 686 | |
|---|
| 687 | |
|---|
| 688 | |
|---|
| 689 | |
|---|
| 690 | |
|---|
| 691 | |
|---|
| 692 | |
|---|
| 693 | |
|---|
| 694 | |
|---|
| 695 | |
|---|
| 696 | |
|---|
| 697 | |
|---|
| 698 | |
|---|
| 699 | |
|---|
| 700 | MagickExport unsigned long GetNumberOfElementsInLinkedList( |
|---|
| 701 | const LinkedListInfo *list_info) |
|---|
| 702 | { |
|---|
| 703 | assert(list_info != (LinkedListInfo *) NULL); |
|---|
| 704 | assert(list_info->signature == MagickSignature); |
|---|
| 705 | if (list_info->debug != MagickFalse) |
|---|
| 706 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 707 | return(list_info->elements); |
|---|
| 708 | } |
|---|
| 709 | |
|---|
| 710 | |
|---|
| 711 | |
|---|
| 712 | |
|---|
| 713 | |
|---|
| 714 | |
|---|
| 715 | |
|---|
| 716 | |
|---|
| 717 | |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | |
|---|
| 723 | |
|---|
| 724 | |
|---|
| 725 | |
|---|
| 726 | |
|---|
| 727 | |
|---|
| 728 | |
|---|
| 729 | |
|---|
| 730 | |
|---|
| 731 | |
|---|
| 732 | |
|---|
| 733 | |
|---|
| 734 | MagickExport void *GetValueFromHashmap(HashmapInfo *hashmap_info, |
|---|
| 735 | const void *key) |
|---|
| 736 | { |
|---|
| 737 | LinkedListInfo |
|---|
| 738 | *list_info; |
|---|
| 739 | |
|---|
| 740 | register EntryInfo |
|---|
| 741 | *entry; |
|---|
| 742 | |
|---|
| 743 | size_t |
|---|
| 744 | hash; |
|---|
| 745 | |
|---|
| 746 | void |
|---|
| 747 | *value; |
|---|
| 748 | |
|---|
| 749 | assert(hashmap_info != (HashmapInfo *) NULL); |
|---|
| 750 | assert(hashmap_info->signature == MagickSignature); |
|---|
| 751 | if (hashmap_info->debug != MagickFalse) |
|---|
| 752 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 753 | if (key == (const void *) NULL) |
|---|
| 754 | return((void *) NULL); |
|---|
| 755 | AcquireSemaphoreInfo(&hashmap_info->semaphore); |
|---|
| 756 | hash=hashmap_info->hash(key); |
|---|
| 757 | list_info=hashmap_info->map[hash % hashmap_info->capacity]; |
|---|
| 758 | if (list_info != (LinkedListInfo *) NULL) |
|---|
| 759 | { |
|---|
| 760 | list_info->next=list_info->head; |
|---|
| 761 | entry=(EntryInfo *) GetNextValueInLinkedList(list_info); |
|---|
| 762 | while (entry != (EntryInfo *) NULL) |
|---|
| 763 | { |
|---|
| 764 | if (entry->hash == hash) |
|---|
| 765 | { |
|---|
| 766 | MagickBooleanType |
|---|
| 767 | compare; |
|---|
| 768 | |
|---|
| 769 | compare=MagickTrue; |
|---|
| 770 | if (hashmap_info->compare != |
|---|
| 771 | (MagickBooleanType (*)(const void *,const void *)) NULL) |
|---|
| 772 | compare=hashmap_info->compare(key,entry->key); |
|---|
| 773 | if (compare == MagickTrue) |
|---|
| 774 | { |
|---|
| 775 | value=entry->value; |
|---|
| 776 | RelinquishSemaphoreInfo(hashmap_info->semaphore); |
|---|
| 777 | return(value); |
|---|
| 778 | } |
|---|
| 779 | } |
|---|
| 780 | entry=(EntryInfo *) GetNextValueInLinkedList(list_info); |
|---|
| 781 | } |
|---|
| 782 | } |
|---|
| 783 | RelinquishSemaphoreInfo(hashmap_info->semaphore); |
|---|
| 784 | return((void *) NULL); |
|---|
| 785 | } |
|---|
| 786 | |
|---|
| 787 | |
|---|
| 788 | |
|---|
| 789 | |
|---|
| 790 | |
|---|
| 791 | |
|---|
| 792 | |
|---|
| 793 | |
|---|
| 794 | |
|---|
| 795 | |
|---|
| 796 | |
|---|
| 797 | |
|---|
| 798 | |
|---|
| 799 | |
|---|
| 800 | |
|---|
| 801 | |
|---|
| 802 | |
|---|
| 803 | |
|---|
| 804 | |
|---|
| 805 | |
|---|
| 806 | |
|---|
| 807 | |
|---|
| 808 | |
|---|
| 809 | |
|---|
| 810 | |
|---|
| 811 | |
|---|
| 812 | |
|---|
| 813 | MagickExport void *GetValueFromLinkedList(LinkedListInfo *list_info, |
|---|
| 814 | const unsigned long index) |
|---|
| 815 | { |
|---|
| 816 | register ElementInfo |
|---|
| 817 | *next; |
|---|
| 818 | |
|---|
| 819 | register long |
|---|
| 820 | i; |
|---|
| 821 | |
|---|
| 822 | void |
|---|
| 823 | *value; |
|---|
| 824 | |
|---|
| 825 | assert(list_info != (LinkedListInfo *) NULL); |
|---|
| 826 | assert(list_info->signature == MagickSignature); |
|---|
| 827 | if (list_info->debug != MagickFalse) |
|---|
| 828 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 829 | if (index >= list_info->elements) |
|---|
| 830 | return((void *) NULL); |
|---|
| 831 | AcquireSemaphoreInfo(&list_info->semaphore); |
|---|
| 832 | if (index == 0) |
|---|
| 833 | { |
|---|
| 834 | value=list_info->head->value; |
|---|
| 835 | RelinquishSemaphoreInfo(list_info->semaphore); |
|---|
| 836 | return(value); |
|---|
| 837 | } |
|---|
| 838 | if (index == (list_info->elements-1)) |
|---|
| 839 | { |
|---|
| 840 | value=list_info->tail->value; |
|---|
| 841 | RelinquishSemaphoreInfo(list_info->semaphore); |
|---|
| 842 | return(value); |
|---|
| 843 | } |
|---|
| 844 | next=list_info->head; |
|---|
| 845 | for (i=0; i < (long) index; i++) |
|---|
| 846 | next=next->next; |
|---|
| 847 | value=next->value; |
|---|
| 848 | RelinquishSemaphoreInfo(list_info->semaphore); |
|---|
| 849 | return(value); |
|---|
| 850 | } |
|---|
| 851 | |
|---|
| 852 | |
|---|
| 853 | |
|---|
| 854 | |
|---|
| 855 | |
|---|
| 856 | |
|---|
| 857 | |
|---|
| 858 | |
|---|
| 859 | |
|---|
| 860 | |
|---|
| 861 | |
|---|
| 862 | |
|---|
| 863 | |
|---|
| 864 | |
|---|
| 865 | |
|---|
| 866 | |
|---|
| 867 | |
|---|
| 868 | |
|---|
| 869 | |
|---|
| 870 | |
|---|
| 871 | |
|---|
| 872 | |
|---|
| 873 | |
|---|
| 874 | |
|---|
| 875 | MagickExport size_t HashPointerType(const void *pointer) |
|---|
| 876 | { |
|---|
| 877 | size_t |
|---|
| 878 | hash; |
|---|
| 879 | |
|---|
| 880 | hash=(size_t) pointer; |
|---|
| 881 | hash+=(~(hash << 9)); |
|---|
| 882 | hash^=(hash >> 14); |
|---|
| 883 | hash+=(hash << 4); |
|---|
| 884 | hash^=(hash >> 10); |
|---|
| 885 | return(hash); |
|---|
| 886 | } |
|---|
| 887 | |
|---|
| 888 | |
|---|
| 889 | |
|---|
| 890 | |
|---|
| 891 | |
|---|
| 892 | |
|---|
| 893 | |
|---|
| 894 | |
|---|
| 895 | |
|---|
| 896 | |
|---|
| 897 | |
|---|
| 898 | |
|---|
| 899 | |
|---|
| 900 | |
|---|
| 901 | |
|---|
| 902 | |
|---|
| 903 | |
|---|
| 904 | |
|---|
| 905 | |
|---|
| 906 | |
|---|
| 907 | |
|---|
| 908 | |
|---|
| 909 | |
|---|
| 910 | |
|---|
| 911 | MagickExport size_t HashStringType(const void *string) |
|---|
| 912 | { |
|---|
| 913 | register long |
|---|
| 914 | i; |
|---|
| 915 | |
|---|
| 916 | SignatureInfo |
|---|
| 917 | signature_info; |
|---|
| 918 | |
|---|
| 919 | size_t |
|---|
| 920 | hash; |
|---|
| 921 | |
|---|
| 922 | GetSignatureInfo(&signature_info); |
|---|
| 923 | UpdateSignature(&signature_info,(const unsigned char *) string, |
|---|
| 924 | strlen((const char *) string)); |
|---|
| 925 | FinalizeSignature(&signature_info); |
|---|
| 926 | hash=0; |
|---|
| 927 | for (i=0; i < 8; i++) |
|---|
| 928 | hash^=signature_info.digest[i]; |
|---|
| 929 | return(hash); |
|---|
| 930 | } |
|---|
| 931 | |
|---|
| 932 | |
|---|
| 933 | |
|---|
| 934 | |
|---|
| 935 | |
|---|
| 936 | |
|---|
| 937 | |
|---|
| 938 | |
|---|
| 939 | |
|---|
| 940 | |
|---|
| 941 | |
|---|
| 942 | |
|---|
| 943 | |
|---|
| 944 | |
|---|
| 945 | |
|---|
| 946 | |
|---|
| 947 | |
|---|
| 948 | |
|---|
| 949 | |
|---|
| 950 | |
|---|
| 951 | |
|---|
| 952 | |
|---|
| 953 | |
|---|
| 954 | |
|---|
| 955 | MagickExport size_t HashStringInfoType(const void *string) |
|---|
| 956 | { |
|---|