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 1432 - (show annotations) (download) (as text)
Fri Jun 28 14:41:56 2013 UTC (11 years, 8 months ago) by amb
File MIME type: text/x-chdr
File size: 7133 byte(s)
Keep the next2 pointer in memory while pruning rather than in the segmentx
object.

1 /***************************************
2 A header file for the extended segments.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2013 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 "cache.h"
33 #include "files.h"
34
35
36 /* Data structures */
37
38
39 /*+ An extended structure used for processing. +*/
40 struct _SegmentX
41 {
42 index_t node1; /*+ The NodeX index of the starting node. +*/
43 index_t node2; /*+ The NodeX index of the finishing node. +*/
44
45 index_t next2; /*+ The index of the next segment with the same node2. +*/
46
47 index_t way; /*+ The WayX index of the way. +*/
48
49 distance_t distance; /*+ The distance between the nodes. +*/
50 };
51
52
53 /*+ A structure containing a set of segments (memory format). +*/
54 struct _SegmentsX
55 {
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 SegmentXCache *cache; /*+ A RAM cache of extended segments read from the file. +*/
72
73 #endif
74
75 index_t *firstnode; /*+ The first segment index for each node. +*/
76
77 index_t *next1; /*+ The index of the next segment with the same node1 (used while pruning). +*/
78 index_t *next2; /*+ The index of the next segment with the same node2 (used while pruning). +*/
79
80 BitMask *usedway; /*+ A flag to indicate if a way is used (used for removing pruned ways). +*/
81 };
82
83
84 /* Functions in segmentsx.c */
85
86 SegmentsX *NewSegmentList(void);
87 void FreeSegmentList(SegmentsX *segmentsx);
88
89 void AppendSegmentList(SegmentsX *segmentsx,index_t way,index_t node1,index_t node2,distance_t distance);
90 void FinishSegmentList(SegmentsX *segmentsx);
91
92 SegmentX *FirstSegmentX(SegmentsX *segmentsx,index_t nodeindex,int position);
93 SegmentX *NextSegmentX(SegmentsX *segmentsx,SegmentX *segmentx,index_t nodeindex);
94
95 void SortSegmentList(SegmentsX *segmentsx);
96
97 void IndexSegments(SegmentsX *segmentsx,NodesX *nodesx,WaysX *waysx);
98
99 void ProcessSegments(SegmentsX *segmentsx,NodesX *nodesx,WaysX *waysx);
100
101 void RemovePrunedSegments(SegmentsX *segmentsx,WaysX *waysx);
102
103 void DeduplicateSuperSegments(SegmentsX *segmentsx,WaysX *waysx);
104
105 void SortSegmentListGeographically(SegmentsX *segmentsx,NodesX *nodesx);
106
107 void SaveSegmentList(SegmentsX *segmentsx,const char *filename);
108
109
110 /* Macros / inline functions */
111
112 /*+ Return true if this is a pruned segment. +*/
113 #define IsPrunedSegmentX(xxx) ((xxx)->node1==NO_NODE)
114
115
116 #if !SLIM
117
118 #define LookupSegmentX(segmentsx,index,position) &(segmentsx)->data[index]
119
120 #define IndexSegmentX(segmentsx,segmentx) (index_t)((segmentx)-&(segmentsx)->data[0])
121
122 #define PutBackSegmentX(segmentsx,segmentx) while(0) { /* nop */ }
123
124 #define ReLookupSegmentX(segmentsx,segmentx) while(0) { /* nop */ }
125
126 #else
127
128 /* Prototypes */
129
130 static inline SegmentX *LookupSegmentX(SegmentsX *segmentsx,index_t index,int position);
131
132 static inline index_t IndexSegmentX(SegmentsX *segmentsx,SegmentX *segmentx);
133
134 static inline void PutBackSegmentX(SegmentsX *segmentsx,SegmentX *segmentx);
135
136 static inline void ReLookupSegmentX(SegmentsX *segmentsx,SegmentX *segmentx);
137
138 CACHE_NEWCACHE_PROTO(SegmentX)
139 CACHE_DELETECACHE_PROTO(SegmentX)
140 CACHE_FETCHCACHE_PROTO(SegmentX)
141 CACHE_REPLACECACHE_PROTO(SegmentX)
142 CACHE_INVALIDATECACHE_PROTO(SegmentX)
143
144
145 /* Inline functions */
146
147 CACHE_STRUCTURE(SegmentX)
148 CACHE_NEWCACHE(SegmentX)
149 CACHE_DELETECACHE(SegmentX)
150 CACHE_FETCHCACHE(SegmentX)
151 CACHE_REPLACECACHE(SegmentX)
152 CACHE_INVALIDATECACHE(SegmentX)
153
154
155 /*++++++++++++++++++++++++++++++++++++++
156 Lookup a particular extended segment with the specified id from the file on disk.
157
158 SegmentX *LookupSegmentX Returns a pointer to a cached copy of the extended segment.
159
160 SegmentsX *segmentsx The set of segments to use.
161
162 index_t index The segment index to look for.
163
164 int position The position in the cache to use.
165 ++++++++++++++++++++++++++++++++++++++*/
166
167 static inline SegmentX *LookupSegmentX(SegmentsX *segmentsx,index_t index,int position)
168 {
169 segmentsx->cached[position-1]=*FetchCachedSegmentX(segmentsx->cache,index,segmentsx->fd,0);
170
171 segmentsx->incache[position-1]=index;
172
173 return(&segmentsx->cached[position-1]);
174 }
175
176
177 /*++++++++++++++++++++++++++++++++++++++
178 Find the extended segment index for a particular extended segment pointer.
179
180 index_t IndexSegmentX Returns the index of the extended segment.
181
182 SegmentsX *segmentsx The set of segments to use.
183
184 SegmentX *segmentx The extended segment whose index is to be found.
185 ++++++++++++++++++++++++++++++++++++++*/
186
187 static inline index_t IndexSegmentX(SegmentsX *segmentsx,SegmentX *segmentx)
188 {
189 int position1=segmentx-&segmentsx->cached[0];
190
191 return(segmentsx->incache[position1]);
192 }
193
194
195 /*++++++++++++++++++++++++++++++++++++++
196 Put back an extended segment's data into the file on disk.
197
198 SegmentsX *segmentsx The set of segments to use.
199
200 SegmentX *segmentx The extended segment to be put back.
201 ++++++++++++++++++++++++++++++++++++++*/
202
203 static inline void PutBackSegmentX(SegmentsX *segmentsx,SegmentX *segmentx)
204 {
205 int position1=segmentx-&segmentsx->cached[0];
206
207 ReplaceCachedSegmentX(segmentsx->cache,segmentx,segmentsx->incache[position1],segmentsx->fd,0);
208 }
209
210
211 /*++++++++++++++++++++++++++++++++++++++
212 Lookup an extended segment's data from the disk into file again after the disk was updated.
213
214 SegmentsX *segmentsx The set of segments to use.
215
216 SegmentX *segmentx The extended segment to refresh.
217 ++++++++++++++++++++++++++++++++++++++*/
218
219 static inline void ReLookupSegmentX(SegmentsX *segmentsx,SegmentX *segmentx)
220 {
221 int position1=segmentx-&segmentsx->cached[0];
222
223 segmentsx->cached[position1]=*FetchCachedSegmentX(segmentsx->cache,segmentsx->incache[position1],segmentsx->fd,0);
224 }
225
226 #endif /* SLIM */
227
228
229 #endif /* SEGMENTSX_H */

Properties

Name Value
cvs:description Extended segments header.