1 /***************************************
2 $Header: /home/amb/routino/src/RCS/waysx.h,v 1.28 2010/09/25 18:47:32 amb Exp $
4 A header file for the extended Ways structure.
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 WAYSX_H /*+ To stop multiple inclusions. +*/
41 /*+ An extended structure containing a single way. +*/
44 way_t id; /*+ The way identifier. +*/
46 index_t prop; /*+ The index of the properties of the way in the compacted list. +*/
48 Way way; /*+ The real Way data. +*/
52 /*+ A structure containing a set of ways (memory format). +*/
55 char *filename; /*+ The name of the temporary file (for the WaysX). +*/
56 int fd; /*+ The file descriptor of the temporary file (for the WaysX). +*/
58 index_t xnumber; /*+ The number of unsorted extended ways. +*/
62 WayX *xdata; /*+ The extended data for the Ways (sorted). +*/
66 WayX xcached[2]; /*+ Two cached ways read from the file in slim mode. +*/
70 index_t number; /*+ How many entries are still useful? +*/
72 index_t cnumber; /*+ How many entries are there after compacting? +*/
74 index_t *idata; /*+ The index of the extended data for the Ways (sorted by ID). +*/
76 char *nfilename; /*+ The name of the temporary file (for the names). +*/
78 uint32_t nlength; /*+ How long is the string of name entries? +*/
85 WaysX *NewWayList(int append);
86 void FreeWayList(WaysX *waysx,int keep);
88 void SaveWayList(WaysX *waysx,const char *filename);
90 index_t IndexWayX(WaysX* waysx,way_t id);
92 void AppendWay(WaysX* waysx,way_t id,Way *way,const char *name);
94 void SortWayList(WaysX *waysx);
96 void CompactWayList(WaysX *waysx);
99 /* Macros / inline functions */
103 #define LookupWayX(waysx,index,position) &(waysx)->xdata[index]
107 static WayX *LookupWayX(WaysX* waysx,index_t index,int position);
110 /*++++++++++++++++++++++++++++++++++++++
111 Lookup a particular extended way.
113 WayX *LookupWayX Returns a pointer to the extended way with the specified id.
115 WaysX* waysx The set of ways to process.
117 index_t index The way index to look for.
119 int position The position in the cache to use.
120 ++++++++++++++++++++++++++++++++++++++*/
122 static inline WayX *LookupWayX(WaysX* waysx,index_t index,int position)
124 SeekFile(waysx->fd,(off_t)index*sizeof(WayX));
126 ReadFile(waysx->fd,&waysx->xcached[position-1],sizeof(WayX));
128 return(&waysx->xcached[position-1]);
132 /*++++++++++++++++++++++++++++++++++++++
133 Put back an extended way.
135 WaysX* waysx The set of ways to process.
137 index_t index The way index to put back.
139 int position The position in the cache to use.
140 ++++++++++++++++++++++++++++++++++++++*/
142 static inline void PutBackWayX(WaysX* waysx,index_t index,int position)
144 SeekFile(waysx->fd,(off_t)index*sizeof(WayX));
146 WriteFile(waysx->fd,&waysx->xcached[position-1],sizeof(WayX));