/***************************************
- $Header: /home/amb/routino/src/RCS/waysx.h,v 1.21 2010/05/22 18:40:47 amb Exp $
+ $Header: /home/amb/routino/src/RCS/waysx.h,v 1.28 2010/09/25 18:47:32 amb Exp $
A header file for the extended Ways structure.
#include <stdint.h>
-#include "typesx.h"
#include "types.h"
+
+#include "typesx.h"
#include "ways.h"
+#include "files.h"
+
/* Data structures */
char *filename; /*+ The name of the temporary file (for the WaysX). +*/
int fd; /*+ The file descriptor of the temporary file (for the WaysX). +*/
- uint32_t xnumber; /*+ The number of unsorted extended ways. +*/
+ index_t xnumber; /*+ The number of unsorted extended ways. +*/
+
+#if !SLIM
WayX *xdata; /*+ The extended data for the Ways (sorted). +*/
- WayX cached[2]; /*+ Two cached ways read from the file in slim mode. +*/
- uint32_t number; /*+ How many entries are still useful? +*/
+#else
- uint32_t cnumber; /*+ How many entries are there after compacting? +*/
+ WayX xcached[2]; /*+ Two cached ways read from the file in slim mode. +*/
+
+#endif
+
+ index_t number; /*+ How many entries are still useful? +*/
+
+ index_t cnumber; /*+ How many entries are there after compacting? +*/
index_t *idata; /*+ The index of the extended data for the Ways (sorted by ID). +*/
void SaveWayList(WaysX *waysx,const char *filename);
index_t IndexWayX(WaysX* waysx,way_t id);
-WayX *LookupWayX(WaysX* waysx,index_t index,int position);
void AppendWay(WaysX* waysx,way_t id,Way *way,const char *name);
void SortWayList(WaysX *waysx);
+void CompactWayList(WaysX *waysx);
+
+
+/* Macros / inline functions */
+
+#if !SLIM
+
+#define LookupWayX(waysx,index,position) &(waysx)->xdata[index]
+
+#else
+
+static WayX *LookupWayX(WaysX* waysx,index_t index,int position);
+
+
+/*++++++++++++++++++++++++++++++++++++++
+ Lookup a particular extended way.
+
+ WayX *LookupWayX Returns a pointer to the extended way with the specified id.
+
+ WaysX* waysx The set of ways to process.
+
+ index_t index The way index to look for.
+
+ int position The position in the cache to use.
+ ++++++++++++++++++++++++++++++++++++++*/
+
+static inline WayX *LookupWayX(WaysX* waysx,index_t index,int position)
+{
+ SeekFile(waysx->fd,(off_t)index*sizeof(WayX));
+
+ ReadFile(waysx->fd,&waysx->xcached[position-1],sizeof(WayX));
+
+ return(&waysx->xcached[position-1]);
+}
+
+
+/*++++++++++++++++++++++++++++++++++++++
+ Put back an extended way.
+
+ WaysX* waysx The set of ways to process.
+
+ index_t index The way index to put back.
+
+ int position The position in the cache to use.
+ ++++++++++++++++++++++++++++++++++++++*/
+
+static inline void PutBackWayX(WaysX* waysx,index_t index,int position)
+{
+ SeekFile(waysx->fd,(off_t)index*sizeof(WayX));
+
+ WriteFile(waysx->fd,&waysx->xcached[position-1],sizeof(WayX));
+}
+
+#endif /* SLIM */
+
+
#endif /* WAYSX_H */