Good day and welcome to the FIRM XMALLOC*() macros. These macros are provided for...
[libfirm] / ir / adt / hashset.c
index b02acf3..d0a3e7e 100644 (file)
@@ -95,7 +95,7 @@
 
 #ifndef Alloc
 #include "xmalloc.h"
-#define Alloc(size)    (HashSetEntry*) xmalloc((size) * sizeof(HashSetEntry))
+#define Alloc(size) XMALLOCN(HashSetEntry, (size))
 #define Free(ptr)      free(ptr)
 #endif /* Alloc */
 
 #ifndef hashset_remove_iterator
 #error You have to redefine hashset_remove_iterator
 #endif
-#endif NO_ITERATOR
+#endif
 
 /**
  * Returns the number of elements in the hashset
@@ -266,6 +266,19 @@ InsertReturnValue insert_nogrow(HashSet *self, KeyType key)
        }
 }
 
+/**
+ * calculate shrink and enlarge limits
+ * @internal
+ */
+static INLINE
+void reset_thresholds(HashSet *self)
+{
+       self->enlarge_threshold = (size_t) HT_OCCUPANCY_FLT(self->num_buckets);
+       self->shrink_threshold  = (size_t) HT_EMPTY_FLT(self->num_buckets);
+       self->consider_shrink   = 0;
+}
+
+#ifndef HAVE_OWN_RESIZE
 /**
  * Inserts an element into a hashset under the assumption that the hashset
  * contains no deleted entries and the element doesn't exist in the hashset yet.
@@ -309,18 +322,6 @@ void insert_new(HashSet *self, unsigned hash, ValueType value)
        }
 }
 
-/**
- * calculate shrink and enlarge limits
- * @internal
- */
-static INLINE
-void reset_thresholds(HashSet *self)
-{
-       self->enlarge_threshold = (size_t) HT_OCCUPANCY_FLT(self->num_buckets);
-       self->shrink_threshold  = (size_t) HT_EMPTY_FLT(self->num_buckets);
-       self->consider_shrink   = 0;
-}
-
 /**
  * Resize the hashset
  * @internal
@@ -359,6 +360,12 @@ void resize(HashSet *self, size_t new_size)
        /* now we can free the old array */
        Free(old_entries);
 }
+#else
+
+/* resize must be defined outside */
+static INLINE void resize(HashSet *self, size_t new_size);
+
+#endif
 
 /**
  * grow the hashset if adding 1 more elements would make it too crowded