Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/segments.h
Parent Directory
|
Revision Log
Revision 1603 -
(show annotations)
(download)
(as text)
Mon Oct 13 18:25:27 2014 UTC (10 years, 5 months ago) by amb
File MIME type: text/x-chdr
File size: 7892 byte(s)
Mon Oct 13 18:25:27 2014 UTC (10 years, 5 months ago) by amb
File MIME type: text/x-chdr
File size: 7892 byte(s)
Try to speed up the search for the closest node/segment by minimising the number of nodes that are examined in detail.
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/segments.h,v 1.38 2010-12-21 17:18:41 amb Exp $ |
3 | |
4 | A header file for the segments. |
5 | |
6 | Part of the Routino routing software. |
7 | ******************/ /****************** |
8 | This file Copyright 2008-2014 Andrew M. Bishop |
9 | |
10 | This program is free software: you can redistribute it and/or modify |
11 | it under the terms of the GNU Affero General Public License as published by |
12 | the Free Software Foundation, either version 3 of the License, or |
13 | (at your option) any later version. |
14 | |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public License |
21 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
22 | ***************************************/ |
23 | |
24 | |
25 | #ifndef SEGMENTS_H |
26 | #define SEGMENTS_H /*+ To stop multiple inclusions. +*/ |
27 | |
28 | #include <stdint.h> |
29 | |
30 | #include "types.h" |
31 | |
32 | #include "cache.h" |
33 | #include "files.h" |
34 | #include "profiles.h" |
35 | |
36 | |
37 | /* Data structures */ |
38 | |
39 | |
40 | /*+ A structure containing a single segment. +*/ |
41 | struct _Segment |
42 | { |
43 | index_t node1; /*+ The index of the starting node. +*/ |
44 | index_t node2; /*+ The index of the finishing node. +*/ |
45 | |
46 | index_t next2; /*+ The index of the next segment sharing node2. +*/ |
47 | |
48 | index_t way; /*+ The index of the way associated with the segment. +*/ |
49 | |
50 | distance_t distance; /*+ The distance between the nodes. +*/ |
51 | }; |
52 | |
53 | |
54 | /*+ A structure containing the header from the file. +*/ |
55 | typedef struct _SegmentsFile |
56 | { |
57 | index_t number; /*+ The number of segments in total. +*/ |
58 | index_t snumber; /*+ The number of super-segments. +*/ |
59 | index_t nnumber; /*+ The number of normal segments. +*/ |
60 | } |
61 | SegmentsFile; |
62 | |
63 | |
64 | /*+ A structure containing a set of segments (and pointers to mmap file). +*/ |
65 | struct _Segments |
66 | { |
67 | SegmentsFile file; /*+ The header data from the file. +*/ |
68 | |
69 | #if !SLIM |
70 | |
71 | void *data; /*+ The memory mapped data. +*/ |
72 | |
73 | Segment *segments; /*+ An array of segments. +*/ |
74 | |
75 | #else |
76 | |
77 | int fd; /*+ The file descriptor for the file. +*/ |
78 | |
79 | Segment cached[4]; /*+ Three cached segments read from the file in slim mode. +*/ |
80 | index_t incache[4]; /*+ The indexes of the cached segments. +*/ |
81 | |
82 | SegmentCache *cache; /*+ A RAM cache of segments read from the file. +*/ |
83 | |
84 | #endif |
85 | }; |
86 | |
87 | |
88 | /* Functions in segments.c */ |
89 | |
90 | Segments *LoadSegmentList(const char *filename); |
91 | |
92 | void DestroySegmentList(Segments *segments); |
93 | |
94 | index_t FindClosestSegmentHeading(Nodes *nodes,Segments *segments,Ways *ways,index_t node1,double heading,Profile *profile); |
95 | |
96 | distance_t Distance(double lat1,double lon1,double lat2,double lon2); |
97 | |
98 | double DeltaLat(double lon,distance_t distance); |
99 | double DeltaLon(double lat,distance_t distance); |
100 | |
101 | duration_t Duration(Segment *segmentp,Way *wayp,Profile *profile); |
102 | |
103 | double TurnAngle(Nodes *nodes,Segment *segment1p,Segment *segment2p,index_t node); |
104 | double BearingAngle(Nodes *nodes,Segment *segmentp,index_t node); |
105 | |
106 | |
107 | static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node); |
108 | |
109 | |
110 | /* Macros and inline functions */ |
111 | |
112 | /*+ Return true if this is a normal segment. +*/ |
113 | #define IsNormalSegment(xxx) (((xxx)->distance)&SEGMENT_NORMAL) |
114 | |
115 | /*+ Return true if this is a super-segment. +*/ |
116 | #define IsSuperSegment(xxx) (((xxx)->distance)&SEGMENT_SUPER) |
117 | |
118 | /*+ Return true if the segment is oneway. +*/ |
119 | #define IsOneway(xxx) ((xxx)->distance&(ONEWAY_2TO1|ONEWAY_1TO2)) |
120 | |
121 | /*+ Return true if the segment is oneway towards the specified node. +*/ |
122 | #define IsOnewayTo(xxx,yyy) ((xxx)->node1==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2)) |
123 | |
124 | /*+ Return true if the segment is oneway from the specified node. +*/ |
125 | #define IsOnewayFrom(xxx,yyy) ((xxx)->node2==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2)) |
126 | |
127 | /*+ Return the other node in the segment that is not the specified node. +*/ |
128 | #define OtherNode(xxx,yyy) ((xxx)->node1==(yyy)?(xxx)->node2:(xxx)->node1) |
129 | |
130 | |
131 | #if !SLIM |
132 | |
133 | /*+ Return a segment pointer given a set of segments and an index. +*/ |
134 | #define LookupSegment(xxx,yyy,ppp) (&(xxx)->segments[yyy]) |
135 | |
136 | /*+ Return a segment index given a set of segments and a pointer. +*/ |
137 | #define IndexSegment(xxx,yyy) (index_t)((yyy)-&(xxx)->segments[0]) |
138 | |
139 | |
140 | /*++++++++++++++++++++++++++++++++++++++ |
141 | Find the next segment with a particular starting node. |
142 | |
143 | Segment *NextSegment Returns a pointer to the next segment. |
144 | |
145 | Segments *segments The set of segments to use. |
146 | |
147 | Segment *segmentp The current segment. |
148 | |
149 | index_t node The wanted node. |
150 | ++++++++++++++++++++++++++++++++++++++*/ |
151 | |
152 | static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node) |
153 | { |
154 | if(segmentp->node1==node) |
155 | { |
156 | segmentp++; |
157 | |
158 | if(IndexSegment(segments,segmentp)>=segments->file.number || segmentp->node1!=node) |
159 | return(NULL); |
160 | else |
161 | return(segmentp); |
162 | } |
163 | else |
164 | { |
165 | if(segmentp->next2==NO_SEGMENT) |
166 | return(NULL); |
167 | else |
168 | return(LookupSegment(segments,segmentp->next2,1)); |
169 | } |
170 | } |
171 | |
172 | #else |
173 | |
174 | /* Prototypes */ |
175 | |
176 | static inline Segment *LookupSegment(Segments *segments,index_t index,int position); |
177 | |
178 | static inline index_t IndexSegment(Segments *segments,Segment *segmentp); |
179 | |
180 | CACHE_NEWCACHE_PROTO(Segment) |
181 | CACHE_DELETECACHE_PROTO(Segment) |
182 | CACHE_FETCHCACHE_PROTO(Segment) |
183 | CACHE_INVALIDATECACHE_PROTO(Segment) |
184 | |
185 | |
186 | /* Inline functions */ |
187 | |
188 | CACHE_STRUCTURE(Segment) |
189 | CACHE_NEWCACHE(Segment) |
190 | CACHE_DELETECACHE(Segment) |
191 | CACHE_FETCHCACHE(Segment) |
192 | CACHE_INVALIDATECACHE(Segment) |
193 | |
194 | |
195 | /*++++++++++++++++++++++++++++++++++++++ |
196 | Find the Segment information for a particular segment. |
197 | |
198 | Segment *LookupSegment Returns a pointer to the cached segment information. |
199 | |
200 | Segments *segments The set of segments to use. |
201 | |
202 | index_t index The index of the segment. |
203 | |
204 | int position The position in the cache to store the value. |
205 | ++++++++++++++++++++++++++++++++++++++*/ |
206 | |
207 | static inline Segment *LookupSegment(Segments *segments,index_t index,int position) |
208 | { |
209 | segments->cached[position-1]=*FetchCachedSegment(segments->cache,index,segments->fd,sizeof(SegmentsFile)); |
210 | |
211 | segments->incache[position-1]=index; |
212 | |
213 | return(&segments->cached[position-1]); |
214 | } |
215 | |
216 | |
217 | /*++++++++++++++++++++++++++++++++++++++ |
218 | Find the segment index for a particular segment pointer. |
219 | |
220 | index_t IndexSegment Returns the index of the segment in the list. |
221 | |
222 | Segments *segments The set of segments to use. |
223 | |
224 | Segment *segmentp The segment whose index is to be found. |
225 | ++++++++++++++++++++++++++++++++++++++*/ |
226 | |
227 | static inline index_t IndexSegment(Segments *segments,Segment *segmentp) |
228 | { |
229 | int position1=segmentp-&segments->cached[0]; |
230 | |
231 | return(segments->incache[position1]); |
232 | } |
233 | |
234 | |
235 | /*++++++++++++++++++++++++++++++++++++++ |
236 | Find the next segment with a particular starting node. |
237 | |
238 | Segment *NextSegment Returns a pointer to the next segment. |
239 | |
240 | Segments *segments The set of segments to use. |
241 | |
242 | Segment *segmentp The current segment. |
243 | |
244 | index_t node The wanted node. |
245 | ++++++++++++++++++++++++++++++++++++++*/ |
246 | |
247 | static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node) |
248 | { |
249 | int position=segmentp-&segments->cached[-1]; |
250 | |
251 | if(segmentp->node1==node) |
252 | { |
253 | index_t index=IndexSegment(segments,segmentp); |
254 | |
255 | index++; |
256 | |
257 | if(index>=segments->file.number) |
258 | return(NULL); |
259 | |
260 | segmentp=LookupSegment(segments,index,position); |
261 | |
262 | if(segmentp->node1!=node) |
263 | return(NULL); |
264 | else |
265 | return(segmentp); |
266 | } |
267 | else |
268 | { |
269 | if(segmentp->next2==NO_SEGMENT) |
270 | return(NULL); |
271 | else |
272 | return(LookupSegment(segments,segmentp->next2,position)); |
273 | } |
274 | } |
275 | |
276 | #endif |
277 | |
278 | |
279 | #endif /* SEGMENTS_H */ |
Properties
Name | Value |
---|---|
cvs:description | Header file for segments. |