Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/nodesx.h
Parent Directory
|
Revision Log
Revision 452 -
(show annotations)
(download)
(as text)
Wed Jul 14 18:00:10 2010 UTC (14 years, 8 months ago) by amb
File MIME type: text/x-chdr
File size: 5725 byte(s)
Wed Jul 14 18:00:10 2010 UTC (14 years, 8 months ago) by amb
File MIME type: text/x-chdr
File size: 5725 byte(s)
Replaced the runtime selection of slim mode / non-slim mode with compile time selection that gives no runtime overhead but gives two executables.
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/nodesx.h,v 1.27 2010-07-14 18:00:09 amb Exp $ |
3 | |
4 | A header file for the extended nodes. |
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 NODESX_H |
26 | #define NODESX_H /*+ To stop multiple inclusions. +*/ |
27 | |
28 | #include <stdint.h> |
29 | |
30 | #include "types.h" |
31 | #include "nodes.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 _NodeX |
43 | { |
44 | node_t id; /*+ The node identifier. +*/ |
45 | |
46 | latlong_t latitude; /*+ The node latitude. +*/ |
47 | latlong_t longitude; /*+ The node longitude. +*/ |
48 | }; |
49 | |
50 | /*+ A structure containing a set of nodes (memory format). +*/ |
51 | struct _NodesX |
52 | { |
53 | char *filename; /*+ The name of the temporary file. +*/ |
54 | int fd; /*+ The file descriptor of the temporary file. +*/ |
55 | |
56 | uint32_t xnumber; /*+ The number of unsorted extended nodes. +*/ |
57 | |
58 | #if !SLIM |
59 | |
60 | NodeX *xdata; /*+ The extended node data (sorted). +*/ |
61 | |
62 | #else |
63 | |
64 | NodeX xcached[2]; /*+ Two cached nodes read from the file in slim mode. +*/ |
65 | |
66 | #endif |
67 | |
68 | uint32_t number; /*+ How many entries are still useful? +*/ |
69 | |
70 | node_t *idata; /*+ The extended node IDs (sorted by ID). +*/ |
71 | |
72 | uint8_t *super; /*+ A marker for super nodes (same order sorted nodes). +*/ |
73 | |
74 | #if !SLIM |
75 | |
76 | Node *ndata; /*+ The actual nodes (same order as geographically sorted nodes). +*/ |
77 | |
78 | #else |
79 | |
80 | char *nfilename; /*+ The name of the temporary file for nodes in slim mode. +*/ |
81 | int nfd; /*+ The file descriptor of the temporary file. +*/ |
82 | |
83 | Node ncached[2]; /*+ Two cached nodes read from the file in slim mode. +*/ |
84 | |
85 | #endif |
86 | |
87 | uint32_t latbins; /*+ The number of bins containing latitude. +*/ |
88 | uint32_t lonbins; /*+ The number of bins containing longitude. +*/ |
89 | |
90 | ll_bin_t latzero; /*+ The bin number of the furthest south bin. +*/ |
91 | ll_bin_t lonzero; /*+ The bin number of the furthest west bin. +*/ |
92 | |
93 | uint32_t latlonbin; /*+ A temporary index into the offsets array. +*/ |
94 | |
95 | index_t *offsets; /*+ An array of offset to the first node in each bin. +*/ |
96 | }; |
97 | |
98 | |
99 | /* Functions */ |
100 | |
101 | NodesX *NewNodeList(int append); |
102 | void FreeNodeList(NodesX *nodesx,int keep); |
103 | |
104 | void SaveNodeList(NodesX *nodesx,const char *filename); |
105 | |
106 | index_t IndexNodeX(NodesX* nodesx,node_t id); |
107 | |
108 | void AppendNode(NodesX* nodesx,node_t id,double latitude,double longitude); |
109 | |
110 | void SortNodeList(NodesX *nodesx); |
111 | |
112 | void SortNodeListGeographically(NodesX* nodesx); |
113 | |
114 | void RemoveNonHighwayNodes(NodesX *nodesx,SegmentsX *segmentsx); |
115 | |
116 | void CreateRealNodes(NodesX *nodesx,int iteration); |
117 | |
118 | void IndexNodes(NodesX *nodesx,SegmentsX *segmentsx); |
119 | |
120 | |
121 | /* Macros / inline functions */ |
122 | |
123 | #if !SLIM |
124 | |
125 | #define LookupNodeX(nodesx,index,position) &(nodesx)->xdata[index] |
126 | |
127 | #define LookupNodeXNode(nodesx,index,position) &(nodesx)->ndata[index] |
128 | |
129 | #else |
130 | |
131 | static NodeX *LookupNodeX(NodesX* nodesx,index_t index,int position); |
132 | |
133 | static Node *LookupNodeXNode(NodesX* nodesx,index_t index,int position); |
134 | |
135 | static void PutBackNodeXNode(NodesX* nodesx,index_t index,int position); |
136 | |
137 | |
138 | /*++++++++++++++++++++++++++++++++++++++ |
139 | Lookup a particular extended node. |
140 | |
141 | NodeX *LookupNodeX Returns a pointer to the extended node with the specified id. |
142 | |
143 | NodesX* nodesx The set of nodes to process. |
144 | |
145 | index_t index The node index to look for. |
146 | |
147 | int position The position in the cache to use. |
148 | ++++++++++++++++++++++++++++++++++++++*/ |
149 | |
150 | static inline NodeX *LookupNodeX(NodesX* nodesx,index_t index,int position) |
151 | { |
152 | SeekFile(nodesx->fd,index*sizeof(NodeX)); |
153 | |
154 | ReadFile(nodesx->fd,&nodesx->xcached[position-1],sizeof(NodeX)); |
155 | |
156 | return(&nodesx->xcached[position-1]); |
157 | } |
158 | |
159 | |
160 | /*++++++++++++++++++++++++++++++++++++++ |
161 | Lookup a particular extended node's normal node. |
162 | |
163 | Node *LookupNodeXNode Returns a pointer to the node with the specified id. |
164 | |
165 | NodesX* nodesx The set of nodes to process. |
166 | |
167 | index_t index The node index to look for. |
168 | |
169 | int position The position in the cache to use. |
170 | ++++++++++++++++++++++++++++++++++++++*/ |
171 | |
172 | static inline Node *LookupNodeXNode(NodesX* nodesx,index_t index,int position) |
173 | { |
174 | SeekFile(nodesx->nfd,index*sizeof(Node)); |
175 | |
176 | ReadFile(nodesx->nfd,&nodesx->ncached[position-1],sizeof(Node)); |
177 | |
178 | return(&nodesx->ncached[position-1]); |
179 | } |
180 | |
181 | |
182 | /*++++++++++++++++++++++++++++++++++++++ |
183 | Put back an extended node's normal node. |
184 | |
185 | NodesX* nodesx The set of nodes to process. |
186 | |
187 | index_t index The node index to look for. |
188 | |
189 | int position The position in the cache to use. |
190 | ++++++++++++++++++++++++++++++++++++++*/ |
191 | |
192 | static inline void PutBackNodeXNode(NodesX* nodesx,index_t index,int position) |
193 | { |
194 | SeekFile(nodesx->nfd,index*sizeof(Node)); |
195 | |
196 | WriteFile(nodesx->nfd,&nodesx->ncached[position-1],sizeof(Node)); |
197 | } |
198 | |
199 | #endif /* SLIM */ |
200 | |
201 | |
202 | #endif /* NODESX_H */ |
Properties
Name | Value |
---|---|
cvs:description | Extended nodes header. |