Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Contents of /trunk/src/nodes.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1292 - (show annotations) (download) (as text)
Fri May 3 15:25:56 2013 UTC (11 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 5000 byte(s)
Add node, segment, way and turn relation cache for slim mode.  Approx 40%
speed-up for router.

1 /***************************************
2 A header file for the nodes.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2013 Andrew M. Bishop
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Affero General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Affero General Public License for more details.
17
18 You should have received a copy of the GNU Affero General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ***************************************/
21
22
23 #ifndef NODES_H
24 #define NODES_H /*+ To stop multiple inclusions. +*/
25
26 #include <stdint.h>
27 #include <sys/types.h>
28
29 #include "types.h"
30 #include "cache.h"
31
32 #include "files.h"
33 #include "profiles.h"
34
35
36 /* Data structures */
37
38
39 /*+ A structure containing a single node. +*/
40 struct _Node
41 {
42 index_t firstseg; /*+ The index of the first segment. +*/
43
44 ll_off_t latoffset; /*+ The node latitude offset within its bin. +*/
45 ll_off_t lonoffset; /*+ The node longitude offset within its bin. +*/
46
47 transports_t allow; /*+ The types of transport that are allowed through the node. +*/
48 nodeflags_t flags; /*+ Flags containing extra information (e.g. super-node, turn restriction). +*/
49 };
50
51
52 /*+ A structure containing the header from the file. +*/
53 typedef struct _NodesFile
54 {
55 index_t number; /*+ The number of nodes in total. +*/
56 index_t snumber; /*+ The number of super-nodes. +*/
57
58 ll_bin_t latbins; /*+ The number of bins containing latitude. +*/
59 ll_bin_t lonbins; /*+ The number of bins containing longitude. +*/
60
61 ll_bin_t latzero; /*+ The bin number of the furthest south bin. +*/
62 ll_bin_t lonzero; /*+ The bin number of the furthest west bin. +*/
63 }
64 NodesFile;
65
66
67 /*+ A structure containing a set of nodes. +*/
68 struct _Nodes
69 {
70 NodesFile file; /*+ The header data from the file. +*/
71
72 #if !SLIM
73
74 void *data; /*+ The memory mapped data in the file. +*/
75
76 index_t *offsets; /*+ A pointer to the array of offsets in the file. +*/
77
78 Node *nodes; /*+ A pointer to the array of nodes in the file. +*/
79
80 #else
81
82 int fd; /*+ The file descriptor for the file. +*/
83
84 index_t *offsets; /*+ An allocated array with a copy of the file offsets. +*/
85
86 off_t nodesoffset; /*+ The offset of the nodes within the file. +*/
87
88 Node cached[6]; /*+ Some cached nodes read from the file in slim mode. +*/
89
90 NodeCache *cache; /*+ A RAM cache of nodes read from the file. +*/
91
92 #endif
93 };
94
95
96 /* Functions in nodes.c */
97
98 Nodes *LoadNodeList(const char *filename);
99
100 index_t FindClosestNode(Nodes *nodes,Segments *segments,Ways *ways,double latitude,double longitude,
101 distance_t distance,Profile *profile,distance_t *bestdist);
102
103 index_t FindClosestSegment(Nodes *nodes,Segments *segments,Ways *ways,double latitude,double longitude,
104 distance_t distance,Profile *profile, distance_t *bestdist,
105 index_t *bestnode1,index_t *bestnode2,distance_t *bestdist1,distance_t *bestdist2);
106
107 void GetLatLong(Nodes *nodes,index_t index,Node *nodep,double *latitude,double *longitude);
108
109
110 /* Macros and inline functions */
111
112 /*+ Return true if this is a super-node. +*/
113 #define IsSuperNode(xxx) (((xxx)->flags)&NODE_SUPER)
114
115 /*+ Return true if this is a turn restricted node. +*/
116 #define IsTurnRestrictedNode(xxx) (((xxx)->flags)&NODE_TURNRSTRCT)
117
118 /*+ Return a Segment index given a Node pointer and a set of segments. +*/
119 #define FirstSegment(xxx,yyy,ppp) LookupSegment((xxx),(yyy)->firstseg,ppp)
120
121 /*+ Return the offset of a geographical region given a set of nodes. +*/
122 #define LookupNodeOffset(xxx,yyy) ((xxx)->offsets[yyy])
123
124
125 #if !SLIM
126
127 /*+ Return a Node pointer given a set of nodes and an index. +*/
128 #define LookupNode(xxx,yyy,ppp) (&(xxx)->nodes[yyy])
129
130 #else
131
132 static Node *LookupNode(Nodes *nodes,index_t index,int position);
133
134
135 /*++++++++++++++++++++++++++++++++++++++
136 Find the Node information for a particular node.
137
138 Node *LookupNode Returns a pointer to the cached node information.
139
140 Nodes *nodes The set of nodes to use.
141
142 index_t index The index of the node.
143
144 int position The position in the cache to store the value.
145 ++++++++++++++++++++++++++++++++++++++*/
146
147 static inline Node *LookupNode(Nodes *nodes,index_t index,int position)
148 {
149 nodes->cached[position-1]=*FetchCachedNode(nodes,index);
150
151 return(&nodes->cached[position-1]);
152 }
153
154 #endif
155
156
157 #endif /* NODES_H */

Properties

Name Value
cvs:description Header file for nodes.