1 /***************************************
2 $Header: /home/amb/routino/src/RCS/segmentsx.h,v 1.26 2010/07/31 14:36:15 amb Exp $
4 A header file for the extended segments.
6 Part of the Routino routing software.
7 ******************/ /******************
8 This file Copyright 2008-2010 Andrew M. Bishop
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.
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.
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 ***************************************/
26 #define SEGMENTSX_H /*+ To stop multiple inclusions. +*/
41 /*+ An extended structure used for processing. +*/
44 node_t node1; /*+ The id of the starting node. +*/
45 node_t node2; /*+ The id of the finishing node. +*/
47 way_t way; /*+ The id of the way. +*/
49 distance_t distance; /*+ The distance between the nodes. +*/
53 /*+ A structure containing a set of segments (memory format). +*/
56 char *filename; /*+ The name of the temporary file. +*/
57 int fd; /*+ The file descriptor of the temporary file. +*/
59 index_t xnumber; /*+ The number of unsorted extended nodes. +*/
63 SegmentX *xdata; /*+ The extended segment data (unsorted). +*/
67 SegmentX xcached[2]; /*+ Two cached segments read from the file in slim mode. +*/
71 index_t number; /*+ How many entries are still useful? +*/
73 node_t *idata; /*+ The extended segment data (sorted by node1 then node2). +*/
74 index_t *firstnode; /*+ The first segment index for each node. +*/
78 Segment *sdata; /*+ The segment data (same order as n1data). +*/
82 char *sfilename; /*+ The name of the temporary file for segments in slim mode. +*/
83 int sfd; /*+ The file descriptor of the temporary file. +*/
85 Segment scached[2]; /*+ Two cached segments read from the file in slim mode. +*/
94 SegmentsX *NewSegmentList(int append);
95 void FreeSegmentList(SegmentsX *segmentsx,int keep);
97 void SaveSegmentList(SegmentsX *segmentsx,const char *filename);
99 index_t IndexFirstSegmentX(SegmentsX* segmentsx,node_t node);
101 index_t IndexNextSegmentX(SegmentsX* segmentsx,index_t segindex,index_t nodeindex);
103 void AppendSegment(SegmentsX* segmentsx,way_t way,node_t node1,node_t node2,distance_t distance);
105 void SortSegmentList(SegmentsX* segmentsx);
107 void RemoveBadSegments(NodesX *nodesx,SegmentsX *segmentsx);
109 void UpdateSegments(SegmentsX *segmentsx,NodesX *nodesx,WaysX *waysx);
111 void RotateSegments(SegmentsX* segmentsx);
113 void DeduplicateSegments(SegmentsX* segmentsx,NodesX *nodesx,WaysX *waysx);
115 void CreateRealSegments(SegmentsX *segmentsx,WaysX *waysx);
117 void IndexSegments(SegmentsX* segmentsx,NodesX *nodesx);
120 /* Macros / inline functions */
125 #define LookupSegmentX(segmentsx,index,position) &(segmentsx)->xdata[index]
127 #define LookupSegmentXSegment(segmentsx,index,position) &(segmentsx)->sdata[index]
131 static SegmentX *LookupSegmentX(SegmentsX* segmentsx,index_t index,int position);
133 static Segment *LookupSegmentXSegment(SegmentsX* segmentsx,index_t index,int position);
135 static void PutBackSegmentXSegment(SegmentsX* segmentsx,index_t index,int position);
138 /*++++++++++++++++++++++++++++++++++++++
139 Lookup a particular extended segment.
141 SegmentX *LookupSegmentX Returns a pointer to the extended segment with the specified id.
143 SegmentsX* segmentsx The set of segments to process.
145 index_t index The segment index to look for.
147 int position The position in the cache to use.
148 ++++++++++++++++++++++++++++++++++++++*/
150 static inline SegmentX *LookupSegmentX(SegmentsX* segmentsx,index_t index,int position)
152 SeekFile(segmentsx->fd,(off_t)index*sizeof(SegmentX));
154 ReadFile(segmentsx->fd,&segmentsx->xcached[position-1],sizeof(SegmentX));
156 return(&segmentsx->xcached[position-1]);
160 /*++++++++++++++++++++++++++++++++++++++
161 Lookup a particular extended segment's normal segment.
163 Segment *LookupSegmentXSegment Returns a pointer to the segment with the specified id.
165 SegmentsX* segmentsx The set of segments to process.
167 index_t index The segment index to look for.
169 int position The position in the cache to use.
170 ++++++++++++++++++++++++++++++++++++++*/
172 static inline Segment *LookupSegmentXSegment(SegmentsX* segmentsx,index_t index,int position)
174 SeekFile(segmentsx->sfd,(off_t)index*sizeof(Segment));
176 ReadFile(segmentsx->sfd,&segmentsx->scached[position-1],sizeof(Segment));
178 return(&segmentsx->scached[position-1]);
182 /*++++++++++++++++++++++++++++++++++++++
183 Put back an extended segment's normal segment.
185 SegmentsX* segmentsx The set of segments to process.
187 index_t index The segment index to look for.
189 int position The position in the cache to use.
190 ++++++++++++++++++++++++++++++++++++++*/
192 static inline void PutBackSegmentXSegment(SegmentsX* segmentsx,index_t index,int position)
194 SeekFile(segmentsx->sfd,(off_t)index*sizeof(Segment));
196 WriteFile(segmentsx->sfd,&segmentsx->scached[position-1],sizeof(Segment));
202 #endif /* SEGMENTSX_H */