From: Arnaud Giersch Date: Mon, 13 Nov 2017 12:54:20 +0000 (+0100) Subject: Kill now unused xbt_heap. X-Git-Tag: v3.18~242^2~44 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/01dbe798813412d771e196798299c082bedc1dbb?ds=sidebyside Kill now unused xbt_heap. --- diff --git a/.gitignore b/.gitignore index 62d7e7d8ee..7c78757723 100644 --- a/.gitignore +++ b/.gitignore @@ -1077,7 +1077,6 @@ teshsuite/surf/lmm_usage/lmm_usage teshsuite/surf/maxmin_bench/maxmin_bench teshsuite/surf/surf_usage/surf_usage teshsuite/surf/surf_usage2/surf_usage2 -teshsuite/xbt/heap_bench/heap_bench teshsuite/xbt/log_large/log_large teshsuite/xbt/log_usage/log_usage teshsuite/xbt/mallocator/mallocator diff --git a/ChangeLog b/ChangeLog index 4930ddf787..ab45e94f52 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,7 +13,8 @@ SimGrid (3.18) NOT RELEASED YET (target: December 24 2017) - Removed unused functions: - xbt/file.h: xbt_basename(), xbt_dirname(), xbt_getline() - xbt/str.h: xbt_str_join() - + - xbt/heap.h: use std::priority_queue or boost::heap instead + XML - Remove the undocumented/untested tag diff --git a/doc/doxygen/module-xbt.doc b/doc/doxygen/module-xbt.doc index 395f744cd4..d2ce9de344 100644 --- a/doc/doxygen/module-xbt.doc +++ b/doc/doxygen/module-xbt.doc @@ -17,7 +17,6 @@ - \ref XBT_dynar - \ref XBT_dict - \ref XBT_swag - - \ref XBT_heap - \ref XBT_misc - \ref XBT_graph @@ -66,7 +65,6 @@ /** @defgroup XBT_dynar Dynar: generic dynamic array */ /** @defgroup XBT_dict Dict: generic dictionnary */ /** @defgroup XBT_swag Swag: O(1) set datatype */ - /** @defgroup XBT_heap Heap: generic heap data structure */ /** @} */ diff --git a/doc/doxygen/uhood_arch.doc b/doc/doxygen/uhood_arch.doc index 9c0e26582e..e75eb7815a 100644 --- a/doc/doxygen/uhood_arch.doc +++ b/doc/doxygen/uhood_arch.doc @@ -75,7 +75,7 @@ It is a portable library providing some grounding features such as \ref XBT_log, \ref XBT_ex and \ref XBT_config. XBT also encompass the following convenient C data structures: -\ref XBT_dynar, \ref XBT_dict, \ref XBT_heap, and +\ref XBT_dynar, \ref XBT_dict, and \ref XBT_swag. The code is being migrated in C++ so you should probably want to use standard C++ containers instead of them if possible. diff --git a/include/xbt.h b/include/xbt.h index 9dd4cafead..5890af37f9 100644 --- a/include/xbt.h +++ b/include/xbt.h @@ -22,7 +22,6 @@ #include #include #include -#include #include #include diff --git a/include/xbt/heap.h b/include/xbt/heap.h deleted file mode 100644 index 27c2a81a58..0000000000 --- a/include/xbt/heap.h +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright (c) 2004-2007, 2009-2011, 2013-2017. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#ifndef XBT_HEAP_H -#define XBT_HEAP_H - -#include "xbt/misc.h" -#include "xbt/dynar.h" /* void_f_pvoid_t */ - -SG_BEGIN_DECL() - -/** @addtogroup XBT_heap - * @brief This section describes the API to generic heap with O(log(n)) access. - * - * @deprecated If you are using C++ you might want to use `std::priority_queue` - * instead. - * - * @{ - */ -/* @brief heap datatype */ -typedef struct xbt_heap *xbt_heap_t; - -XBT_PUBLIC(xbt_heap_t) xbt_heap_new(int init_size, void_f_pvoid_t const free_func); -XBT_PUBLIC(void) xbt_heap_free(xbt_heap_t H); -XBT_PUBLIC(int) xbt_heap_size(xbt_heap_t H); - -XBT_PUBLIC(void) xbt_heap_push(xbt_heap_t H, void *content, double key); -XBT_PUBLIC(void *) xbt_heap_pop(xbt_heap_t H); -XBT_PUBLIC(void *) xbt_heap_rm_elm(xbt_heap_t H, void *content, double key); - -XBT_PUBLIC(double) xbt_heap_maxkey(xbt_heap_t H); -XBT_PUBLIC(void *) xbt_heap_maxcontent(xbt_heap_t H); -XBT_PUBLIC(void) xbt_heap_set_update_callback(xbt_heap_t H, void (*update_callback) (void*, int)); -XBT_PUBLIC(void *) xbt_heap_remove(xbt_heap_t H, int i); -XBT_PUBLIC(void ) xbt_heap_update(xbt_heap_t H, int i, double key); - -/* @} */ -SG_END_DECL() - -#endif /* _XBT_HEAP_H */ diff --git a/src/xbt/heap.c b/src/xbt/heap.c deleted file mode 100644 index db2431e707..0000000000 --- a/src/xbt/heap.c +++ /dev/null @@ -1,282 +0,0 @@ -/* a generic and efficient heap */ - -/* Copyright (c) 2004-2005, 2007-2017. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "xbt/sysdep.h" -#include "xbt/log.h" -#include "heap_private.h" - -#include -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_heap, xbt, "Heap"); - -static void xbt_heap_max_heapify(xbt_heap_t H, int i); -static void xbt_heap_increase_key(xbt_heap_t H, int i); - -/** @addtogroup XBT_heap - * \brief This section describes the API to generic heap with O(log(n)) access. - */ - -/** - * @brief Creates a new heap. - * \param init_size initial size of the heap - * \param free_func function to call on each element when you want to free the whole heap (or NULL if nothing to do). - * - * Creates a new heap. - */ -inline xbt_heap_t xbt_heap_new(int init_size, void_f_pvoid_t const free_func) -{ - xbt_heap_t H = xbt_new0(struct xbt_heap, 1); - H->size = init_size; - H->count = 0; - H->items = (xbt_heap_item_t) xbt_new0(struct xbt_heap_item, init_size); - H->free = free_func; - return H; -} - -/** - * @brief Set the update callback function. - * @param H the heap we're working on - * \param update_callback function to call on each element to update its index when needed. - */ -inline void xbt_heap_set_update_callback(xbt_heap_t H, void (*update_callback) (void*, int)) -{ - H->update_callback = update_callback; -} - -/** - * @brief kilkil a heap and its content - * @param H poor victim - */ -void xbt_heap_free(xbt_heap_t H) -{ - if (!H) - return; - - if (H->free) - for (int i = 0; i < H->count; i++) - H->free(H->items[i].content); - free(H->items); - free(H); -} - -/** - * @brief returns the number of elements in the heap - * @param H the heap we're working on - * @return the number of elements in the heap - */ -inline int xbt_heap_size(xbt_heap_t H) -{ - return (H->count); -} - -/** - * @brief Add an element into the heap. - * \param H the heap we're working on - * \param content the object you want to add to the heap - * \param key the key associated to this object - * - * The element with the smallest key is automatically moved at the top of the heap. - */ -void xbt_heap_push(xbt_heap_t H, void *content, double key) -{ - H->count += 1; - int count = H->count; - - int size = H->size; - xbt_heap_item_t item; - - if (count > size) { - H->size = (size << 1) + 1; - H->items = (void *) xbt_realloc(H->items, (H->size) * sizeof(struct xbt_heap_item)); - xbt_assert(H->items != NULL); - } - - item = &(H->items[count - 1]); - item->key = key; - item->content = content; - xbt_heap_increase_key(H, count - 1); - XBT_DEBUG("Heap has now %d elements and max elem is %g",xbt_heap_size(H),xbt_heap_maxkey(H)); -} - -/** - * @brief Extracts from the heap and returns the element with the smallest key. - * \param H the heap we're working on - * \return the element with the smallest key - * - * Extracts from the heap and returns the element with the smallest key. The element with the next smallest key is - * automatically moved at the top of the heap. - */ -void *xbt_heap_pop(xbt_heap_t H) -{ - xbt_heap_item_t items = H->items; - int size = H->size; - void *max; - - if (H->count == 0) - return NULL; - - XBT_DEBUG("Heap has %d elements before extraction and max elem was %g",xbt_heap_size(H),xbt_heap_maxkey(H)); - - max = CONTENT(H, 0); - - items[0] = items[(H->count) - 1]; - (H->count)--; - xbt_heap_max_heapify(H,0); - if (H->count < size >> 2 && size > 16) { - size = (size >> 1) + 1; - H->items = (void *) xbt_realloc(items, size * sizeof(struct xbt_heap_item)); - H->size = size; - } - - if (H->update_callback) - H->update_callback(max, -1); - return max; -} - -/** - * @brief Extracts from the heap and returns the element at position i. - * \param H the heap we're working on - * \param i element position - * \return the element at position i if ok, NULL otherwise - * - * Extracts from the heap and returns the element at position i. The heap is automatically reordered. - */ -void *xbt_heap_remove(xbt_heap_t H, int i) -{ - XBT_DEBUG("Heap has %d elements: extracting element %d",xbt_heap_size(H),i); - - if ((i < 0) || (i > H->count - 1)) - return NULL; - /* put element i at head */ - if (i > 0) { - KEY(H, i) = MIN_KEY_VALUE; - xbt_heap_increase_key(H, i); - } - - return xbt_heap_pop(H); -} - -/** @brief Remove an arbitrary element from the heap - * \param H the heap we're working on - * \param content the object you want to remove from the heap - * \param key the key associated to this object - * \return the removed element if found, NULL otherwise - */ -void *xbt_heap_rm_elm(xbt_heap_t H, void *content, double key) -{ - int i=0; - while (i < H->count && (KEY(H, i) != key || CONTENT(H, i) != content)) - i++; - return xbt_heap_remove(H, i); -} - -/** - * @brief Updates an element of the heap with a new value. - * \param H the heap we're working on - * \param i element position - * \param key new value for the element - * - * Updates an element of the heap with a new value. - */ -void xbt_heap_update(xbt_heap_t H, int i, double key) -{ - XBT_DEBUG("Heap has %d elements: updating element %d : was %1.12f to %1.12f ",xbt_heap_size(H),i,KEY(H, i), key); - - if ((i < 0) || (i > H->count - 1) || key == KEY(H, i)) - return ; - - if(key< KEY(H, i)){ - KEY(H, i)=key; - xbt_heap_increase_key(H, i); - }else{ - KEY(H, i)=key; - xbt_heap_max_heapify(H,i); - } -} - -/** - * @brief returns the smallest key in the heap (heap unchanged) - * \param H the heap we're working on - * - * \return the smallest key in the heap without modifying the heap. - */ -inline double xbt_heap_maxkey(xbt_heap_t H) -{ - xbt_assert(H->count != 0, "Empty heap"); - return KEY(H, 0); -} - -/** - * @brief returns the value associated to the smallest key in the heap (heap unchanged) - * \param H the heap we're working on - * - * \return the value associated to the smallest key in the heap - * without modifying the heap. - */ -void *xbt_heap_maxcontent(xbt_heap_t H) -{ - xbt_assert(H->count != 0, "Empty heap"); - return CONTENT(H, 0); -} - -/* <<<< private >>>> - * \param H the heap we're working on - * - * Restores the heap property once an element has been deleted. - */ -static void xbt_heap_max_heapify(xbt_heap_t H, int index) -{ - int i = index; - int count = H->count; - xbt_heap_item_t items = H->items; - - while (1) { - int greatest = i; - int l = LEFT(i); - int r = l + 1; - if (l < count && items[l].key < items[i].key) - greatest = l; - if (r < count && items[r].key < items[greatest].key) - greatest = r; - if (greatest != i) { - struct xbt_heap_item tmp = items[i]; - items[i] = items[greatest]; - items[greatest] = tmp; - if (H->update_callback) - H->update_callback(items[i].content, i); - i = greatest; - } else { - if (H->update_callback) - H->update_callback(items[i].content, i); - return; - } - } -} - -/* <<<< private >>>> - * \param H the heap we're working on - * \param i an item position in the heap - * - * Moves up an item at position i to its correct position. Works only when called from xbt_heap_push. - * Do not use otherwise. - */ -static void xbt_heap_increase_key(xbt_heap_t H, int i) -{ - xbt_heap_item_t items = H->items; - int p = PARENT(i); - while (i > 0 && items[p].key > items[i].key) { - struct xbt_heap_item tmp = items[i]; - items[i] = items[p]; - items[p] = tmp; - if (H->update_callback) - H->update_callback(items[i].content, i); - i = p; - p = PARENT(i); - } - if (H->update_callback) - H->update_callback(items[i].content, i); -} diff --git a/src/xbt/heap_private.h b/src/xbt/heap_private.h deleted file mode 100644 index aeed373793..0000000000 --- a/src/xbt/heap_private.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (c) 2004-2017. The SimGrid Team. All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#ifndef XBT_HEAP_PRIVATE_H -#define XBT_HEAP_PRIVATE_H - -#include -#include -#include - -typedef struct xbt_heap_item { - void *content; - double key; -} s_xbt_heap_item_t; -typedef s_xbt_heap_item_t* xbt_heap_item_t; - -typedef struct xbt_heap { - int size; - int count; - s_xbt_heap_item_t* items; /* array of structs */ - void_f_pvoid_t free; - void (*update_callback) (void *, int); -} s_xbt_heap_t; - -#define PARENT(i) (i >> 1) -#define LEFT(i) (i << 1) -#define RIGHT(i) ((i << 1) + 1) - -#define KEY(H,i) ((H->items)[i]).key -#define CONTENT(H,i) ((H->items)[i]).content - -#define MIN_KEY_VALUE -DBL_MAX - -#endif diff --git a/src/xbt/log.c b/src/xbt/log.c index 5479e4d968..6969b593fd 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -112,7 +112,6 @@ static void xbt_log_connect_categories(void) XBT_LOG_CONNECT(xbt_backtrace); XBT_LOG_CONNECT(xbt_exception); XBT_LOG_CONNECT(xbt_graph); - XBT_LOG_CONNECT(xbt_heap); XBT_LOG_CONNECT(xbt_mallocator); XBT_LOG_CONNECT(xbt_memory_map); XBT_LOG_CONNECT(xbt_parmap); diff --git a/teshsuite/xbt/CMakeLists.txt b/teshsuite/xbt/CMakeLists.txt index 70f58b35b7..8a16af4c43 100644 --- a/teshsuite/xbt/CMakeLists.txt +++ b/teshsuite/xbt/CMakeLists.txt @@ -1,4 +1,4 @@ -foreach(x heap_bench log_large log_usage mallocator parallel_log_crashtest) +foreach(x log_large log_usage mallocator parallel_log_crashtest) add_executable (${x} ${x}/${x}.c) target_link_libraries(${x} simgrid) set_target_properties(${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) @@ -27,7 +27,7 @@ set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/log_usage/log_us ${CMAKE_CURRENT_SOURCE_DIR}/mmalloc/mmalloc_32.tesh PARENT_SCOPE) set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/mmalloc/mmalloc_test.cpp PARENT_SCOPE) -foreach(x heap_bench log_large parallel_log_crashtest parmap_test) #mallocator parmap_bench +foreach(x log_large parallel_log_crashtest parmap_test) #mallocator parmap_bench ADD_TESH(tesh-xbt-${x} --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/xbt/${x} --cd ${CMAKE_HOME_DIRECTORY}/teshsuite/xbt/${x} ${x}.tesh) endforeach() diff --git a/teshsuite/xbt/heap_bench/heap_bench.c b/teshsuite/xbt/heap_bench/heap_bench.c deleted file mode 100644 index 47797d2a34..0000000000 --- a/teshsuite/xbt/heap_bench/heap_bench.c +++ /dev/null @@ -1,102 +0,0 @@ -/* A few tests for the xbt_heap module */ - -/* Copyright (c) 2004-2010, 2012-2015. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include -#include -#include - -#include "simgrid/msg.h" -#include "xbt/heap.h" -#include "xbt/sysdep.h" - -#define MAX_TEST 1000000 - -static int compare_double(const void *a, const void *b) -{ - double pa = *((double *) a); - double pb = *((double *) b); - - if (pa > pb) - return 1; - if (pa < pb) - return -1; - return 0; -} - -static void test_reset_heap(xbt_heap_t * heap, int size) -{ - xbt_heap_free(*heap); - *heap = xbt_heap_new(size, NULL); - - for (int i = 0; i < size; i++) { - xbt_heap_push(*heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0))); - } -} - -static void test_heap_validity(int size) -{ - xbt_heap_t heap = xbt_heap_new(size, NULL); - double *tab = xbt_new0(double, size); - int i; - - for (i = 0; i < size; i++) { - tab[i] = (double) (10.0 * rand() / (RAND_MAX + 1.0)); - xbt_heap_push(heap, NULL, (double) tab[i]); - } - - qsort(tab, size, sizeof(double), compare_double); - - for (i = 0; i < size; i++) { - if (fabs(xbt_heap_maxkey(heap) - tab[i]) > 1e-9) { - fprintf(stderr, "Problem !\n"); - exit(1); - } - xbt_heap_pop(heap); - } - xbt_heap_free(heap); - free(tab); - printf("Validity test complete!\n"); -} - -static void test_heap_mean_operation(int size) -{ - xbt_heap_t heap = xbt_heap_new(size, NULL); - - double date = xbt_os_time() * 1000000; - for (int i = 0; i < size; i++) - xbt_heap_push(heap, NULL, (10.0 * rand() / (RAND_MAX + 1.0))); - - date = xbt_os_time() * 1000000 - date; - printf("Creation time %d size heap : %g\n", size, date); - - date = xbt_os_time() * 1000000; - for (int j = 0; j < MAX_TEST; j++) { - - if (!(j % size) && j) - test_reset_heap(&heap, size); - - double val = xbt_heap_maxkey(heap); - xbt_heap_pop(heap); - xbt_heap_push(heap, NULL, 3.0 * val); - } - date = xbt_os_time() * 1000000 - date; - printf("Mean access time for a %d size heap : %g\n", size, date * 1.0 / (MAX_TEST + 0.0)); - - xbt_heap_free(heap); -} - -int main(int argc, char** argv) -{ - MSG_init(&argc, argv); - - for (int size = 100; size < 10000; size *= 10) { - test_heap_validity(size); - test_heap_mean_operation(size); - } - return 0; -} diff --git a/teshsuite/xbt/heap_bench/heap_bench.tesh b/teshsuite/xbt/heap_bench/heap_bench.tesh deleted file mode 100644 index a07abd42a8..0000000000 --- a/teshsuite/xbt/heap_bench/heap_bench.tesh +++ /dev/null @@ -1,10 +0,0 @@ -#! ./tesh - -! output display -$ $SG_TEST_EXENV ${bindir:=.}/heap_bench -> Validity test complete! -> Creation time 100 size heap : 6 -> Mean access time for a 100 size heap : 0.14687 -> Validity test complete! -> Creation time 1000 size heap : 38 -> Mean access time for a 1000 size heap : 0.179765 diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index efb29b208c..83f8cdc55f 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -71,7 +71,6 @@ set(EXTRA_DIST src/xbt/backtrace_linux.cpp src/xbt/dict_private.h src/xbt/graph_private.h - src/xbt/heap_private.h src/xbt/log_private.h src/xbt/mallocator_private.h @@ -275,7 +274,6 @@ set(XBT_SRC src/xbt/ex.cpp src/xbt/exception.cpp src/xbt/graph.c - src/xbt/heap.c src/xbt/log.c src/xbt/mallocator.c src/xbt/memory_map.cpp @@ -726,7 +724,6 @@ set(headers_to_install include/xbt/function_types.h include/xbt/future.hpp include/xbt/graph.h - include/xbt/heap.h include/xbt/log.h include/xbt/log.hpp include/xbt/mallocator.h diff --git a/tools/cmake/GCCFlags.cmake b/tools/cmake/GCCFlags.cmake index 432441c9b7..400194a718 100644 --- a/tools/cmake/GCCFlags.cmake +++ b/tools/cmake/GCCFlags.cmake @@ -145,7 +145,7 @@ if(enable_model-checking AND enable_compile_optimizations) src/xbt/log.c src/xbt/xbt_log_appender_file.c src/xbt/xbt_log_layout_format.c src/xbt/xbt_log_layout_simple.c src/xbt/dict.cpp src/xbt/dict_elm.c src/xbt/dict_cursor.c - src/xbt/dynar.cpp src/xbt/heap.c src/xbt/swag.c + src/xbt/dynar.cpp src/xbt/swag.c src/xbt/str.c src src/xbt/snprintf.c src/xbt/queue.c src/xbt/xbt_os_time.c src/xbt/xbt_os_thread.c