]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/hashmap.c
(no commit message)
[imagemagick] / MagickCore / hashmap.c
index ce0afb09bef91a2ca686d31c029b03198cb749b2..28bbad6f3549af4b4826335dc5c0b65b3ba975b5 100644 (file)
 %                  MagickCore Hash-map and Linked-list Methods                %
 %                                                                             %
 %                              Software Design                                %
-%                                John Cristy                                  %
+%                                   Cristy                                    %
 %                               December 2002                                 %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -84,9 +84,6 @@ struct _LinkedListInfo
     *tail,
     *next;
 
-  MagickBooleanType
-    debug;
-
   SemaphoreInfo
     *semaphore;
 
@@ -117,9 +114,6 @@ struct _HashmapInfo
   LinkedListInfo
     **map;
 
-  MagickBooleanType
-    debug;
-
   SemaphoreInfo
     *semaphore;
 
@@ -160,9 +154,6 @@ MagickExport MagickBooleanType AppendValueToLinkedList(
 
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  list_info->debug=IsEventLogging();
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if (list_info->elements == list_info->capacity)
     return(MagickFalse);
   next=(ElementInfo *) AcquireMagickMemory(sizeof(*next));
@@ -220,8 +211,6 @@ MagickExport void ClearLinkedList(LinkedListInfo *list_info,
 
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   LockSemaphoreInfo(list_info->semaphore);
   next=list_info->head;
   while (next != (ElementInfo *) NULL)
@@ -274,7 +263,7 @@ MagickExport MagickBooleanType CompareHashmapString(const void *target,
 
   p=(const char *) target;
   q=(const char *) source;
-  return(LocaleCompare(p,q) == 0 ? MagickTrue : MagickFalse);
+  return(IsMagickTrue(LocaleCompare(p,q)));
 }
 \f
 /*
@@ -306,13 +295,8 @@ MagickExport MagickBooleanType CompareHashmapString(const void *target,
 MagickExport MagickBooleanType CompareHashmapStringInfo(const void *target,
   const void *source)
 {
-  const StringInfo
-    *p,
-    *q;
-
-  p=(const StringInfo *) target;
-  q=(const StringInfo *) source;
-  return(CompareStringInfo(p,q) == 0 ? MagickTrue : MagickFalse);
+  return(IsMagickTrue(LocaleCompare((const char *)target,
+           (const char *)source)));
 }
 \f
 /*
@@ -350,8 +334,6 @@ MagickExport HashmapInfo *DestroyHashmap(HashmapInfo *hashmap_info)
 
   assert(hashmap_info != (HashmapInfo *) NULL);
   assert(hashmap_info->signature == MagickSignature);
-  if (hashmap_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   LockSemaphoreInfo(hashmap_info->semaphore);
   for (i=0; i < (ssize_t) hashmap_info->capacity; i++)
   {
@@ -376,7 +358,7 @@ MagickExport HashmapInfo *DestroyHashmap(HashmapInfo *hashmap_info)
     hashmap_info->map);
   hashmap_info->signature=(~MagickSignature);
   UnlockSemaphoreInfo(hashmap_info->semaphore);
-  DestroySemaphoreInfo(&hashmap_info->semaphore);
+  RelinquishSemaphoreInfo(&hashmap_info->semaphore);
   hashmap_info=(HashmapInfo *) RelinquishMagickMemory(hashmap_info);
   return(hashmap_info);
 }
@@ -418,8 +400,6 @@ MagickExport LinkedListInfo *DestroyLinkedList(LinkedListInfo *list_info,
 
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   LockSemaphoreInfo(list_info->semaphore);
   for (next=list_info->head; next != (ElementInfo *) NULL; )
   {
@@ -431,7 +411,7 @@ MagickExport LinkedListInfo *DestroyLinkedList(LinkedListInfo *list_info,
   }
   list_info->signature=(~MagickSignature);
   UnlockSemaphoreInfo(list_info->semaphore);
-  DestroySemaphoreInfo(&list_info->semaphore);
+  RelinquishSemaphoreInfo(&list_info->semaphore);
   list_info=(LinkedListInfo *) RelinquishMagickMemory(list_info);
   return(list_info);
 }
@@ -465,8 +445,6 @@ MagickExport void *GetLastValueInLinkedList(LinkedListInfo *list_info)
 
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if (list_info->elements == 0)
     return((void *) NULL);
   LockSemaphoreInfo(list_info->semaphore);
@@ -510,15 +488,13 @@ MagickExport void *GetNextKeyInHashmap(HashmapInfo *hashmap_info)
 
   assert(hashmap_info != (HashmapInfo *) NULL);
   assert(hashmap_info->signature == MagickSignature);
-  if (hashmap_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   LockSemaphoreInfo(hashmap_info->semaphore);
   while (hashmap_info->next < hashmap_info->capacity)
   {
     list_info=hashmap_info->map[hashmap_info->next];
     if (list_info != (LinkedListInfo *) NULL)
       {
-        if (hashmap_info->head_of_list == MagickFalse)
+        if (IfMagickFalse(hashmap_info->head_of_list))
           {
             list_info->next=list_info->head;
             hashmap_info->head_of_list=MagickTrue;
@@ -573,15 +549,13 @@ MagickExport void *GetNextValueInHashmap(HashmapInfo *hashmap_info)
 
   assert(hashmap_info != (HashmapInfo *) NULL);
   assert(hashmap_info->signature == MagickSignature);
-  if (hashmap_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   LockSemaphoreInfo(hashmap_info->semaphore);
   while (hashmap_info->next < hashmap_info->capacity)
   {
     list_info=hashmap_info->map[hashmap_info->next];
     if (list_info != (LinkedListInfo *) NULL)
       {
-        if (hashmap_info->head_of_list == MagickFalse)
+        if (IfMagickFalse(hashmap_info->head_of_list))
           {
             list_info->next=list_info->head;
             hashmap_info->head_of_list=MagickTrue;
@@ -630,8 +604,6 @@ MagickExport void *GetNextValueInLinkedList(LinkedListInfo *list_info)
 
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   LockSemaphoreInfo(list_info->semaphore);
   if (list_info->next == (ElementInfo *) NULL)
     {
@@ -671,8 +643,6 @@ MagickExport size_t GetNumberOfEntriesInHashmap(
 {
   assert(hashmap_info != (HashmapInfo *) NULL);
   assert(hashmap_info->signature == MagickSignature);
-  if (hashmap_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   return(hashmap_info->entries);
 }
 \f
@@ -705,8 +675,6 @@ MagickExport size_t GetNumberOfElementsInLinkedList(
 {
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   return(list_info->elements);
 }
 \f
@@ -751,8 +719,6 @@ MagickExport void *GetValueFromHashmap(HashmapInfo *hashmap_info,
 
   assert(hashmap_info != (HashmapInfo *) NULL);
   assert(hashmap_info->signature == MagickSignature);
-  if (hashmap_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if (key == (const void *) NULL)
     return((void *) NULL);
   LockSemaphoreInfo(hashmap_info->semaphore);
@@ -773,7 +739,7 @@ MagickExport void *GetValueFromHashmap(HashmapInfo *hashmap_info,
             if (hashmap_info->compare !=
                 (MagickBooleanType (*)(const void *,const void *)) NULL)
               compare=hashmap_info->compare(key,entry->key);
-            if (compare == MagickTrue)
+            if (IfMagickTrue(compare))
               {
                 value=entry->value;
                 UnlockSemaphoreInfo(hashmap_info->semaphore);
@@ -827,8 +793,6 @@ MagickExport void *GetValueFromLinkedList(LinkedListInfo *list_info,
 
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if (index >= list_info->elements)
     return((void *) NULL);
   LockSemaphoreInfo(list_info->semaphore);
@@ -1028,8 +992,6 @@ MagickExport MagickBooleanType InsertValueInLinkedList(
 
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if (value == (const void *) NULL)
     return(MagickFalse);
   if ((index > list_info->elements) ||
@@ -1135,8 +1097,6 @@ MagickExport MagickBooleanType InsertValueInSortedLinkedList(
 
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if ((compare == (int (*)(const void *,const void *)) NULL) ||
       (value == (const void *) NULL))
     return(MagickFalse);
@@ -1211,9 +1171,7 @@ MagickExport MagickBooleanType IsHashmapEmpty(const HashmapInfo *hashmap_info)
 {
   assert(hashmap_info != (HashmapInfo *) NULL);
   assert(hashmap_info->signature == MagickSignature);
-  if (hashmap_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
-  return(hashmap_info->entries == 0 ? MagickTrue : MagickFalse);
+  return(IsMagickTrue(hashmap_info->entries == 0));
 }
 \f
 /*
@@ -1243,9 +1201,7 @@ MagickExport MagickBooleanType IsLinkedListEmpty(
 {
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
-  return(list_info->elements == 0 ? MagickTrue : MagickFalse);
+  return(IsMagickTrue(list_info->elements == 0));
 }
 \f
 /*
@@ -1284,8 +1240,6 @@ MagickExport MagickBooleanType LinkedListToArray(LinkedListInfo *list_info,
 
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if (array == (void **) NULL)
     return(MagickFalse);
   LockSemaphoreInfo(list_info->semaphore);
@@ -1372,8 +1326,7 @@ MagickExport HashmapInfo *NewHashmap(const size_t capacity,
     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
   (void) ResetMagickMemory(hashmap_info->map,0,(size_t) capacity*
     sizeof(*hashmap_info->map));
-  hashmap_info->debug=IsEventLogging();
-  hashmap_info->semaphore=AllocateSemaphoreInfo();
+  hashmap_info->semaphore=AcquireSemaphoreInfo();
   hashmap_info->signature=MagickSignature;
   return(hashmap_info);
 }
@@ -1415,8 +1368,7 @@ MagickExport LinkedListInfo *NewLinkedList(const size_t capacity)
   list_info->head=(ElementInfo *) NULL;
   list_info->tail=(ElementInfo *) NULL;
   list_info->next=(ElementInfo *) NULL;
-  list_info->debug=MagickFalse;
-  list_info->semaphore=AllocateSemaphoreInfo();
+  list_info->semaphore=AcquireSemaphoreInfo();
   list_info->signature=MagickSignature;
   return(list_info);
 }
@@ -1522,7 +1474,7 @@ static MagickBooleanType IncreaseHashmapCapacity(HashmapInfo *hashmap_info)
     }
     list_info->signature=(~MagickSignature);
     UnlockSemaphoreInfo(list_info->semaphore);
-    DestroySemaphoreInfo(&list_info->semaphore);
+    RelinquishSemaphoreInfo(&list_info->semaphore);
     list_info=(LinkedListInfo *) RelinquishMagickMemory(list_info);
   }
   hashmap_info->map=(LinkedListInfo **) RelinquishMagickMemory(
@@ -1547,8 +1499,6 @@ MagickExport MagickBooleanType PutEntryInHashmap(HashmapInfo *hashmap_info,
 
   assert(hashmap_info != (HashmapInfo *) NULL);
   assert(hashmap_info->signature == MagickSignature);
-  if (hashmap_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if ((key == (void *) NULL) || (value == (void *) NULL))
     return(MagickFalse);
   next=(EntryInfo *) AcquireMagickMemory(sizeof(*next));
@@ -1579,7 +1529,7 @@ MagickExport MagickBooleanType PutEntryInHashmap(HashmapInfo *hashmap_info,
             if (hashmap_info->compare !=
                 (MagickBooleanType (*)(const void *,const void *)) NULL)
               compare=hashmap_info->compare(key,entry->key);
-            if (compare == MagickTrue)
+            if( IfMagickTrue(compare) )
               {
                 (void) RemoveElementFromLinkedList(list_info,i);
                 if (hashmap_info->relinquish_key != (void *(*)(void *)) NULL)
@@ -1593,14 +1543,14 @@ MagickExport MagickBooleanType PutEntryInHashmap(HashmapInfo *hashmap_info,
         entry=(EntryInfo *) GetNextValueInLinkedList(list_info);
       }
     }
-  if (InsertValueInLinkedList(list_info,0,next) == MagickFalse)
+  if (IfMagickFalse(InsertValueInLinkedList(list_info,0,next)))
     {
       next=(EntryInfo *) RelinquishMagickMemory(next);
       UnlockSemaphoreInfo(hashmap_info->semaphore);
       return(MagickFalse);
     }
   if (list_info->elements >= (hashmap_info->capacity-1))
-    if (IncreaseHashmapCapacity(hashmap_info) == MagickFalse)
+    if (IfMagickFalse(IncreaseHashmapCapacity(hashmap_info)))
       {
         UnlockSemaphoreInfo(hashmap_info->semaphore);
         return(MagickFalse);
@@ -1644,8 +1594,6 @@ MagickExport void *RemoveElementByValueFromLinkedList(LinkedListInfo *list_info,
 
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if ((list_info->elements == 0) || (value == (const void *) NULL))
     return((void *) NULL);
   LockSemaphoreInfo(list_info->semaphore);
@@ -1724,8 +1672,6 @@ MagickExport void *RemoveElementFromLinkedList(LinkedListInfo *list_info,
 
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if (index >= list_info->elements)
     return((void *) NULL);
   LockSemaphoreInfo(list_info->semaphore);
@@ -1804,8 +1750,6 @@ MagickExport void *RemoveEntryFromHashmap(HashmapInfo *hashmap_info,
 
   assert(hashmap_info != (HashmapInfo *) NULL);
   assert(hashmap_info->signature == MagickSignature);
-  if (hashmap_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if (key == (const void *) NULL)
     return((void *) NULL);
   LockSemaphoreInfo(hashmap_info->semaphore);
@@ -1826,7 +1770,7 @@ MagickExport void *RemoveEntryFromHashmap(HashmapInfo *hashmap_info,
             if (hashmap_info->compare !=
                 (MagickBooleanType (*)(const void *,const void *)) NULL)
               compare=hashmap_info->compare(key,entry->key);
-            if (compare == MagickTrue)
+            if( IfMagickTrue(compare) )
               {
                 entry=(EntryInfo *) RemoveElementFromLinkedList(list_info,i);
                 if (entry == (EntryInfo *) NULL)
@@ -1880,8 +1824,6 @@ MagickExport void *RemoveLastElementFromLinkedList(LinkedListInfo *list_info)
 
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if (list_info->elements == 0)
     return((void *) NULL);
   LockSemaphoreInfo(list_info->semaphore);
@@ -1938,8 +1880,6 @@ MagickExport void ResetHashmapIterator(HashmapInfo *hashmap_info)
 {
   assert(hashmap_info != (HashmapInfo *) NULL);
   assert(hashmap_info->signature == MagickSignature);
-  if (hashmap_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   LockSemaphoreInfo(hashmap_info->semaphore);
   hashmap_info->next=0;
   hashmap_info->head_of_list=MagickFalse;
@@ -1974,8 +1914,6 @@ MagickExport void ResetLinkedListIterator(LinkedListInfo *list_info)
 {
   assert(list_info != (LinkedListInfo *) NULL);
   assert(list_info->signature == MagickSignature);
-  if (list_info->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   LockSemaphoreInfo(list_info->semaphore);
   list_info->next=list_info->head;
   UnlockSemaphoreInfo(list_info->semaphore);