vertexGraph.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2017 Uber Technologies, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /** @file vertexGraph.h
  17. * @brief Data structure for storing a graph of vertices
  18. */
  19. #ifndef VERTEX_GRAPH_H
  20. #define VERTEX_GRAPH_H
  21. #include <stdint.h>
  22. #include <stdlib.h>
  23. #include "geoCoord.h"
  24. /** @struct VertexNode
  25. * @brief A single node in a vertex graph, part of a linked list
  26. */
  27. typedef struct VertexNode VertexNode;
  28. struct VertexNode {
  29. GeoCoord from;
  30. GeoCoord to;
  31. VertexNode* next;
  32. };
  33. /** @struct VertexGraph
  34. * @brief A data structure to store a graph of vertices
  35. */
  36. typedef struct {
  37. VertexNode** buckets;
  38. int numBuckets;
  39. int size;
  40. int res;
  41. } VertexGraph;
  42. void initVertexGraph(VertexGraph* graph, int numBuckets, int res);
  43. void destroyVertexGraph(VertexGraph* graph);
  44. VertexNode* addVertexNode(VertexGraph* graph, const GeoCoord* fromVtx,
  45. const GeoCoord* toVtx);
  46. int removeVertexNode(VertexGraph* graph, VertexNode* node);
  47. VertexNode* findNodeForEdge(const VertexGraph* graph, const GeoCoord* fromVtx,
  48. const GeoCoord* toVtx);
  49. VertexNode* findNodeForVertex(const VertexGraph* graph,
  50. const GeoCoord* fromVtx);
  51. VertexNode* firstVertexNode(const VertexGraph* graph);
  52. // Internal functions
  53. uint32_t _hashVertex(const GeoCoord* vertex, int res, int numBuckets);
  54. void _initVertexNode(VertexNode* node, const GeoCoord* fromVtx,
  55. const GeoCoord* toVtx);
  56. #endif