Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Annotation of /trunk/src/segmentsx.h
Parent Directory
|
Revision Log
Revision 1297 -
(hide annotations)
(download)
(as text)
Tue May 7 14:41:11 2013 UTC (11 years, 11 months ago) by amb
File MIME type: text/x-chdr
File size: 7476 byte(s)
Tue May 7 14:41:11 2013 UTC (11 years, 11 months ago) by amb
File MIME type: text/x-chdr
File size: 7476 byte(s)
Add cache functions for NodesX, SegmentsX and WaysX to speed up the planetsplitter in slim mode.
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 | 1297 | This file Copyright 2008-2013 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 | 1297 | #include "cache.h" |
33 | amb | 451 | #include "files.h" |
34 | amb | 110 | |
35 | amb | 451 | |
36 | amb | 110 | /* Data structures */ |
37 | |||
38 | |||
39 | /*+ An extended structure used for processing. +*/ | ||
40 | struct _SegmentX | ||
41 | { | ||
42 | amb | 539 | node_t node1; /*+ The id of the starting node; initially the OSM value, later the NodeX index. +*/ |
43 | node_t node2; /*+ The id of the finishing node; initially the OSM value, later the NodeX index. +*/ | ||
44 | amb | 110 | |
45 | amb | 643 | index_t next2; /*+ The index of the next segment with the same node2. +*/ |
46 | |||
47 | amb | 539 | way_t way; /*+ The id of the way; initially the OSM value, later the WayX index. +*/ |
48 | amb | 203 | |
49 | amb | 1168 | distance_t distance; /*+ The distance between the nodes. +*/ |
50 | amb | 110 | }; |
51 | |||
52 | |||
53 | /*+ A structure containing a set of segments (memory format). +*/ | ||
54 | struct _SegmentsX | ||
55 | { | ||
56 | amb | 1120 | char *filename; /*+ The name of the intermediate file (for the SegmentsX). +*/ |
57 | char *filename_tmp; /*+ The name of the temporary file (for the SegmentsX). +*/ | ||
58 | amb | 216 | |
59 | amb | 1120 | int fd; /*+ The file descriptor of the open file (for the SegmentsX). +*/ |
60 | |||
61 | amb | 651 | index_t number; /*+ The number of extended segments still being considered. +*/ |
62 | amb | 216 | |
63 | amb | 452 | #if !SLIM |
64 | |||
65 | amb | 651 | SegmentX *data; /*+ The extended segment data (when mapped into memory). +*/ |
66 | amb | 256 | |
67 | amb | 452 | #else |
68 | |||
69 | amb | 964 | SegmentX cached[4]; /*+ Four cached extended segments read from the file in slim mode. +*/ |
70 | index_t incache[4]; /*+ The indexes of the cached extended segments. +*/ | ||
71 | amb | 452 | |
72 | amb | 1297 | SegmentXCache *cache; /*+ A RAM cache of extended segments read from the file. +*/ |
73 | |||
74 | amb | 452 | #endif |
75 | |||
76 | amb | 643 | index_t *firstnode; /*+ The first segment index for each node. +*/ |
77 | amb | 558 | |
78 | amb | 949 | index_t *next1; /*+ The index of the next segment with the same node1 (used while pruning). +*/ |
79 | |||
80 | amb | 950 | BitMask *usednode; /*+ A flag to indicate if a node is used (used for removing bad segments). +*/ |
81 | amb | 1100 | |
82 | BitMask *usedway; /*+ A flag to indicate if a way is used (used for removing pruned ways). +*/ | ||
83 | amb | 110 | }; |
84 | |||
85 | |||
86 | amb | 680 | /* Functions in segmentsx.c */ |
87 | amb | 110 | |
88 | amb | 1123 | SegmentsX *NewSegmentList(int append,int readonly); |
89 | amb | 1167 | void FreeSegmentList(SegmentsX *segmentsx,int keep); |
90 | amb | 110 | |
91 | amb | 1168 | void AppendSegmentList(SegmentsX *segmentsx,way_t way,node_t node1,node_t node2,distance_t distance); |
92 | amb | 1151 | void FinishSegmentList(SegmentsX *segmentsx); |
93 | |||
94 | amb | 771 | SegmentX *FirstSegmentX(SegmentsX *segmentsx,index_t nodeindex,int position); |
95 | amb | 943 | SegmentX *NextSegmentX(SegmentsX *segmentsx,SegmentX *segmentx,index_t nodeindex); |
96 | amb | 256 | |
97 | amb | 1140 | void ApplySegmentChanges(SegmentsX *segmentsx); |
98 | |||
99 | amb | 1100 | void SortSegmentList(SegmentsX *segmentsx); |
100 | amb | 110 | |
101 | amb | 1160 | void IndexSegments(SegmentsX *segmentsx,NodesX *nodesx,WaysX *waysx); |
102 | amb | 1107 | |
103 | amb | 1167 | void RemoveBadSegments(SegmentsX *segmentsx,NodesX *nodesx,WaysX *waysx,int keep); |
104 | amb | 110 | |
105 | amb | 644 | void MeasureSegments(SegmentsX *segmentsx,NodesX *nodesx,WaysX *waysx); |
106 | amb | 110 | |
107 | amb | 1160 | void RemovePrunedSegments(SegmentsX *segmentsx,WaysX *waysx); |
108 | |||
109 | amb | 1132 | void DeduplicateSuperSegments(SegmentsX *segmentsx,WaysX *waysx); |
110 | amb | 110 | |
111 | amb | 1160 | void SortSegmentListGeographically(SegmentsX *segmentsx,NodesX *nodesx); |
112 | amb | 209 | |
113 | amb | 1160 | void SaveSegmentList(SegmentsX *segmentsx,const char *filename); |
114 | amb | 110 | |
115 | |||
116 | amb | 452 | /* Macros / inline functions */ |
117 | amb | 451 | |
118 | amb | 949 | /*+ Return true if this is a pruned segment. +*/ |
119 | #define IsPrunedSegmentX(xxx) ((xxx)->node1==NO_NODE) | ||
120 | amb | 451 | |
121 | amb | 949 | |
122 | amb | 452 | #if !SLIM |
123 | |||
124 | amb | 651 | #define LookupSegmentX(segmentsx,index,position) &(segmentsx)->data[index] |
125 | amb | 452 | |
126 | amb | 788 | #define IndexSegmentX(segmentsx,segmentx) (index_t)((segmentx)-&(segmentsx)->data[0]) |
127 | amb | 557 | |
128 | amb | 942 | #define PutBackSegmentX(segmentsx,segmentx) /* nop */ |
129 | amb | 1121 | |
130 | #define ReLookupSegmentX(segmentsx,segmentx) /* nop */ | ||
131 | amb | 643 | |
132 | amb | 452 | #else |
133 | |||
134 | amb | 1297 | /* Prototypes */ |
135 | amb | 452 | |
136 | amb | 1297 | static inline SegmentX *LookupSegmentX(SegmentsX *segmentsx,index_t index,int position); |
137 | amb | 452 | |
138 | amb | 1297 | static inline index_t IndexSegmentX(SegmentsX *segmentsx,SegmentX *segmentx); |
139 | amb | 452 | |
140 | amb | 1297 | static inline void PutBackSegmentX(SegmentsX *segmentsx,SegmentX *segmentx); |
141 | amb | 452 | |
142 | amb | 1297 | static inline void ReLookupSegmentX(SegmentsX *segmentsx,SegmentX *segmentx); |
143 | amb | 1121 | |
144 | amb | 1297 | CACHE_NEWCACHE_PROTO(SegmentX) |
145 | CACHE_DELETECACHE_PROTO(SegmentX) | ||
146 | CACHE_FETCHCACHE_PROTO(SegmentX) | ||
147 | CACHE_REPLACECACHE_PROTO(SegmentX) | ||
148 | CACHE_INVALIDATECACHE_PROTO(SegmentX) | ||
149 | |||
150 | |||
151 | /* Inline functions */ | ||
152 | |||
153 | CACHE_STRUCTURE(SegmentX) | ||
154 | CACHE_NEWCACHE(SegmentX) | ||
155 | CACHE_DELETECACHE(SegmentX) | ||
156 | CACHE_FETCHCACHE(SegmentX) | ||
157 | CACHE_REPLACECACHE(SegmentX) | ||
158 | CACHE_INVALIDATECACHE(SegmentX) | ||
159 | |||
160 | |||
161 | amb | 451 | /*++++++++++++++++++++++++++++++++++++++ |
162 | amb | 680 | Lookup a particular extended segment with the specified id from the file on disk. |
163 | amb | 451 | |
164 | amb | 680 | SegmentX *LookupSegmentX Returns a pointer to a cached copy of the extended segment. |
165 | amb | 451 | |
166 | amb | 681 | SegmentsX *segmentsx The set of segments to use. |
167 | amb | 451 | |
168 | index_t index The segment index to look for. | ||
169 | |||
170 | int position The position in the cache to use. | ||
171 | ++++++++++++++++++++++++++++++++++++++*/ | ||
172 | |||
173 | amb | 681 | static inline SegmentX *LookupSegmentX(SegmentsX *segmentsx,index_t index,int position) |
174 | amb | 451 | { |
175 | amb | 1297 | segmentsx->cached[position-1]=*FetchCachedSegmentX(segmentsx->cache,index,segmentsx->fd,0); |
176 | amb | 451 | |
177 | amb | 643 | segmentsx->incache[position-1]=index; |
178 | |||
179 | return(&segmentsx->cached[position-1]); | ||
180 | amb | 451 | } |
181 | |||
182 | |||
183 | /*++++++++++++++++++++++++++++++++++++++ | ||
184 | amb | 643 | Find the extended segment index for a particular extended segment pointer. |
185 | amb | 451 | |
186 | amb | 680 | index_t IndexSegmentX Returns the index of the extended segment. |
187 | amb | 451 | |
188 | amb | 681 | SegmentsX *segmentsx The set of segments to use. |
189 | amb | 451 | |
190 | amb | 643 | SegmentX *segmentx The extended segment whose index is to be found. |
191 | amb | 451 | ++++++++++++++++++++++++++++++++++++++*/ |
192 | |||
193 | amb | 643 | static inline index_t IndexSegmentX(SegmentsX *segmentsx,SegmentX *segmentx) |
194 | amb | 451 | { |
195 | amb | 704 | int position1=segmentx-&segmentsx->cached[0]; |
196 | amb | 451 | |
197 | amb | 704 | return(segmentsx->incache[position1]); |
198 | amb | 451 | } |
199 | |||
200 | |||
201 | /*++++++++++++++++++++++++++++++++++++++ | ||
202 | amb | 680 | Put back an extended segment's data into the file on disk. |
203 | amb | 451 | |
204 | amb | 681 | SegmentsX *segmentsx The set of segments to use. |
205 | amb | 451 | |
206 | amb | 942 | SegmentX *segmentx The extended segment to be put back. |
207 | amb | 451 | ++++++++++++++++++++++++++++++++++++++*/ |
208 | |||
209 | amb | 942 | static inline void PutBackSegmentX(SegmentsX *segmentsx,SegmentX *segmentx) |
210 | amb | 451 | { |
211 | amb | 942 | int position1=segmentx-&segmentsx->cached[0]; |
212 | |||
213 | amb | 1297 | ReplaceCachedSegmentX(segmentsx->cache,segmentx,segmentsx->incache[position1],segmentsx->fd,0); |
214 | amb | 451 | } |
215 | |||
216 | amb | 1121 | |
217 | /*++++++++++++++++++++++++++++++++++++++ | ||
218 | Lookup an extended segment's data from the disk into file again after the disk was updated. | ||
219 | |||
220 | SegmentsX *segmentsx The set of segments to use. | ||
221 | |||
222 | SegmentX *segmentx The extended segment to refresh. | ||
223 | ++++++++++++++++++++++++++++++++++++++*/ | ||
224 | |||
225 | static inline void ReLookupSegmentX(SegmentsX *segmentsx,SegmentX *segmentx) | ||
226 | { | ||
227 | int position1=segmentx-&segmentsx->cached[0]; | ||
228 | |||
229 | amb | 1297 | segmentsx->cached[position1]=*FetchCachedSegmentX(segmentsx->cache,segmentsx->incache[position1],segmentsx->fd,0); |
230 | amb | 1121 | } |
231 | |||
232 | amb | 452 | #endif /* SLIM */ |
233 | amb | 451 | |
234 | amb | 452 | |
235 | amb | 110 | #endif /* SEGMENTSX_H */ |
Properties
Name | Value |
---|---|
cvs:description | Extended segments header. |