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 552 - (show annotations) (download) (as text)
Mon Dec 20 17:38:29 2010 UTC (14 years, 2 months ago) by amb
File MIME type: text/x-chdr
File size: 6184 byte(s)
Don't maintain a copy of the whole set of Nodes along with the NodeXs but
generate the Node from the NodeX when written to disk.  Create a lookup table
between the original index and the geographically sorted index.

1 /***************************************
2 $Header: /home/amb/CVS/routino/src/segmentsx.h,v 1.29 2010-12-20 17:38:29 amb Exp $
3
4 A header file for the extended segments.
5
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008-2010 Andrew M. Bishop
9
10 This program is free software: you can redistribute it and/or modify
11 it under the terms of the GNU Affero General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Affero General Public License for more details.
19
20 You should have received a copy of the GNU Affero General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ***************************************/
23
24
25 #ifndef SEGMENTSX_H
26 #define SEGMENTSX_H /*+ To stop multiple inclusions. +*/
27
28 #include <stdint.h>
29
30 #include "types.h"
31 #include "segments.h"
32
33 #include "typesx.h"
34
35 #include "files.h"
36
37
38 /* Data structures */
39
40
41 /*+ An extended structure used for processing. +*/
42 struct _SegmentX
43 {
44 node_t node1; /*+ The id of the starting node; initially the OSM value, later the NodeX index. +*/
45 node_t node2; /*+ The id of the finishing node; initially the OSM value, later the NodeX index. +*/
46
47 way_t way; /*+ The id of the way; initially the OSM value, later the WayX index. +*/
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; /*+ The name of the temporary file. +*/
57 int fd; /*+ The file descriptor of the temporary file. +*/
58
59 index_t xnumber; /*+ The number of unsorted extended nodes. +*/
60
61 #if !SLIM
62
63 SegmentX *xdata; /*+ The extended segment data (unsorted). +*/
64
65 #else
66
67 SegmentX xcached[2]; /*+ Two cached segments read from the file in slim mode. +*/
68
69 #endif
70
71 index_t number; /*+ How many entries are still useful? +*/
72
73 node_t *idata; /*+ The extended segment data (sorted by node1 then node2). +*/
74 index_t *firstnode; /*+ The first segment index for each node. +*/
75
76 #if !SLIM
77
78 Segment *sdata; /*+ The segment data (same order as sorted xdata). +*/
79
80 #else
81
82 char *sfilename; /*+ The name of the temporary file for segments in slim mode. +*/
83 int sfd; /*+ The file descriptor of the temporary file. +*/
84
85 Segment scached[2]; /*+ Two cached segments read from the file in slim mode. +*/
86
87 #endif
88 };
89
90
91 /* Functions */
92
93
94 SegmentsX *NewSegmentList(int append);
95 void FreeSegmentList(SegmentsX *segmentsx,int keep);
96
97 void SaveSegmentList(SegmentsX *segmentsx,const char *filename);
98
99 index_t IndexFirstSegmentX1(SegmentsX* segmentsx,node_t node);
100 index_t IndexNextSegmentX1(SegmentsX* segmentsx,index_t segindex,node_t node);
101
102 index_t IndexFirstSegmentX2(SegmentsX* segmentsx,index_t node);
103 index_t IndexNextSegmentX2(SegmentsX* segmentsx,index_t segindex,index_t node);
104
105 void AppendSegment(SegmentsX* segmentsx,way_t way,node_t node1,node_t node2,distance_t distance);
106
107 void SortSegmentList(SegmentsX* segmentsx);
108
109 void RemoveBadSegments(NodesX *nodesx,SegmentsX *segmentsx);
110
111 void UpdateSegments(SegmentsX *segmentsx,NodesX *nodesx,WaysX *waysx);
112
113 void RotateSegments(SegmentsX* segmentsx);
114
115 void DeduplicateSegments(SegmentsX* segmentsx,NodesX *nodesx,WaysX *waysx);
116
117 void CreateRealSegments(SegmentsX *segmentsx,WaysX *waysx);
118
119 void IndexSegments(SegmentsX* segmentsx,NodesX *nodesx);
120
121
122 /* Macros / inline functions */
123
124
125 #if !SLIM
126
127 #define LookupSegmentX(segmentsx,index,position) &(segmentsx)->xdata[index]
128
129 #define LookupSegmentXSegment(segmentsx,index,position) &(segmentsx)->sdata[index]
130
131 #else
132
133 static SegmentX *LookupSegmentX(SegmentsX* segmentsx,index_t index,int position);
134
135 static Segment *LookupSegmentXSegment(SegmentsX* segmentsx,index_t index,int position);
136
137 static void PutBackSegmentXSegment(SegmentsX* segmentsx,index_t index,int position);
138
139
140 /*++++++++++++++++++++++++++++++++++++++
141 Lookup a particular extended segment.
142
143 SegmentX *LookupSegmentX Returns a pointer to the extended segment with the specified id.
144
145 SegmentsX* segmentsx The set of segments to process.
146
147 index_t index The segment index to look for.
148
149 int position The position in the cache to use.
150 ++++++++++++++++++++++++++++++++++++++*/
151
152 static inline SegmentX *LookupSegmentX(SegmentsX* segmentsx,index_t index,int position)
153 {
154 SeekFile(segmentsx->fd,(off_t)index*sizeof(SegmentX));
155
156 ReadFile(segmentsx->fd,&segmentsx->xcached[position-1],sizeof(SegmentX));
157
158 return(&segmentsx->xcached[position-1]);
159 }
160
161
162 /*++++++++++++++++++++++++++++++++++++++
163 Lookup a particular extended segment's normal segment.
164
165 Segment *LookupSegmentXSegment Returns a pointer to the segment with the specified id.
166
167 SegmentsX* segmentsx The set of segments to process.
168
169 index_t index The segment index to look for.
170
171 int position The position in the cache to use.
172 ++++++++++++++++++++++++++++++++++++++*/
173
174 static inline Segment *LookupSegmentXSegment(SegmentsX* segmentsx,index_t index,int position)
175 {
176 SeekFile(segmentsx->sfd,(off_t)index*sizeof(Segment));
177
178 ReadFile(segmentsx->sfd,&segmentsx->scached[position-1],sizeof(Segment));
179
180 return(&segmentsx->scached[position-1]);
181 }
182
183
184 /*++++++++++++++++++++++++++++++++++++++
185 Put back an extended segment's normal segment.
186
187 SegmentsX* segmentsx The set of segments to process.
188
189 index_t index The segment index to look for.
190
191 int position The position in the cache to use.
192 ++++++++++++++++++++++++++++++++++++++*/
193
194 static inline void PutBackSegmentXSegment(SegmentsX* segmentsx,index_t index,int position)
195 {
196 SeekFile(segmentsx->sfd,(off_t)index*sizeof(Segment));
197
198 WriteFile(segmentsx->sfd,&segmentsx->scached[position-1],sizeof(Segment));
199 }
200
201 #endif /* SLIM */
202
203
204 #endif /* SEGMENTSX_H */

Properties

Name Value
cvs:description Extended segments header.