summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxcore/DHT.c4
-rw-r--r--toxcore/DHT.h3
-rw-r--r--toxcore/misc_tools.h5
3 files changed, 10 insertions, 2 deletions
diff --git a/toxcore/DHT.c b/toxcore/DHT.c
index 307b1e33..02e0ed08 100644
--- a/toxcore/DHT.c
+++ b/toxcore/DHT.c
@@ -56,6 +56,8 @@
56#define NAT_PING_REQUEST 0 56#define NAT_PING_REQUEST 0
57#define NAT_PING_RESPONSE 1 57#define NAT_PING_RESPONSE 1
58 58
59/* Create the quicksort function. See misc_tools.h for the definition. */
60make_quick_sort(ClientPair);
59 61
60Client_data *DHT_get_close_list(DHT *dht) 62Client_data *DHT_get_close_list(DHT *dht)
61{ 63{
@@ -299,8 +301,6 @@ static void sort_list(Client_data *list, uint32_t length, uint8_t *comp_client_i
299 ClientPair pairs[length]; 301 ClientPair pairs[length];
300 uint32_t i; 302 uint32_t i;
301 303
302 /* Create the quicksort function. See misc_tools.h for the definition. */
303 make_quick_sort(ClientPair);
304 memcpy(cd.client_id, comp_client_id, CLIENT_ID_SIZE); 304 memcpy(cd.client_id, comp_client_id, CLIENT_ID_SIZE);
305 for (i = 0; i < length; ++i) { 305 for (i = 0; i < length; ++i) {
306 pairs[i].c1 = cd; 306 pairs[i].c1 = cd;
diff --git a/toxcore/DHT.h b/toxcore/DHT.h
index d0afda35..88073779 100644
--- a/toxcore/DHT.h
+++ b/toxcore/DHT.h
@@ -106,6 +106,9 @@ typedef struct {
106} DHT; 106} DHT;
107/*----------------------------------------------------------------------------------*/ 107/*----------------------------------------------------------------------------------*/
108 108
109/* Create the declaration for a quick sort for ClientPair structures. */
110declare_quick_sort(ClientPair);
111
109Client_data *DHT_get_close_list(DHT *dht); 112Client_data *DHT_get_close_list(DHT *dht);
110 113
111/* Add a new friend to the friends list. 114/* Add a new friend to the friends list.
diff --git a/toxcore/misc_tools.h b/toxcore/misc_tools.h
index 4d62a856..1889eba4 100644
--- a/toxcore/misc_tools.h
+++ b/toxcore/misc_tools.h
@@ -199,6 +199,11 @@ static inline void tox_array_pop(tox_array *arr, uint32_t num)
199 * cmpfn - a function that compares two values of type type. 199 * cmpfn - a function that compares two values of type type.
200 * Must return -1, 0, 1 for a < b, a == b, and a > b respectively. 200 * Must return -1, 0, 1 for a < b, a == b, and a > b respectively.
201 */ 201 */
202/* Must be called in the header file. */
203#define declare_quick_sort(type) \
204void type##_quick_sort(type *arr, int n, int (*cmpfn)(type, type));
205
206/* Must be called in the C file. */
202#define make_quick_sort(type) \ 207#define make_quick_sort(type) \
203void type##_quick_sort(type *arr, int n, int (*cmpfn)(type, type)) \ 208void type##_quick_sort(type *arr, int n, int (*cmpfn)(type, type)) \
204{ \ 209{ \