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 704 -
(show annotations)
(download)
(as text)
Sun May 8 16:19:10 2011 UTC (13 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 5587 byte(s)
Sun May 8 16:19:10 2011 UTC (13 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 5587 byte(s)
Simplify the lookup of the segment index in slim mode.
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-2011 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 "files.h" |
33 | #include "profiles.h" |
34 | |
35 | |
36 | /* Data structures */ |
37 | |
38 | |
39 | /*+ A structure containing a single segment. +*/ |
40 | struct _Segment |
41 | { |
42 | index_t node1; /*+ The index of the starting node. +*/ |
43 | index_t node2; /*+ The index of the finishing node. +*/ |
44 | |
45 | index_t next2; /*+ The index of the next segment sharing node2. +*/ |
46 | |
47 | index_t way; /*+ The index of the way associated with the segment. +*/ |
48 | |
49 | distance_t distance; /*+ The distance between the nodes. +*/ |
50 | }; |
51 | |
52 | |
53 | /*+ A structure containing the header from the file. +*/ |
54 | typedef struct _SegmentsFile |
55 | { |
56 | index_t number; /*+ The number of segments in total. +*/ |
57 | index_t snumber; /*+ The number of super-segments. +*/ |
58 | index_t nnumber; /*+ The number of normal segments. +*/ |
59 | } |
60 | SegmentsFile; |
61 | |
62 | |
63 | /*+ A structure containing a set of segments (and pointers to mmap file). +*/ |
64 | struct _Segments |
65 | { |
66 | SegmentsFile file; /*+ The header data from the file. +*/ |
67 | |
68 | #if !SLIM |
69 | |
70 | void *data; /*+ The memory mapped data. +*/ |
71 | |
72 | Segment *segments; /*+ An array of segments. +*/ |
73 | |
74 | #else |
75 | |
76 | int fd; /*+ The file descriptor for the file. +*/ |
77 | |
78 | Segment cached[3]; /*+ Three cached segments read from the file in slim mode. +*/ |
79 | index_t incache[3]; /*+ The indexes of the cached segments. +*/ |
80 | |
81 | #endif |
82 | }; |
83 | |
84 | |
85 | /* Functions in segments.c */ |
86 | |
87 | Segments *LoadSegmentList(const char *filename); |
88 | |
89 | Segment *NextSegment(Segments *segments,Segment *segment,index_t node); |
90 | |
91 | index_t FindClosestSegmentHeading(Nodes *nodes,Segments *segments,Ways *ways,index_t node1,double heading,Profile *profile); |
92 | |
93 | distance_t Distance(double lat1,double lon1,double lat2,double lon2); |
94 | |
95 | duration_t Duration(Segment *segment,Way *way,Profile *profile); |
96 | |
97 | double TurnAngle(Nodes *nodes,Segment *segment1,Segment *segment2,index_t node); |
98 | double BearingAngle(Nodes *nodes,Segment *segment,index_t node); |
99 | |
100 | |
101 | /* Macros and inline functions */ |
102 | |
103 | /*+ Return true if this is a normal segment. +*/ |
104 | #define IsNormalSegment(xxx) (((xxx)->distance)&SEGMENT_NORMAL) |
105 | |
106 | /*+ Return true if this is a super-segment. +*/ |
107 | #define IsSuperSegment(xxx) (((xxx)->distance)&SEGMENT_SUPER) |
108 | |
109 | /*+ Return true if the segment is oneway towards the specified node. +*/ |
110 | #define IsOnewayTo(xxx,yyy) ((xxx)->node1==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2)) |
111 | |
112 | /*+ Return true if the segment is oneway from the specified node. +*/ |
113 | #define IsOnewayFrom(xxx,yyy) ((xxx)->node2==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2)) |
114 | |
115 | /*+ Return the other node in the segment that is not the specified node. +*/ |
116 | #define OtherNode(xxx,yyy) ((xxx)->node1==(yyy)?(xxx)->node2:(xxx)->node1) |
117 | |
118 | |
119 | #if !SLIM |
120 | |
121 | /*+ Return a segment pointer given a set of segments and an index. +*/ |
122 | #define LookupSegment(xxx,yyy,zzz) (&(xxx)->segments[yyy]) |
123 | |
124 | /*+ Return a segment index given a set of segments and a pointer. +*/ |
125 | #define IndexSegment(xxx,yyy) ((yyy)-&(xxx)->segments[0]) |
126 | |
127 | #else |
128 | |
129 | static Segment *LookupSegment(Segments *segments,index_t index,int position); |
130 | |
131 | static index_t IndexSegment(Segments *segments,Segment *segment); |
132 | |
133 | |
134 | /*++++++++++++++++++++++++++++++++++++++ |
135 | Find the Segment information for a particular segment. |
136 | |
137 | Segment *LookupSegment Returns a pointer to the cached segment information. |
138 | |
139 | Segments *segments The set of segments to use. |
140 | |
141 | index_t index The index of the segment. |
142 | |
143 | int position The position in the cache to store the value. |
144 | ++++++++++++++++++++++++++++++++++++++*/ |
145 | |
146 | static inline Segment *LookupSegment(Segments *segments,index_t index,int position) |
147 | { |
148 | if(segments->incache[position-1]!=index) |
149 | { |
150 | SeekFile(segments->fd,sizeof(SegmentsFile)+(off_t)index*sizeof(Segment)); |
151 | |
152 | ReadFile(segments->fd,&segments->cached[position-1],sizeof(Segment)); |
153 | |
154 | segments->incache[position-1]=index; |
155 | } |
156 | |
157 | return(&segments->cached[position-1]); |
158 | } |
159 | |
160 | |
161 | /*++++++++++++++++++++++++++++++++++++++ |
162 | Find the segment index for a particular segment pointer. |
163 | |
164 | index_t IndexSegment Returns the index of the segment in the list. |
165 | |
166 | Segments *segments The set of segments to use. |
167 | |
168 | Segment *segment The segment whose index is to be found. |
169 | ++++++++++++++++++++++++++++++++++++++*/ |
170 | |
171 | static inline index_t IndexSegment(Segments *segments,Segment *segment) |
172 | { |
173 | int position1=segment-&segments->cached[0]; |
174 | |
175 | return(segments->incache[position1]); |
176 | } |
177 | |
178 | #endif |
179 | |
180 | |
181 | #endif /* SEGMENTS_H */ |
Properties
Name | Value |
---|---|
cvs:description | Header file for segments. |