Routino SVN Repository Browser

Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino

ViewVC logotype

Annotation of /trunk/src/segments.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 704 - (hide annotations) (download) (as text)
Sun May 8 16:19:10 2011 UTC (13 years, 10 months ago) by amb
File MIME type: text/x-chdr
File size: 5587 byte(s)
Simplify the lookup of the segment index in slim mode.

1 amb 24 /***************************************
2 amb 564 $Header: /home/amb/CVS/routino/src/segments.h,v 1.38 2010-12-21 17:18:41 amb Exp $
3 amb 24
4     A header file for the segments.
5 amb 151
6     Part of the Routino routing software.
7 amb 24 ******************/ /******************
8 amb 672 This file Copyright 2008-2011 Andrew M. Bishop
9 amb 24
10 amb 151 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 amb 24 ***************************************/
23    
24    
25     #ifndef SEGMENTS_H
26     #define SEGMENTS_H /*+ To stop multiple inclusions. +*/
27    
28     #include <stdint.h>
29    
30 amb 96 #include "types.h"
31 amb 459
32     #include "files.h"
33 amb 82 #include "profiles.h"
34 amb 24
35 amb 26
36 amb 24 /* Data structures */
37    
38    
39 amb 109 /*+ A structure containing a single segment. +*/
40     struct _Segment
41 amb 88 {
42 amb 109 index_t node1; /*+ The index of the starting node. +*/
43     index_t node2; /*+ The index of the finishing node. +*/
44 amb 88
45 amb 109 index_t next2; /*+ The index of the next segment sharing node2. +*/
46 amb 88
47 amb 109 index_t way; /*+ The index of the way associated with the segment. +*/
48    
49     distance_t distance; /*+ The distance between the nodes. +*/
50     };
51    
52    
53 amb 459 /*+ A structure containing the header from the file. +*/
54     typedef struct _SegmentsFile
55 amb 24 {
56 amb 680 index_t number; /*+ The number of segments in total. +*/
57     index_t snumber; /*+ The number of super-segments. +*/
58     index_t nnumber; /*+ The number of normal segments. +*/
59 amb 459 }
60     SegmentsFile;
61 amb 88
62    
63 amb 459 /*+ A structure containing a set of segments (and pointers to mmap file). +*/
64     struct _Segments
65     {
66     SegmentsFile file; /*+ The header data from the file. +*/
67    
68     #if !SLIM
69    
70     void *data; /*+ The memory mapped data. +*/
71    
72     Segment *segments; /*+ An array of segments. +*/
73    
74     #else
75    
76     int fd; /*+ The file descriptor for the file. +*/
77    
78 amb 680 Segment cached[3]; /*+ Three cached segments read from the file in slim mode. +*/
79 amb 459 index_t incache[3]; /*+ The indexes of the cached segments. +*/
80    
81     #endif
82 amb 109 };
83 amb 24
84    
85 amb 680 /* Functions in segments.c */
86 amb 24
87 amb 459 Segments *LoadSegmentList(const char *filename);
88 amb 24
89 amb 681 Segment *NextSegment(Segments *segments,Segment *segment,index_t node);
90 amb 24
91 amb 681 index_t FindClosestSegmentHeading(Nodes *nodes,Segments *segments,Ways *ways,index_t node1,double heading,Profile *profile);
92 amb 675
93 amb 459 distance_t Distance(double lat1,double lon1,double lat2,double lon2);
94 amb 303
95 amb 459 duration_t Duration(Segment *segment,Way *way,Profile *profile);
96    
97 amb 672 double TurnAngle(Nodes *nodes,Segment *segment1,Segment *segment2,index_t node);
98     double BearingAngle(Nodes *nodes,Segment *segment,index_t node);
99 amb 459
100 amb 672
101 amb 459 /* Macros and inline functions */
102    
103 amb 109 /*+ Return true if this is a normal segment. +*/
104 amb 208 #define IsNormalSegment(xxx) (((xxx)->distance)&SEGMENT_NORMAL)
105 amb 24
106 amb 109 /*+ Return true if this is a super-segment. +*/
107 amb 208 #define IsSuperSegment(xxx) (((xxx)->distance)&SEGMENT_SUPER)
108 amb 24
109 amb 109 /*+ Return true if the segment is oneway towards the specified node. +*/
110 amb 208 #define IsOnewayTo(xxx,yyy) ((xxx)->node1==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2))
111 amb 24
112 amb 109 /*+ Return true if the segment is oneway from the specified node. +*/
113 amb 208 #define IsOnewayFrom(xxx,yyy) ((xxx)->node2==(yyy)?((xxx)->distance&ONEWAY_2TO1):((xxx)->distance&ONEWAY_1TO2))
114 amb 97
115 amb 109 /*+ Return the other node in the segment that is not the specified node. +*/
116 amb 208 #define OtherNode(xxx,yyy) ((xxx)->node1==(yyy)?(xxx)->node2:(xxx)->node1)
117 amb 97
118 amb 24
119 amb 459 #if !SLIM
120 amb 39
121 amb 459 /*+ Return a segment pointer given a set of segments and an index. +*/
122     #define LookupSegment(xxx,yyy,zzz) (&(xxx)->segments[yyy])
123 amb 24
124 amb 459 /*+ Return a segment index given a set of segments and a pointer. +*/
125     #define IndexSegment(xxx,yyy) ((yyy)-&(xxx)->segments[0])
126 amb 88
127 amb 459 #else
128 amb 88
129 amb 459 static Segment *LookupSegment(Segments *segments,index_t index,int position);
130 amb 99
131 amb 459 static index_t IndexSegment(Segments *segments,Segment *segment);
132 amb 63
133 amb 32
134 amb 459 /*++++++++++++++++++++++++++++++++++++++
135     Find the Segment information for a particular segment.
136    
137     Segment *LookupSegment Returns a pointer to the cached segment information.
138    
139 amb 680 Segments *segments The set of segments to use.
140 amb 459
141     index_t index The index of the segment.
142    
143     int position The position in the cache to store the value.
144     ++++++++++++++++++++++++++++++++++++++*/
145    
146     static inline Segment *LookupSegment(Segments *segments,index_t index,int position)
147     {
148 amb 564 if(segments->incache[position-1]!=index)
149     {
150     SeekFile(segments->fd,sizeof(SegmentsFile)+(off_t)index*sizeof(Segment));
151 amb 459
152 amb 564 ReadFile(segments->fd,&segments->cached[position-1],sizeof(Segment));
153 amb 459
154 amb 564 segments->incache[position-1]=index;
155     }
156 amb 459
157     return(&segments->cached[position-1]);
158     }
159    
160    
161     /*++++++++++++++++++++++++++++++++++++++
162     Find the segment index for a particular segment pointer.
163    
164     index_t IndexSegment Returns the index of the segment in the list.
165    
166 amb 680 Segments *segments The set of segments to use.
167 amb 459
168     Segment *segment The segment whose index is to be found.
169     ++++++++++++++++++++++++++++++++++++++*/
170    
171     static inline index_t IndexSegment(Segments *segments,Segment *segment)
172     {
173 amb 704 int position1=segment-&segments->cached[0];
174 amb 459
175 amb 704 return(segments->incache[position1]);
176 amb 459 }
177    
178     #endif
179    
180    
181 amb 24 #endif /* SEGMENTS_H */

Properties

Name Value
cvs:description Header file for segments.