Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/segments.h
Parent Directory
|
Revision Log
Revision 465 -
(hide annotations)
(download)
(as text)
Sat Jul 31 14:36:15 2010 UTC (14 years, 7 months ago) by amb
File MIME type: text/x-chdr
File size: 5286 byte(s)
Sat Jul 31 14:36:15 2010 UTC (14 years, 7 months ago) by amb
File MIME type: text/x-chdr
File size: 5286 byte(s)
Change the data types to index_t where they are counting nodes/segments/ways.
1 | amb | 24 | /*************************************** |
2 | amb | 465 | $Header: /home/amb/CVS/routino/src/segments.h,v 1.37 2010-07-31 14:36:15 amb Exp $ |
3 | amb | 24 | |
4 | A header file for the segments. | ||
5 | amb | 151 | |
6 | Part of the Routino routing software. | ||
7 | amb | 24 | ******************/ /****************** |
8 | amb | 459 | This file Copyright 2008-2010 Andrew M. Bishop |
9 | amb | 24 | |
10 | amb | 151 | 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 | amb | 24 | ***************************************/ |
23 | |||
24 | |||
25 | #ifndef SEGMENTS_H | ||
26 | #define SEGMENTS_H /*+ To stop multiple inclusions. +*/ | ||
27 | |||
28 | #include <stdint.h> | ||
29 | |||
30 | amb | 96 | #include "types.h" |
31 | amb | 459 | |
32 | #include "files.h" | ||
33 | amb | 82 | #include "profiles.h" |
34 | amb | 24 | |
35 | amb | 26 | |
36 | amb | 24 | /* Data structures */ |
37 | |||
38 | |||
39 | amb | 109 | /*+ A structure containing a single segment. +*/ |
40 | struct _Segment | ||
41 | amb | 88 | { |
42 | amb | 109 | index_t node1; /*+ The index of the starting node. +*/ |
43 | index_t node2; /*+ The index of the finishing node. +*/ | ||
44 | amb | 88 | |
45 | amb | 109 | index_t next2; /*+ The index of the next segment sharing node2. +*/ |
46 | amb | 88 | |
47 | amb | 109 | 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 | amb | 459 | /*+ A structure containing the header from the file. +*/ |
54 | typedef struct _SegmentsFile | ||
55 | amb | 24 | { |
56 | amb | 465 | index_t number; /*+ How many segments in total? +*/ |
57 | index_t snumber; /*+ How many super-segments? +*/ | ||
58 | index_t nnumber; /*+ How many normal segments? +*/ | ||
59 | amb | 459 | } |
60 | SegmentsFile; | ||
61 | amb | 88 | |
62 | |||
63 | amb | 459 | /*+ 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]; /*+ The cached segments. +*/ | ||
79 | index_t incache[3]; /*+ The indexes of the cached segments. +*/ | ||
80 | |||
81 | #endif | ||
82 | amb | 109 | }; |
83 | amb | 24 | |
84 | |||
85 | amb | 459 | /* Functions */ |
86 | amb | 24 | |
87 | amb | 459 | Segments *LoadSegmentList(const char *filename); |
88 | amb | 24 | |
89 | amb | 459 | Segment *NextSegment(Segments* segments,Segment *segment,index_t node); |
90 | amb | 24 | |
91 | amb | 459 | distance_t Distance(double lat1,double lon1,double lat2,double lon2); |
92 | amb | 303 | |
93 | amb | 459 | duration_t Duration(Segment *segment,Way *way,Profile *profile); |
94 | |||
95 | |||
96 | /* Macros and inline functions */ | ||
97 | |||
98 | amb | 109 | /*+ Return true if this is a normal segment. +*/ |
99 | amb | 208 | #define IsNormalSegment(xxx) (((xxx)->distance)&SEGMENT_NORMAL) |
100 | amb | 24 | |
101 | amb | 109 | /*+ Return true if this is a super-segment. +*/ |
102 | amb | 208 | #define IsSuperSegment(xxx) (((xxx)->distance)&SEGMENT_SUPER) |
103 | amb | 24 | |
104 | amb | 109 | /*+ Return true if the segment is oneway towards the specified node. +*/ |
105 | amb | 208 | #define IsOnewayTo(xxx,yyy) ((xxx)->node1==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2)) |
106 | amb | 24 | |
107 | amb | 109 | /*+ Return true if the segment is oneway from the specified node. +*/ |
108 | amb | 208 | #define IsOnewayFrom(xxx,yyy) ((xxx)->node2==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2)) |
109 | amb | 97 | |
110 | amb | 109 | /*+ Return the other node in the segment that is not the specified node. +*/ |
111 | amb | 208 | #define OtherNode(xxx,yyy) ((xxx)->node1==(yyy)?(xxx)->node2:(xxx)->node1) |
112 | amb | 97 | |
113 | amb | 24 | |
114 | amb | 459 | #if !SLIM |
115 | amb | 39 | |
116 | amb | 459 | /*+ Return a segment pointer given a set of segments and an index. +*/ |
117 | #define LookupSegment(xxx,yyy,zzz) (&(xxx)->segments[yyy]) | ||
118 | amb | 24 | |
119 | amb | 459 | /*+ Return a segment index given a set of segments and a pointer. +*/ |
120 | #define IndexSegment(xxx,yyy) ((yyy)-&(xxx)->segments[0]) | ||
121 | amb | 88 | |
122 | amb | 459 | #else |
123 | amb | 88 | |
124 | amb | 459 | static Segment *LookupSegment(Segments *segments,index_t index,int position); |
125 | amb | 99 | |
126 | amb | 459 | static index_t IndexSegment(Segments *segments,Segment *segment); |
127 | amb | 63 | |
128 | amb | 32 | |
129 | amb | 459 | /*++++++++++++++++++++++++++++++++++++++ |
130 | Find the Segment information for a particular segment. | ||
131 | |||
132 | Segment *LookupSegment Returns a pointer to the cached segment information. | ||
133 | |||
134 | Segments *segments The segments structure to use. | ||
135 | |||
136 | index_t index The index of the segment. | ||
137 | |||
138 | int position The position in the cache to store the value. | ||
139 | ++++++++++++++++++++++++++++++++++++++*/ | ||
140 | |||
141 | static inline Segment *LookupSegment(Segments *segments,index_t index,int position) | ||
142 | { | ||
143 | amb | 464 | SeekFile(segments->fd,sizeof(SegmentsFile)+(off_t)index*sizeof(Segment)); |
144 | amb | 459 | |
145 | ReadFile(segments->fd,&segments->cached[position-1],sizeof(Segment)); | ||
146 | |||
147 | segments->incache[position-1]=index; | ||
148 | |||
149 | return(&segments->cached[position-1]); | ||
150 | } | ||
151 | |||
152 | |||
153 | /*++++++++++++++++++++++++++++++++++++++ | ||
154 | Find the segment index for a particular segment pointer. | ||
155 | |||
156 | index_t IndexSegment Returns the index of the segment in the list. | ||
157 | |||
158 | Segments *segments The segments structure to use. | ||
159 | |||
160 | Segment *segment The segment whose index is to be found. | ||
161 | ++++++++++++++++++++++++++++++++++++++*/ | ||
162 | |||
163 | static inline index_t IndexSegment(Segments *segments,Segment *segment) | ||
164 | { | ||
165 | int i; | ||
166 | |||
167 | for(i=0;i<sizeof(segments->cached)/sizeof(segments->cached[0]);i++) | ||
168 | if(&segments->cached[i]==segment) | ||
169 | return(segments->incache[i]); | ||
170 | |||
171 | return(NO_SEGMENT); | ||
172 | } | ||
173 | |||
174 | #endif | ||
175 | |||
176 | |||
177 | amb | 24 | #endif /* SEGMENTS_H */ |
Properties
Name | Value |
---|---|
cvs:description | Header file for segments. |