# yapf_node.hpp

Go to the documentation of this file.

    00001 /* $Id: yapf_node.hpp 10392 2007-06-29 23:45:13Z KUDr $ */
    00002
    00005 #ifndef  YAPF_NODE_HPP
    00006 #define  YAPF_NODE_HPP
    00007
    00009 struct CYapfNodeKeyExitDir {
    00010   TileIndex      m_tile;
    00011   Trackdir       m_td;
    00012   DiagDirection  m_exitdir;
    00013
    00014   FORCEINLINE void Set(TileIndex tile, Trackdir td)
    00015   {
    00016     m_tile = tile;
    00017     m_td = td;
    00018     m_exitdir = (m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(m_td);
    00019   }
    00020
    00021   FORCEINLINE int CalcHash() const {return m_exitdir | (m_tile << 2);}
    00022   FORCEINLINE bool operator == (const CYapfNodeKeyExitDir& other) const {return (m_tile == other.m_tile) && (m_exitdir == other.m_exitdir);}
    00023
    00024   void Dump(DumpTarget &dmp) const
    00025   {
    00026     dmp.WriteTile("m_tile", m_tile);
    00027     dmp.WriteEnumT("m_td", m_td);
    00028     dmp.WriteEnumT("m_exitdir", m_exitdir);
    00029   }
    00030 };
    00031
    00032 struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir
    00033 {
    00034   FORCEINLINE int CalcHash() const {return m_td | (m_tile << 4);}
    00035   FORCEINLINE bool operator == (const CYapfNodeKeyTrackDir& other) const {return (m_tile == other.m_tile) && (m_td == other.m_td);}
    00036 };
    00037
    00039 template <class Tkey_, class Tnode>
    00040 struct CYapfNodeT {
    00041   typedef Tkey_ Key;
    00042   typedef Tnode Node;
    00043
    00044   Tkey_       m_key;
    00045   Node       *m_hash_next;
    00046   Node       *m_parent;
    00047   int         m_cost;
    00048   int         m_estimate;
    00049
    00050   FORCEINLINE void Set(Node *parent, TileIndex tile, Trackdir td, bool is_choice)
    00051   {
    00052     m_key.Set(tile, td);
    00053     m_hash_next = NULL;
    00054     m_parent = parent;
    00055     m_cost = 0;
    00056     m_estimate = 0;
    00057   }
    00058
    00059   FORCEINLINE Node* GetHashNext() {return m_hash_next;}
    00060   FORCEINLINE void SetHashNext(Node *pNext) {m_hash_next = pNext;}
    00061   FORCEINLINE TileIndex GetTile() const {return m_key.m_tile;}
    00062   FORCEINLINE Trackdir GetTrackdir() const {return m_key.m_td;}
    00063   FORCEINLINE const Tkey_& GetKey() const {return m_key;}
    00064   FORCEINLINE int GetCost() {return m_cost;}
    00065   FORCEINLINE int GetCostEstimate() {return m_estimate;}
    00066   FORCEINLINE bool operator < (const Node& other) const {return m_estimate < other.m_estimate;}
    00067
    00068   void Dump(DumpTarget &dmp) const
    00069   {
    00070     dmp.WriteStructT("m_key", &m_key);
    00071     dmp.WriteStructT("m_parent", m_parent);
    00072     dmp.WriteLine("m_cost = %d", m_cost);
    00073     dmp.WriteLine("m_estimate = %d", m_estimate);
    00074   }
    00075 };
    00076
    00078 template <class Tkey_>
    00079 struct CYapfShipNodeT
    00080   : CYapfNodeT<Tkey_, CYapfShipNodeT<Tkey_> >
    00081 {
    00082
    00083 };
    00084
    00085 // now define two major node types (that differ by key type)
    00086 typedef CYapfShipNodeT<CYapfNodeKeyExitDir>  CYapfShipNodeExitDir;
    00087 typedef CYapfShipNodeT<CYapfNodeKeyTrackDir> CYapfShipNodeTrackDir;
    00088
    00089 // Default NodeList types
    00090 typedef CNodeList_HashTableT<CYapfShipNodeExitDir , 14, 16> CShipNodeListExitDir;
    00091 typedef CNodeList_HashTableT<CYapfShipNodeTrackDir, 16, 20> CShipNodeListTrackDir;
    00092
    00093
    00094 #endif /* YAPF_NODE_HPP */