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 949 - (show annotations) (download) (as text)
Fri Jan 13 17:13:39 2012 UTC (13 years, 2 months ago) by amb
File MIME type: text/x-chdr
File size: 5980 byte(s)
Add an infrastructure to allow adding new functions to prune nodes and segments.

1 /***************************************
2 A header file for the extended segments.
3
4 Part of the Routino routing software.
5 ******************/ /******************
6 This file Copyright 2008-2012 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 #include "segments.h"
30
31 #include "typesx.h"
32
33 #include "files.h"
34
35
36 /* Data structures */
37
38
39 /*+ An extended structure used for processing. +*/
40 struct _SegmentX
41 {
42 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
45 index_t next2; /*+ The index of the next segment with the same node2. +*/
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 number; /*+ The number of extended segments still being considered. +*/
60
61 #if !SLIM
62
63 SegmentX *data; /*+ The extended segment data (when mapped into memory). +*/
64
65 #else
66
67 SegmentX cached[2]; /*+ Two cached extended segments read from the file in slim mode. +*/
68 index_t incache[2]; /*+ The indexes of the cached extended segments. +*/
69
70 #endif
71
72 index_t *firstnode; /*+ The first segment index for each node. +*/
73
74 index_t *next1; /*+ The index of the next segment with the same node1 (used while pruning). +*/
75
76 char *usednode; /*+ A flag to indicate if a node is used (used for removing bad segments). +*/
77 };
78
79
80 /* Functions in segmentsx.c */
81
82
83 SegmentsX *NewSegmentList(int append);
84 void FreeSegmentList(SegmentsX *segmentsx,int keep);
85
86 void SaveSegmentList(SegmentsX *segmentsx,const char *filename);
87
88 SegmentX *FirstSegmentX(SegmentsX *segmentsx,index_t nodeindex,int position);
89 SegmentX *NextSegmentX(SegmentsX *segmentsx,SegmentX *segmentx,index_t nodeindex);
90
91 void AppendSegment(SegmentsX *segmentsx,way_t way,node_t node1,node_t node2,distance_t distance);
92
93 void SortSegmentList(SegmentsX *segmentsx,int delete);
94
95 void RemoveBadSegments(NodesX *nodesx,SegmentsX *segmentsx);
96
97 void MeasureSegments(SegmentsX *segmentsx,NodesX *nodesx,WaysX *waysx);
98
99 void DeduplicateSegments(SegmentsX *segmentsx,NodesX *nodesx,WaysX *waysx);
100
101 void CreateRealSegments(SegmentsX *segmentsx,WaysX *waysx);
102
103 void IndexSegments(SegmentsX *segmentsx,NodesX *nodesx);
104
105 void UpdateSegments(SegmentsX *segmentsx,NodesX *nodesx,WaysX *waysx);
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) /* nop */
121
122 #else
123
124 static SegmentX *LookupSegmentX(SegmentsX *segmentsx,index_t index,int position);
125
126 static index_t IndexSegmentX(SegmentsX *segmentsx,SegmentX *segmentx);
127
128 static void PutBackSegmentX(SegmentsX *segmentsx,SegmentX *segmentx);
129
130
131 /*++++++++++++++++++++++++++++++++++++++
132 Lookup a particular extended segment with the specified id from the file on disk.
133
134 SegmentX *LookupSegmentX Returns a pointer to a cached copy of the extended segment.
135
136 SegmentsX *segmentsx The set of segments to use.
137
138 index_t index The segment index to look for.
139
140 int position The position in the cache to use.
141 ++++++++++++++++++++++++++++++++++++++*/
142
143 static inline SegmentX *LookupSegmentX(SegmentsX *segmentsx,index_t index,int position)
144 {
145 SeekReadFile(segmentsx->fd,&segmentsx->cached[position-1],sizeof(SegmentX),(off_t)index*sizeof(SegmentX));
146
147 segmentsx->incache[position-1]=index;
148
149 return(&segmentsx->cached[position-1]);
150 }
151
152
153 /*++++++++++++++++++++++++++++++++++++++
154 Find the extended segment index for a particular extended segment pointer.
155
156 index_t IndexSegmentX Returns the index of the extended segment.
157
158 SegmentsX *segmentsx The set of segments to use.
159
160 SegmentX *segmentx The extended segment whose index is to be found.
161 ++++++++++++++++++++++++++++++++++++++*/
162
163 static inline index_t IndexSegmentX(SegmentsX *segmentsx,SegmentX *segmentx)
164 {
165 int position1=segmentx-&segmentsx->cached[0];
166
167 return(segmentsx->incache[position1]);
168 }
169
170
171 /*++++++++++++++++++++++++++++++++++++++
172 Put back an extended segment's data into the file on disk.
173
174 SegmentsX *segmentsx The set of segments to use.
175
176 SegmentX *segmentx The extended segment to be put back.
177 ++++++++++++++++++++++++++++++++++++++*/
178
179 static inline void PutBackSegmentX(SegmentsX *segmentsx,SegmentX *segmentx)
180 {
181 int position1=segmentx-&segmentsx->cached[0];
182
183 SeekWriteFile(segmentsx->fd,&segmentsx->cached[position1],sizeof(SegmentX),(off_t)segmentsx->incache[position1]*sizeof(SegmentX));
184 }
185
186 #endif /* SLIM */
187
188
189 #endif /* SEGMENTSX_H */

Properties

Name Value
cvs:description Extended segments header.