Check out the latest version of Routino: svn co http://routino.org/svn/trunk routino
Contents of /trunk/src/ways.c
Parent Directory
|
Revision Log
Revision 564 -
(show annotations)
(download)
(as text)
Tue Dec 21 17:18:41 2010 UTC (14 years, 3 months ago) by amb
File MIME type: text/x-csrc
File size: 3062 byte(s)
Tue Dec 21 17:18:41 2010 UTC (14 years, 3 months ago) by amb
File MIME type: text/x-csrc
File size: 3062 byte(s)
Optimise the node, segment, way lookup in slim mode by checking if the previous index is being requested again.
1 | /*************************************** |
2 | $Header: /home/amb/CVS/routino/src/ways.c,v 1.47 2010-12-21 17:18:41 amb Exp $ |
3 | |
4 | Way data type functions. |
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 | #include <stdlib.h> |
26 | |
27 | #include "ways.h" |
28 | |
29 | #include "files.h" |
30 | |
31 | |
32 | /*++++++++++++++++++++++++++++++++++++++ |
33 | Load in a way list from a file. |
34 | |
35 | Ways* LoadWayList Returns the way list. |
36 | |
37 | const char *filename The name of the file to load. |
38 | ++++++++++++++++++++++++++++++++++++++*/ |
39 | |
40 | Ways *LoadWayList(const char *filename) |
41 | { |
42 | Ways *ways; |
43 | |
44 | ways=(Ways*)malloc(sizeof(Ways)); |
45 | |
46 | #if !SLIM |
47 | |
48 | ways->data=MapFile(filename); |
49 | |
50 | /* Copy the WaysFile structure from the loaded data */ |
51 | |
52 | ways->file=*((WaysFile*)ways->data); |
53 | |
54 | /* Set the pointers in the Ways structure. */ |
55 | |
56 | ways->ways =(Way *)(ways->data+sizeof(WaysFile)); |
57 | ways->names=(char*)(ways->data+sizeof(WaysFile)+ways->file.number*sizeof(Way)); |
58 | |
59 | #else |
60 | |
61 | ways->fd=ReOpenFile(filename); |
62 | |
63 | /* Copy the WaysFile header structure from the loaded data */ |
64 | |
65 | ReadFile(ways->fd,&ways->file,sizeof(WaysFile)); |
66 | |
67 | ways->incache[0]=NO_WAY; |
68 | ways->incache[1]=NO_WAY; |
69 | |
70 | ways->namesoffset=sizeof(WaysFile)+ways->file.number*sizeof(Way); |
71 | |
72 | ways->nincache=~0; |
73 | ways->ncached=NULL; |
74 | |
75 | #endif |
76 | |
77 | return(ways); |
78 | } |
79 | |
80 | |
81 | /*++++++++++++++++++++++++++++++++++++++ |
82 | Return 0 if the two ways are the same (in respect of their types and limits), |
83 | otherwise return positive or negative to allow sorting. |
84 | |
85 | int WaysCompare Returns a comparison. |
86 | |
87 | Way *way1 The first way. |
88 | |
89 | Way *way2 The second way. |
90 | ++++++++++++++++++++++++++++++++++++++*/ |
91 | |
92 | int WaysCompare(Way *way1,Way *way2) |
93 | { |
94 | if(way1==way2) |
95 | return(0); |
96 | |
97 | if(way1->type!=way2->type) |
98 | return((int)way1->type - (int)way2->type); |
99 | |
100 | if(way1->allow!=way2->allow) |
101 | return((int)way1->allow - (int)way2->allow); |
102 | |
103 | if(way1->props!=way2->props) |
104 | return((int)way1->props - (int)way2->props); |
105 | |
106 | if(way1->speed!=way2->speed) |
107 | return((int)way1->speed - (int)way2->speed); |
108 | |
109 | if(way1->weight!=way2->weight) |
110 | return((int)way1->weight - (int)way2->weight); |
111 | |
112 | if(way1->height!=way2->height) |
113 | return((int)way1->height - (int)way2->height); |
114 | |
115 | if(way1->width!=way2->width) |
116 | return((int)way1->width - (int)way2->width); |
117 | |
118 | if(way1->length!=way2->length) |
119 | return((int)way1->length - (int)way2->length); |
120 | |
121 | return(0); |
122 | } |
Properties
Name | Value |
---|---|
cvs:description | Functions for ways. |