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/segments.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1296 - (show annotations) (download) (as text)
Tue May 7 09:31:00 2013 UTC (11 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 7747 byte(s)
Move the cache functions out of cache.c and into each data type's header file as
inline functions.

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-2013 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[3]; /*+ Three cached segments read from the file in slim mode. +*/
80 index_t incache[3]; /*+ 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 index_t FindClosestSegmentHeading(Nodes *nodes,Segments *segments,Ways *ways,index_t node1,double heading,Profile *profile);
93
94 distance_t Distance(double lat1,double lon1,double lat2,double lon2);
95
96 duration_t Duration(Segment *segmentp,Way *wayp,Profile *profile);
97
98 double TurnAngle(Nodes *nodes,Segment *segment1p,Segment *segment2p,index_t node);
99 double BearingAngle(Nodes *nodes,Segment *segmentp,index_t node);
100
101
102 static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node);
103
104
105 /* Macros and inline functions */
106
107 /*+ Return true if this is a normal segment. +*/
108 #define IsNormalSegment(xxx) (((xxx)->distance)&SEGMENT_NORMAL)
109
110 /*+ Return true if this is a super-segment. +*/
111 #define IsSuperSegment(xxx) (((xxx)->distance)&SEGMENT_SUPER)
112
113 /*+ Return true if the segment is oneway. +*/
114 #define IsOneway(xxx) ((xxx)->distance&(ONEWAY_2TO1|ONEWAY_1TO2))
115
116 /*+ Return true if the segment is oneway towards the specified node. +*/
117 #define IsOnewayTo(xxx,yyy) ((xxx)->node1==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2))
118
119 /*+ Return true if the segment is oneway from the specified node. +*/
120 #define IsOnewayFrom(xxx,yyy) ((xxx)->node2==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2))
121
122 /*+ Return the other node in the segment that is not the specified node. +*/
123 #define OtherNode(xxx,yyy) ((xxx)->node1==(yyy)?(xxx)->node2:(xxx)->node1)
124
125
126 #if !SLIM
127
128 /*+ Return a segment pointer given a set of segments and an index. +*/
129 #define LookupSegment(xxx,yyy,ppp) (&(xxx)->segments[yyy])
130
131 /*+ Return a segment index given a set of segments and a pointer. +*/
132 #define IndexSegment(xxx,yyy) (index_t)((yyy)-&(xxx)->segments[0])
133
134
135 /*++++++++++++++++++++++++++++++++++++++
136 Find the next segment with a particular starting node.
137
138 Segment *NextSegment Returns a pointer to the next segment.
139
140 Segments *segments The set of segments to use.
141
142 Segment *segmentp The current segment.
143
144 index_t node The wanted node.
145 ++++++++++++++++++++++++++++++++++++++*/
146
147 static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node)
148 {
149 if(segmentp->node1==node)
150 {
151 segmentp++;
152
153 if(IndexSegment(segments,segmentp)>=segments->file.number || segmentp->node1!=node)
154 return(NULL);
155 else
156 return(segmentp);
157 }
158 else
159 {
160 if(segmentp->next2==NO_SEGMENT)
161 return(NULL);
162 else
163 return(LookupSegment(segments,segmentp->next2,1));
164 }
165 }
166
167 #else
168
169 /* Prototypes */
170
171 static inline Segment *LookupSegment(Segments *segments,index_t index,int position);
172
173 static inline index_t IndexSegment(Segments *segments,Segment *segmentp);
174
175 CACHE_NEWCACHE_PROTO(Segment)
176 CACHE_DELETECACHE_PROTO(Segment)
177 CACHE_FETCHCACHE_PROTO(Segment)
178 CACHE_INVALIDATECACHE_PROTO(Segment)
179
180
181 /* Inline functions */
182
183 CACHE_STRUCTURE(Segment)
184 CACHE_NEWCACHE(Segment)
185 CACHE_DELETECACHE(Segment)
186 CACHE_FETCHCACHE(Segment)
187 CACHE_INVALIDATECACHE(Segment)
188
189
190 /*++++++++++++++++++++++++++++++++++++++
191 Find the Segment information for a particular segment.
192
193 Segment *LookupSegment Returns a pointer to the cached segment information.
194
195 Segments *segments The set of segments to use.
196
197 index_t index The index of the segment.
198
199 int position The position in the cache to store the value.
200 ++++++++++++++++++++++++++++++++++++++*/
201
202 static inline Segment *LookupSegment(Segments *segments,index_t index,int position)
203 {
204 segments->cached[position-1]=*FetchCachedSegment(segments->cache,index,segments->fd,sizeof(SegmentsFile));
205
206 segments->incache[position-1]=index;
207
208 return(&segments->cached[position-1]);
209 }
210
211
212 /*++++++++++++++++++++++++++++++++++++++
213 Find the segment index for a particular segment pointer.
214
215 index_t IndexSegment Returns the index of the segment in the list.
216
217 Segments *segments The set of segments to use.
218
219 Segment *segmentp The segment whose index is to be found.
220 ++++++++++++++++++++++++++++++++++++++*/
221
222 static inline index_t IndexSegment(Segments *segments,Segment *segmentp)
223 {
224 int position1=segmentp-&segments->cached[0];
225
226 return(segments->incache[position1]);
227 }
228
229
230 /*++++++++++++++++++++++++++++++++++++++
231 Find the next segment with a particular starting node.
232
233 Segment *NextSegment Returns a pointer to the next segment.
234
235 Segments *segments The set of segments to use.
236
237 Segment *segmentp The current segment.
238
239 index_t node The wanted node.
240 ++++++++++++++++++++++++++++++++++++++*/
241
242 static inline Segment *NextSegment(Segments *segments,Segment *segmentp,index_t node)
243 {
244 int position=segmentp-&segments->cached[-1];
245
246 if(segmentp->node1==node)
247 {
248 index_t index=IndexSegment(segments,segmentp);
249
250 index++;
251
252 if(index>=segments->file.number)
253 return(NULL);
254
255 segmentp=LookupSegment(segments,index,position);
256
257 if(segmentp->node1!=node)
258 return(NULL);
259 else
260 return(segmentp);
261 }
262 else
263 {
264 if(segmentp->next2==NO_SEGMENT)
265 return(NULL);
266 else
267 return(LookupSegment(segments,segmentp->next2,position));
268 }
269 }
270
271 #endif
272
273
274 #endif /* SEGMENTS_H */

Properties

Name Value
cvs:description Header file for segments.