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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1739 - (show annotations) (download) (as text)
Fri Jul 10 18:59:01 2015 UTC (9 years, 8 months ago) by amb
File MIME type: text/x-chdr
File size: 5184 byte(s)
Clarify the comments surrounding the definition of the slim mode cache
data structures.

1 /***************************************
2 A header file for the extended Ways structure.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2015 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 WAYSX_H
24 #define WAYSX_H /*+ To stop multiple inclusions. +*/
25
26 #include <stdint.h>
27
28 #include "types.h"
29 #include "ways.h"
30
31 #include "typesx.h"
32
33 #include "cache.h"
34 #include "files.h"
35
36
37 /* Data structures */
38
39
40 /*+ An extended structure containing a single way. +*/
41 struct _WayX
42 {
43 way_t id; /*+ The way identifier; initially the OSM value, later the Way index. +*/
44
45 Way way; /*+ The real way data. +*/
46 };
47
48
49 /*+ A structure containing a set of ways (memory format). +*/
50 struct _WaysX
51 {
52 char *filename; /*+ The name of the intermediate file (for the WaysX). +*/
53 char *filename_tmp; /*+ The name of the temporary file (for the WaysX). +*/
54
55 int fd; /*+ The file descriptor of the open file (for the WaysX). +*/
56
57 index_t number; /*+ The number of extended ways still being considered. +*/
58 index_t knumber; /*+ The number of extended ways kept for next time. +*/
59
60 transports_t allow; /*+ The types of traffic that were seen when parsing. +*/
61
62 #if !SLIM
63
64 WayX *data; /*+ The extended ways data (when mapped into memory). +*/
65
66 #else
67
68 WayX cached[3]; /*+ Three cached extended ways read from the file in slim mode. +*/
69 index_t incache[3]; /*+ The indexes of the cached extended ways. +*/
70
71 WayXCache *cache; /*+ A RAM cache of extended ways read from the file. +*/
72
73 #endif
74
75 way_t *idata; /*+ The extended way IDs (sorted by ID). +*/
76 off_t *odata; /*+ The offset of the way in the file (used for error log). +*/
77
78 index_t *cdata; /*+ The compacted way IDs (same order as sorted ways). +*/
79
80 char *nfilename_tmp; /*+ The name of the temporary file (for the WaysX names). +*/
81
82 int nfd; /*+ The file descriptor of the temporary file (for the WaysX names). +*/
83
84 uint32_t nlength; /*+ The length of the string of name entries. +*/
85 };
86
87
88 /* Functions in waysx.c */
89
90
91 WaysX *NewWayList(int append,int readonly);
92 void FreeWayList(WaysX *waysx,int keep);
93
94 void AppendWayList(WaysX *waysx,way_t id,Way *way,node_t *nodes,int nnodes,const char *name);
95 void FinishWayList(WaysX *waysx);
96
97 index_t IndexWayX(WaysX *waysx,way_t id);
98
99 void SortWayList(WaysX *waysx);
100
101 SegmentsX *SplitWays(WaysX *waysx,NodesX *nodesx,int keep);
102
103 void SortWayNames(WaysX *waysx);
104
105 void CompactWayList(WaysX *waysx,SegmentsX *segmentsx);
106
107 void SaveWayList(WaysX *waysx,const char *filename);
108
109
110 /* Macros / inline functions */
111
112 #if !SLIM
113
114 #define LookupWayX(waysx,index,position) &(waysx)->data[index]
115
116 #define PutBackWayX(waysx,wayx) while(0) { /* nop */ }
117
118 #else
119
120 /* Prototypes */
121
122 static inline WayX *LookupWayX(WaysX *waysx,index_t index,int position);
123
124 static inline void PutBackWayX(WaysX *waysx,WayX *wayx);
125
126 CACHE_NEWCACHE_PROTO(WayX)
127 CACHE_DELETECACHE_PROTO(WayX)
128 CACHE_FETCHCACHE_PROTO(WayX)
129 CACHE_REPLACECACHE_PROTO(WayX)
130 CACHE_INVALIDATECACHE_PROTO(WayX)
131
132 /* Data type */
133
134 CACHE_STRUCTURE(WayX)
135
136 /* Inline functions */
137
138 CACHE_NEWCACHE(WayX)
139 CACHE_DELETECACHE(WayX)
140 CACHE_FETCHCACHE(WayX)
141 CACHE_REPLACECACHE(WayX)
142 CACHE_INVALIDATECACHE(WayX)
143
144
145 /*++++++++++++++++++++++++++++++++++++++
146 Lookup a particular extended way with the specified id from the file on disk.
147
148 WayX *LookupWayX Returns a pointer to a cached copy of the extended way.
149
150 WaysX *waysx The set of ways to use.
151
152 index_t index The way index to look for.
153
154 int position The position in the cache to use.
155 ++++++++++++++++++++++++++++++++++++++*/
156
157 static inline WayX *LookupWayX(WaysX *waysx,index_t index,int position)
158 {
159 waysx->cached[position-1]=*FetchCachedWayX(waysx->cache,index,waysx->fd,0);
160
161 waysx->incache[position-1]=index;
162
163 return(&waysx->cached[position-1]);
164 }
165
166
167 /*++++++++++++++++++++++++++++++++++++++
168 Put back an extended way's data into the file on disk.
169
170 WaysX *waysx The set of ways to use.
171
172 WayX *wayx The extended way to be put back.
173 ++++++++++++++++++++++++++++++++++++++*/
174
175 static inline void PutBackWayX(WaysX *waysx,WayX *wayx)
176 {
177 int position1=wayx-&waysx->cached[0];
178
179 ReplaceCachedWayX(waysx->cache,wayx,waysx->incache[position1],waysx->fd,0);
180 }
181
182 #endif /* SLIM */
183
184
185 #endif /* WAYSX_H */

Properties

Name Value
cvs:description Extended ways header.