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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1140 - (show annotations) (download) (as text)
Fri Nov 16 18:47:07 2012 UTC (12 years, 4 months ago) by amb
File MIME type: text/x-chdr
File size: 7083 byte(s)
Code to allow adding OSC change files (.osc files) to an existing set of parsed
(and preserved) data.

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

Properties

Name Value
cvs:description Extended segments header.