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/nodesx.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1120 - (show annotations) (download) (as text)
Thu Nov 1 20:00:27 2012 UTC (12 years, 4 months ago) by amb
File MIME type: text/x-chdr
File size: 5085 byte(s)
Introduce a new'--append' option for appending data from a file to the currently
parsed data.  Rename the intermediate file used for storing data to be appended
to.  Add a function to call after appending to a file which closes the file and
renames it to a temporary filename which is used for the remaining processing.

1 /***************************************
2 A header file for the extended nodes.
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 NODESX_H
24 #define NODESX_H /*+ To stop multiple inclusions. +*/
25
26 #include <stdint.h>
27
28 #include "types.h"
29 #include "nodes.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 _NodeX
41 {
42 node_t id; /*+ The node identifier; initially the OSM value, later the Node index, finally the first segment. +*/
43
44 latlong_t latitude; /*+ The node latitude. +*/
45 latlong_t longitude; /*+ The node longitude. +*/
46
47 transports_t allow; /*+ The node allowed traffic. +*/
48
49 uint16_t flags; /*+ The node flags. +*/
50 };
51
52 /*+ A structure containing a set of nodes (memory format). +*/
53 struct _NodesX
54 {
55 char *filename; /*+ The name of the intermediate file (for the NodesX). +*/
56 char *filename_tmp; /*+ The name of the temporary file (for the NodesX). +*/
57
58 int fd; /*+ The file descriptor of the open file (for the NodesX). +*/
59
60 index_t number; /*+ The number of extended nodes still being considered. +*/
61
62 #if !SLIM
63
64 NodeX *data; /*+ The extended node data (when mapped into memory). +*/
65
66 #else
67
68 NodeX cached[3]; /*+ Three cached extended nodes read from the file in slim mode. +*/
69 index_t incache[3]; /*+ The indexes of the cached extended nodes. +*/
70
71 #endif
72
73 node_t *idata; /*+ The extended node IDs (sorted by ID). +*/
74
75 index_t *pdata; /*+ The node indexes after pruning. +*/
76
77 index_t *gdata; /*+ The final node indexes (sorted geographically). +*/
78
79 BitMask *super; /*+ A bit-mask marker for super nodes (same order as sorted nodes). +*/
80
81 index_t latbins; /*+ The number of bins containing latitude. +*/
82 index_t lonbins; /*+ The number of bins containing longitude. +*/
83
84 ll_bin_t latzero; /*+ The bin number of the furthest south bin. +*/
85 ll_bin_t lonzero; /*+ The bin number of the furthest west bin. +*/
86 };
87
88
89 /* Functions in nodesx.c */
90
91 NodesX *NewNodeList(int append);
92 void FreeNodeList(NodesX *nodesx,int keep);
93 void FinishNodeList(NodesX *nodesx);
94
95 void SaveNodeList(NodesX *nodesx,const char *filename,SegmentsX *segmentsx);
96
97 index_t IndexNodeX(NodesX *nodesx,node_t id);
98
99 void AppendNode(NodesX *nodesx,node_t id,double latitude,double longitude,transports_t allow,uint16_t flags);
100
101 void SortNodeList(NodesX *nodesx);
102
103 void SortNodeListGeographically(NodesX *nodesx);
104
105 void RemoveNonHighwayNodes(NodesX *nodesx,SegmentsX *segmentsx);
106
107 void RemovePrunedNodes(NodesX *nodesx,SegmentsX *segmentsx);
108
109 void UpdateNodes(NodesX *nodesx,SegmentsX *segmentsx);
110
111
112 /* Macros and inline functions */
113
114 #if !SLIM
115
116 #define LookupNodeX(nodesx,index,position) &(nodesx)->data[index]
117
118 #define PutBackNodeX(nodesx,nodex) /* nop */
119
120 #else
121
122 static NodeX *LookupNodeX(NodesX *nodesx,index_t index,int position);
123
124 static void PutBackNodeX(NodesX *nodesx,NodeX *nodex);
125
126
127 /*++++++++++++++++++++++++++++++++++++++
128 Lookup a particular extended node with the specified id from the file on disk.
129
130 NodeX *LookupNodeX Returns a pointer to a cached copy of the extended node.
131
132 NodesX *nodesx The set of nodes to use.
133
134 index_t index The node index to look for.
135
136 int position The position in the cache to use.
137 ++++++++++++++++++++++++++++++++++++++*/
138
139 static inline NodeX *LookupNodeX(NodesX *nodesx,index_t index,int position)
140 {
141 SeekReadFile(nodesx->fd,&nodesx->cached[position-1],sizeof(NodeX),(off_t)index*sizeof(NodeX));
142
143 nodesx->incache[position-1]=index;
144
145 return(&nodesx->cached[position-1]);
146 }
147
148
149 /*++++++++++++++++++++++++++++++++++++++
150 Put back an extended node's data into the file on disk.
151
152 NodesX *nodesx The set of nodes to modify.
153
154 NodeX *nodex The extended node to be put back.
155 ++++++++++++++++++++++++++++++++++++++*/
156
157 static inline void PutBackNodeX(NodesX *nodesx,NodeX *nodex)
158 {
159 int position1=nodex-&nodesx->cached[0];
160
161 SeekWriteFile(nodesx->fd,&nodesx->cached[position1],sizeof(NodeX),(off_t)nodesx->incache[position1]*sizeof(NodeX));
162 }
163
164 #endif /* SLIM */
165
166
167 #endif /* NODESX_H */

Properties

Name Value
cvs:description Extended nodes header.