ext/h3/src/src/h3lib/lib/vertexGraph.c in h3-3.6.2 vs ext/h3/src/src/h3lib/lib/vertexGraph.c in h3-3.7.1

- old
+ new

@@ -16,26 +16,29 @@ /** @file vertexGraph.c * @brief Data structure for storing a graph of vertices */ #include "vertexGraph.h" + #include <assert.h> #include <math.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> + +#include "alloc.h" #include "geoCoord.h" /** * Initialize a new VertexGraph * @param graph Graph to initialize * @param numBuckets Number of buckets to include in the graph * @param res Resolution of the hexagons whose vertices we're storing */ void initVertexGraph(VertexGraph* graph, int numBuckets, int res) { if (numBuckets > 0) { - graph->buckets = calloc(numBuckets, sizeof(VertexNode*)); + graph->buckets = H3_MEMORY(calloc)(numBuckets, sizeof(VertexNode*)); assert(graph->buckets != NULL); } else { graph->buckets = NULL; } graph->numBuckets = numBuckets; @@ -51,11 +54,11 @@ void destroyVertexGraph(VertexGraph* graph) { VertexNode* node; while ((node = firstVertexNode(graph)) != NULL) { removeVertexNode(graph, node); } - free(graph->buckets); + H3_MEMORY(free)(graph->buckets); } /** * Get an integer hash for a lat/lon point, at a precision determined * by the current hexagon resolution. @@ -89,11 +92,11 @@ * @return Pointer to the new node */ VertexNode* addVertexNode(VertexGraph* graph, const GeoCoord* fromVtx, const GeoCoord* toVtx) { // Make the new node - VertexNode* node = malloc(sizeof(VertexNode)); + VertexNode* node = H3_MEMORY(malloc)(sizeof(VertexNode)); assert(node != NULL); _initVertexNode(node, fromVtx, toVtx); // Determine location uint32_t index = _hashVertex(fromVtx, graph->res, graph->numBuckets); // Check whether there's an existing node in that spot @@ -106,11 +109,11 @@ do { // Check the the edge we're adding doesn't already exist if (geoAlmostEqual(&currentNode->from, fromVtx) && geoAlmostEqual(&currentNode->to, toVtx)) { // already exists, bail - free(node); + H3_MEMORY(free)(node); return currentNode; } if (currentNode->next != NULL) { currentNode = currentNode->next; } @@ -148,10 +151,10 @@ } currentNode = currentNode->next; } } if (found) { - free(node); + H3_MEMORY(free)(node); graph->size--; return 0; } // Failed to find the node return 1;