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 1428 - (show annotations) (download) (as text)
Thu Jun 27 18:29:33 2013 UTC (11 years, 8 months ago) by amb
File MIME type: text/x-chdr
File size: 6999 byte(s)
Put the next1 pointer in the segmentx object rather than in-memory.

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

Properties

Name Value
cvs:description Extended segments header.