+/* Macros and inline functions */
+
+#if !SLIM
+
+/*+ Return a Node pointer given a set of nodes and an index. +*/
+#define LookupNode(xxx,yyy,zzz) (&(xxx)->nodes[yyy])
+
+/*+ Return a Segment points given a Node pointer and a set of segments. +*/
+#define FirstSegment(xxx,yyy,zzz) LookupSegment((xxx),(yyy)->nodes[zzz].firstseg,1)
+
+/*+ Return true if this is a super-node. +*/
+#define IsSuperNode(xxx,yyy) (((xxx)->nodes[yyy].flags)&NODE_SUPER)
+
+/*+ Return the offset of a geographical region given a set of nodes and an index. +*/
+#define LookupNodeOffset(xxx,yyy) ((xxx)->offsets[yyy])
+
+#else
+
+static Node *LookupNode(Nodes *nodes,index_t index,int position);
+
+#define FirstSegment(xxx,yyy,zzz) LookupSegment((xxx),FirstSegment_internal(yyy,zzz),1)
+
+static index_t FirstSegment_internal(Nodes *nodes,index_t index);
+
+static int IsSuperNode(Nodes *nodes,index_t index);
+
+static index_t LookupNodeOffset(Nodes *nodes,index_t index);
+
+
+/*++++++++++++++++++++++++++++++++++++++
+ Find the Node information for a particular node.
+
+ Node *LookupNode Returns a pointer to the cached node information.
+
+ Nodes *nodes The nodes structure to use.
+
+ index_t index The index of the node.
+
+ int position The position in the cache to store the value.
+ ++++++++++++++++++++++++++++++++++++++*/
+
+static inline Node *LookupNode(Nodes *nodes,index_t index,int position)
+{
+ SeekFile(nodes->fd,nodes->nodesoffset+(off_t)index*sizeof(Node));
+
+ ReadFile(nodes->fd,&nodes->cached[position-1],sizeof(Node));
+
+ nodes->incache[position-1]=index;
+
+ return(&nodes->cached[position-1]);
+}
+
+
+/*++++++++++++++++++++++++++++++++++++++
+ Find the index of the first segment of a node (called by FirstSegment() macro).
+
+ index_t FirstSegment_internal Returns the index of the first segment.
+
+ Nodes *nodes The nodes structure to use.
+
+ index_t index The index of the node.
+ ++++++++++++++++++++++++++++++++++++++*/
+
+static inline index_t FirstSegment_internal(Nodes *nodes,index_t index)
+{
+ if(nodes->incache[0]==index)
+ return(nodes->cached[0].firstseg);
+ else if(nodes->incache[1]==index)
+ return(nodes->cached[1].firstseg);
+ else if(nodes->incache[2]==index)
+ return(nodes->cached[2].firstseg);
+ else
+ {
+ Node *node=LookupNode(nodes,index,3);
+
+ return(node->firstseg);
+ }
+}
+
+
+/*++++++++++++++++++++++++++++++++++++++
+ Decide if a node is a super-node.
+
+ int IsSuperNode Return true if it is a supernode.
+
+ Nodes *nodes The nodes structure to use.
+
+ index_t index The index of the node.
+ ++++++++++++++++++++++++++++++++++++++*/
+
+static inline int IsSuperNode(Nodes *nodes,index_t index)
+{
+ if(nodes->incache[0]==index)
+ return(nodes->cached[0].flags&NODE_SUPER);
+ else if(nodes->incache[1]==index)
+ return(nodes->cached[1].flags&NODE_SUPER);
+ else if(nodes->incache[2]==index)
+ return(nodes->cached[2].flags&NODE_SUPER);
+ else
+ {
+ Node *node=LookupNode(nodes,index,3);
+
+ return(node->flags&NODE_SUPER);
+ }
+}
+
+
+/*++++++++++++++++++++++++++++++++++++++
+ Find the offset of nodes in a geographical region.
+
+ index_t LookupNodeOffset Returns the value of the index offset.
+
+ Nodes *nodes The nodes structure to use.
+
+ index_t index The index of the offset.
+ ++++++++++++++++++++++++++++++++++++++*/
+
+static inline index_t LookupNodeOffset(Nodes *nodes,index_t index)
+{
+ index_t offset;
+
+ SeekFile(nodes->fd,sizeof(NodesFile)+(off_t)index*sizeof(index_t));
+
+ ReadFile(nodes->fd,&offset,sizeof(index_t));
+
+ return(offset);
+}
+
+#endif
+
+