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 595 - (show annotations) (download) (as text)
Sat Jan 8 15:42:28 2011 UTC (14 years, 2 months ago) by amb
File MIME type: text/x-chdr
File size: 6213 byte(s)
Change the IsSuperNode() macro to take a single pointer argument.

1 /***************************************
2 A header file for the nodes.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2011 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
28 #include "types.h"
29
30 #include "files.h"
31 #include "profiles.h"
32
33
34 /* Data structures */
35
36
37 /*+ A structure containing a single node. +*/
38 struct _Node
39 {
40 index_t firstseg; /*+ The index of the first segment. +*/
41
42 ll_off_t latoffset; /*+ The node latitude offset within its bin. +*/
43 ll_off_t lonoffset; /*+ The node longitude offset within its bin. +*/
44
45 transports_t allow; /*+ The types of transport that are allowed through the node. +*/
46 uint16_t flags; /*+ Flags containing extra information (super-node, turn restriction). +*/
47 };
48
49
50 /*+ A structure containing the header from the file. +*/
51 typedef struct _NodesFile
52 {
53 index_t number; /*+ How many nodes in total? +*/
54 index_t snumber; /*+ How many super-nodes? +*/
55
56 index_t latbins; /*+ The number of bins containing latitude. +*/
57 index_t lonbins; /*+ The number of bins containing longitude. +*/
58
59 ll_bin_t latzero; /*+ The bin number of the furthest south bin. +*/
60 ll_bin_t lonzero; /*+ The bin number of the furthest west bin. +*/
61 }
62 NodesFile;
63
64
65 /*+ A structure containing a set of nodes (and pointers to mmap file). +*/
66 struct _Nodes
67 {
68 NodesFile file; /*+ The header data from the file. +*/
69
70 #if !SLIM
71
72 void *data; /*+ The memory mapped data. +*/
73
74 index_t *offsets; /*+ An array of offsets to the first node in each bin. +*/
75
76 Node *nodes; /*+ An array of nodes. +*/
77
78 #else
79
80 int fd; /*+ The file descriptor for the file. +*/
81 off_t nodesoffset; /*+ The offset of the nodes within the file. +*/
82
83 Node cached[2]; /*+ The cached nodes. +*/
84 index_t incache[2]; /*+ The indexes of the cached nodes. +*/
85
86 #endif
87 };
88
89
90 /* Functions */
91
92 Nodes *LoadNodeList(const char *filename);
93
94 index_t FindClosestNode(Nodes* nodes,Segments *segments,Ways *ways,double latitude,double longitude,
95 distance_t distance,Profile *profile,distance_t *bestdist);
96
97 index_t FindClosestSegment(Nodes* nodes,Segments *segments,Ways *ways,double latitude,double longitude,
98 distance_t distance,Profile *profile, distance_t *bestdist,
99 index_t *bestnode1,index_t *bestnode2,distance_t *bestdist1,distance_t *bestdist2);
100
101 void GetLatLong(Nodes *nodes,index_t index,double *latitude,double *longitude);
102
103
104 /* Macros and inline functions */
105
106 /*+ Return true if this is a super-node. +*/
107 #define IsSuperNode(xxx) (((xxx)->flags)&NODE_SUPER)
108
109
110 #if !SLIM
111
112 /*+ Return a Node pointer given a set of nodes and an index. +*/
113 #define LookupNode(xxx,yyy,zzz) (&(xxx)->nodes[yyy])
114
115 /*+ Return a Segment points given a Node pointer and a set of segments. +*/
116 #define FirstSegment(xxx,yyy,zzz) LookupSegment((xxx),(yyy)->nodes[zzz].firstseg,1)
117
118 /*+ Return the offset of a geographical region given a set of nodes and an index. +*/
119 #define LookupNodeOffset(xxx,yyy) ((xxx)->offsets[yyy])
120
121 #else
122
123 static Node *LookupNode(Nodes *nodes,index_t index,int position);
124
125 #define FirstSegment(xxx,yyy,zzz) LookupSegment((xxx),FirstSegment_internal(yyy,zzz),1)
126
127 static index_t FirstSegment_internal(Nodes *nodes,index_t index);
128
129 static index_t LookupNodeOffset(Nodes *nodes,index_t index);
130
131
132 /*++++++++++++++++++++++++++++++++++++++
133 Find the Node information for a particular node.
134
135 Node *LookupNode Returns a pointer to the cached node information.
136
137 Nodes *nodes The nodes structure to use.
138
139 index_t index The index of the node.
140
141 int position The position in the cache to store the value.
142 ++++++++++++++++++++++++++++++++++++++*/
143
144 static inline Node *LookupNode(Nodes *nodes,index_t index,int position)
145 {
146 if(nodes->incache[position-1]!=index)
147 {
148 SeekFile(nodes->fd,nodes->nodesoffset+(off_t)index*sizeof(Node));
149
150 ReadFile(nodes->fd,&nodes->cached[position-1],sizeof(Node));
151
152 nodes->incache[position-1]=index;
153 }
154
155 return(&nodes->cached[position-1]);
156 }
157
158
159 /*++++++++++++++++++++++++++++++++++++++
160 Find the index of the first segment of a node (called by FirstSegment() macro).
161
162 index_t FirstSegment_internal Returns the index of the first segment.
163
164 Nodes *nodes The nodes structure to use.
165
166 index_t index The index of the node.
167 ++++++++++++++++++++++++++++++++++++++*/
168
169 static inline index_t FirstSegment_internal(Nodes *nodes,index_t index)
170 {
171 if(nodes->incache[0]==index)
172 return(nodes->cached[0].firstseg);
173 else if(nodes->incache[1]==index)
174 return(nodes->cached[1].firstseg);
175 else
176 {
177 Node *node=LookupNode(nodes,index,3);
178
179 return(node->firstseg);
180 }
181 }
182
183
184 /*++++++++++++++++++++++++++++++++++++++
185 Find the offset of nodes in a geographical region.
186
187 index_t LookupNodeOffset Returns the value of the index offset.
188
189 Nodes *nodes The nodes structure to use.
190
191 index_t index The index of the offset.
192 ++++++++++++++++++++++++++++++++++++++*/
193
194 static inline index_t LookupNodeOffset(Nodes *nodes,index_t index)
195 {
196 index_t offset;
197
198 SeekFile(nodes->fd,sizeof(NodesFile)+(off_t)index*sizeof(index_t));
199
200 ReadFile(nodes->fd,&offset,sizeof(index_t));
201
202 return(offset);
203 }
204
205 #endif
206
207
208 #endif /* NODES_H */

Properties

Name Value
cvs:description Header file for nodes.