Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Annotation of /trunk/src/segmentsx.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1121 - (hide annotations) (download) (as text)
Fri Nov 2 19:51:17 2012 UTC (12 years, 4 months ago) by amb
File MIME type: text/x-chdr
File size: 7001 byte(s)
Fix a bug which gave different results for slim mode and normal mode when
pruning short segments.

1 amb 110 /***************************************
2     A header file for the extended segments.
3 amb 151
4     Part of the Routino routing software.
5 amb 110 ******************/ /******************
6 amb 949 This file Copyright 2008-2012 Andrew M. Bishop
7 amb 110
8 amb 151 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 amb 110 ***************************************/
21    
22    
23     #ifndef SEGMENTSX_H
24     #define SEGMENTSX_H /*+ To stop multiple inclusions. +*/
25    
26     #include <stdint.h>
27    
28 amb 449 #include "types.h"
29 amb 448
30 amb 199 #include "typesx.h"
31 amb 110
32 amb 451 #include "files.h"
33 amb 110
34 amb 451
35 amb 110 /* Data structures */
36    
37    
38     /*+ An extended structure used for processing. +*/
39     struct _SegmentX
40     {
41 amb 539 node_t node1; /*+ The id of the starting node; initially the OSM value, later the NodeX index. +*/
42     node_t node2; /*+ The id of the finishing node; initially the OSM value, later the NodeX index. +*/
43 amb 110
44 amb 643 index_t next2; /*+ The index of the next segment with the same node2. +*/
45    
46 amb 539 way_t way; /*+ The id of the way; initially the OSM value, later the WayX index. +*/
47 amb 203
48 amb 209 distance_t distance; /*+ The distance between the nodes. +*/
49 amb 110 };
50    
51    
52     /*+ A structure containing a set of segments (memory format). +*/
53     struct _SegmentsX
54     {
55 amb 1120 char *filename; /*+ The name of the intermediate file (for the SegmentsX). +*/
56     char *filename_tmp; /*+ The name of the temporary file (for the SegmentsX). +*/
57 amb 216
58 amb 1120 int fd; /*+ The file descriptor of the open file (for the SegmentsX). +*/
59    
60 amb 651 index_t number; /*+ The number of extended segments still being considered. +*/
61 amb 216
62 amb 452 #if !SLIM
63    
64 amb 651 SegmentX *data; /*+ The extended segment data (when mapped into memory). +*/
65 amb 256
66 amb 452 #else
67    
68 amb 964 SegmentX cached[4]; /*+ Four cached extended segments read from the file in slim mode. +*/
69     index_t incache[4]; /*+ The indexes of the cached extended segments. +*/
70 amb 452
71     #endif
72    
73 amb 643 index_t *firstnode; /*+ The first segment index for each node. +*/
74 amb 558
75 amb 949 index_t *next1; /*+ The index of the next segment with the same node1 (used while pruning). +*/
76    
77 amb 950 BitMask *usednode; /*+ A flag to indicate if a node is used (used for removing bad segments). +*/
78 amb 1100
79     BitMask *usedway; /*+ A flag to indicate if a way is used (used for removing pruned ways). +*/
80 amb 110 };
81    
82    
83 amb 680 /* Functions in segmentsx.c */
84 amb 110
85    
86 amb 326 SegmentsX *NewSegmentList(int append);
87     void FreeSegmentList(SegmentsX *segmentsx,int keep);
88 amb 1120 void FinishSegmentList(SegmentsX *segmentsx);
89 amb 110
90     void SaveSegmentList(SegmentsX *segmentsx,const char *filename);
91    
92 amb 771 SegmentX *FirstSegmentX(SegmentsX *segmentsx,index_t nodeindex,int position);
93 amb 943 SegmentX *NextSegmentX(SegmentsX *segmentsx,SegmentX *segmentx,index_t nodeindex);
94 amb 256
95 amb 681 void AppendSegment(SegmentsX *segmentsx,way_t way,node_t node1,node_t node2,distance_t distance);
96 amb 110
97 amb 1100 void SortSegmentList(SegmentsX *segmentsx);
98 amb 110
99 amb 1107 void SortSegmentListGeographically(SegmentsX *segmentsx,NodesX *nodesx);
100    
101 amb 1100 void RemovePrunedSegments(SegmentsX *segmentsx,WaysX *waysx);
102    
103 amb 204 void RemoveBadSegments(NodesX *nodesx,SegmentsX *segmentsx);
104 amb 110
105 amb 644 void MeasureSegments(SegmentsX *segmentsx,NodesX *nodesx,WaysX *waysx);
106 amb 110
107 amb 681 void DeduplicateSegments(SegmentsX *segmentsx,NodesX *nodesx,WaysX *waysx);
108 amb 110
109 amb 209 void CreateRealSegments(SegmentsX *segmentsx,WaysX *waysx);
110    
111 amb 1100 void IndexSegments(SegmentsX *segmentsx,NodesX *nodesx,WaysX *waysx);
112 amb 110
113    
114 amb 452 /* Macros / inline functions */
115 amb 451
116 amb 949 /*+ Return true if this is a pruned segment. +*/
117     #define IsPrunedSegmentX(xxx) ((xxx)->node1==NO_NODE)
118 amb 451
119 amb 949
120 amb 452 #if !SLIM
121    
122 amb 651 #define LookupSegmentX(segmentsx,index,position) &(segmentsx)->data[index]
123 amb 452
124 amb 788 #define IndexSegmentX(segmentsx,segmentx) (index_t)((segmentx)-&(segmentsx)->data[0])
125 amb 557
126 amb 942 #define PutBackSegmentX(segmentsx,segmentx) /* nop */
127 amb 1121
128     #define ReLookupSegmentX(segmentsx,segmentx) /* nop */
129 amb 643
130 amb 452 #else
131    
132 amb 681 static SegmentX *LookupSegmentX(SegmentsX *segmentsx,index_t index,int position);
133 amb 452
134 amb 643 static index_t IndexSegmentX(SegmentsX *segmentsx,SegmentX *segmentx);
135 amb 452
136 amb 942 static void PutBackSegmentX(SegmentsX *segmentsx,SegmentX *segmentx);
137 amb 452
138 amb 1121 static void ReLookupSegmentX(SegmentsX *segmentsx,SegmentX *segmentx);
139 amb 452
140 amb 1121
141 amb 451 /*++++++++++++++++++++++++++++++++++++++
142 amb 680 Lookup a particular extended segment with the specified id from the file on disk.
143 amb 451
144 amb 680 SegmentX *LookupSegmentX Returns a pointer to a cached copy of the extended segment.
145 amb 451
146 amb 681 SegmentsX *segmentsx The set of segments to use.
147 amb 451
148     index_t index The segment index to look for.
149    
150     int position The position in the cache to use.
151     ++++++++++++++++++++++++++++++++++++++*/
152    
153 amb 681 static inline SegmentX *LookupSegmentX(SegmentsX *segmentsx,index_t index,int position)
154 amb 451 {
155 amb 887 SeekReadFile(segmentsx->fd,&segmentsx->cached[position-1],sizeof(SegmentX),(off_t)index*sizeof(SegmentX));
156 amb 451
157 amb 643 segmentsx->incache[position-1]=index;
158    
159     return(&segmentsx->cached[position-1]);
160 amb 451 }
161    
162    
163     /*++++++++++++++++++++++++++++++++++++++
164 amb 643 Find the extended segment index for a particular extended segment pointer.
165 amb 451
166 amb 680 index_t IndexSegmentX Returns the index of the extended segment.
167 amb 451
168 amb 681 SegmentsX *segmentsx The set of segments to use.
169 amb 451
170 amb 643 SegmentX *segmentx The extended segment whose index is to be found.
171 amb 451 ++++++++++++++++++++++++++++++++++++++*/
172    
173 amb 643 static inline index_t IndexSegmentX(SegmentsX *segmentsx,SegmentX *segmentx)
174 amb 451 {
175 amb 704 int position1=segmentx-&segmentsx->cached[0];
176 amb 451
177 amb 704 return(segmentsx->incache[position1]);
178 amb 451 }
179    
180    
181     /*++++++++++++++++++++++++++++++++++++++
182 amb 680 Put back an extended segment's data into the file on disk.
183 amb 451
184 amb 681 SegmentsX *segmentsx The set of segments to use.
185 amb 451
186 amb 942 SegmentX *segmentx The extended segment to be put back.
187 amb 451 ++++++++++++++++++++++++++++++++++++++*/
188    
189 amb 942 static inline void PutBackSegmentX(SegmentsX *segmentsx,SegmentX *segmentx)
190 amb 451 {
191 amb 942 int position1=segmentx-&segmentsx->cached[0];
192    
193     SeekWriteFile(segmentsx->fd,&segmentsx->cached[position1],sizeof(SegmentX),(off_t)segmentsx->incache[position1]*sizeof(SegmentX));
194 amb 451 }
195    
196 amb 1121
197     /*++++++++++++++++++++++++++++++++++++++
198     Lookup an extended segment's data from the disk into file again after the disk was updated.
199    
200     SegmentsX *segmentsx The set of segments to use.
201    
202     SegmentX *segmentx The extended segment to refresh.
203     ++++++++++++++++++++++++++++++++++++++*/
204    
205     static inline void ReLookupSegmentX(SegmentsX *segmentsx,SegmentX *segmentx)
206     {
207     int position1=segmentx-&segmentsx->cached[0];
208    
209     SeekReadFile(segmentsx->fd,&segmentsx->cached[position1],sizeof(SegmentX),(off_t)segmentsx->incache[position1]*sizeof(SegmentX));
210     }
211    
212 amb 452 #endif /* SLIM */
213 amb 451
214 amb 452
215 amb 110 #endif /* SEGMENTSX_H */

Properties

Name Value
cvs:description Extended segments header.