1 /***************************************
2 $Header: /home/amb/routino/src/RCS/nodesx.h,v 1.30 2010/08/02 18:44:54 amb Exp $
4 A header file for the extended nodes.
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 NODESX_H /*+ To stop multiple inclusions. +*/
41 /*+ An extended structure used for processing. +*/
44 node_t id; /*+ The node identifier. +*/
46 latlong_t latitude; /*+ The node latitude. +*/
47 latlong_t longitude; /*+ The node longitude. +*/
49 allow_t allow; /*+ The node allowed traffic. +*/
52 /*+ A structure containing a set of nodes (memory format). +*/
55 char *filename; /*+ The name of the temporary file. +*/
56 int fd; /*+ The file descriptor of the temporary file. +*/
58 index_t xnumber; /*+ The number of unsorted extended nodes. +*/
62 NodeX *xdata; /*+ The extended node data (sorted). +*/
66 NodeX xcached[2]; /*+ Two cached nodes read from the file in slim mode. +*/
70 index_t number; /*+ How many entries are still useful? +*/
72 node_t *idata; /*+ The extended node IDs (sorted by ID). +*/
74 uint8_t *super; /*+ A marker for super nodes (same order sorted nodes). +*/
78 Node *ndata; /*+ The actual nodes (same order as geographically sorted nodes). +*/
82 char *nfilename; /*+ The name of the temporary file for nodes in slim mode. +*/
83 int nfd; /*+ The file descriptor of the temporary file. +*/
85 Node ncached[2]; /*+ Two cached nodes read from the file in slim mode. +*/
89 index_t latbins; /*+ The number of bins containing latitude. +*/
90 index_t lonbins; /*+ The number of bins containing longitude. +*/
92 ll_bin_t latzero; /*+ The bin number of the furthest south bin. +*/
93 ll_bin_t lonzero; /*+ The bin number of the furthest west bin. +*/
95 index_t latlonbin; /*+ A temporary index into the offsets array. +*/
97 index_t *offsets; /*+ An array of offset to the first node in each bin. +*/
103 NodesX *NewNodeList(int append);
104 void FreeNodeList(NodesX *nodesx,int keep);
106 void SaveNodeList(NodesX *nodesx,const char *filename);
108 index_t IndexNodeX(NodesX* nodesx,node_t id);
110 void AppendNode(NodesX* nodesx,node_t id,double latitude,double longitude,allow_t allow);
112 void SortNodeList(NodesX *nodesx);
114 void SortNodeListGeographically(NodesX* nodesx);
116 void RemoveNonHighwayNodes(NodesX *nodesx,SegmentsX *segmentsx);
118 void CreateRealNodes(NodesX *nodesx,int iteration);
120 void IndexNodes(NodesX *nodesx,SegmentsX *segmentsx);
123 /* Macros / inline functions */
127 #define LookupNodeX(nodesx,index,position) &(nodesx)->xdata[index]
129 #define LookupNodeXNode(nodesx,index,position) &(nodesx)->ndata[index]
133 static NodeX *LookupNodeX(NodesX* nodesx,index_t index,int position);
135 static Node *LookupNodeXNode(NodesX* nodesx,index_t index,int position);
137 static void PutBackNodeXNode(NodesX* nodesx,index_t index,int position);
140 /*++++++++++++++++++++++++++++++++++++++
141 Lookup a particular extended node.
143 NodeX *LookupNodeX Returns a pointer to the extended node with the specified id.
145 NodesX* nodesx The set of nodes to process.
147 index_t index The node index to look for.
149 int position The position in the cache to use.
150 ++++++++++++++++++++++++++++++++++++++*/
152 static inline NodeX *LookupNodeX(NodesX* nodesx,index_t index,int position)
154 SeekFile(nodesx->fd,(off_t)index*sizeof(NodeX));
156 ReadFile(nodesx->fd,&nodesx->xcached[position-1],sizeof(NodeX));
158 return(&nodesx->xcached[position-1]);
162 /*++++++++++++++++++++++++++++++++++++++
163 Lookup a particular extended node's normal node.
165 Node *LookupNodeXNode Returns a pointer to the node with the specified id.
167 NodesX* nodesx The set of nodes to process.
169 index_t index The node index to look for.
171 int position The position in the cache to use.
172 ++++++++++++++++++++++++++++++++++++++*/
174 static inline Node *LookupNodeXNode(NodesX* nodesx,index_t index,int position)
176 SeekFile(nodesx->nfd,(off_t)index*sizeof(Node));
178 ReadFile(nodesx->nfd,&nodesx->ncached[position-1],sizeof(Node));
180 return(&nodesx->ncached[position-1]);
184 /*++++++++++++++++++++++++++++++++++++++
185 Put back an extended node's normal node.
187 NodesX* nodesx The set of nodes to process.
189 index_t index The node index to look for.
191 int position The position in the cache to use.
192 ++++++++++++++++++++++++++++++++++++++*/
194 static inline void PutBackNodeXNode(NodesX* nodesx,index_t index,int position)
196 SeekFile(nodesx->nfd,(off_t)index*sizeof(Node));
198 WriteFile(nodesx->nfd,&nodesx->ncached[position-1],sizeof(Node));
204 #endif /* NODESX_H */