Guest User

Untitled

a guest
May 20th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. /********************************************************************
  2.  
  3. created: 2008/06/24
  4.  
  5. created: 24:6:2008 0:27
  6.  
  7. filename: c:\Program Files\Microsoft Visual Studio 9.0\VC\include\ozlib\hashtable.h
  8.  
  9. file path: c:\Program Files\Microsoft Visual Studio 9.0\VC\include\ozlib
  10.  
  11. file base: hashtable
  12.  
  13. file ext: h
  14.  
  15. author: Eric Smaxwill
  16.  
  17.  
  18.  
  19. purpose: C# Hashtable implementation
  20.  
  21. *********************************************************************/
  22.  
  23.  
  24.  
  25. #pragma once
  26.  
  27.  
  28.  
  29. #include <map>
  30.  
  31.  
  32.  
  33. #include <ozlib/types.h>
  34.  
  35. #include <ozlib/array.h>
  36.  
  37.  
  38.  
  39. NAMESPACE_BEGIN
  40.  
  41.  
  42.  
  43. //extraction macros from iterator P
  44.  
  45. #define KEY( p ) (*p).first
  46.  
  47. #define VALUE( p ) (*p).second
  48.  
  49.  
  50.  
  51. template <typename _Key, typename _Value>
  52.  
  53. class Hashtable
  54.  
  55. {
  56.  
  57. private:
  58.  
  59. std::map<_Key, _Value> m_Table;
  60.  
  61. ozlib::array<_Key> m_Keys;
  62.  
  63. public:
  64.  
  65. _Value& operator[]( _Key keyVal )
  66.  
  67. {
  68.  
  69. std::map<_Key, _Value>::iterator itr = m_Table.find( keyVal );
  70.  
  71. if(itr!=m_Table.end())
  72.  
  73. {
  74.  
  75. if(!m_Keys.contains( keyVal )) m_Keys.Add(keyVal);
  76.  
  77. return VALUE(itr);
  78.  
  79. }
  80.  
  81. else
  82.  
  83. {
  84.  
  85. if(!m_Keys.contains( keyVal )) m_Keys.Add(keyVal);
  86.  
  87. return m_Table[keyVal];
  88.  
  89. }
  90.  
  91. }
  92.  
  93. ozlib::array<_Key> Keys() const
  94.  
  95. {
  96.  
  97. return m_Keys;
  98.  
  99. }
  100.  
  101. };
  102.  
  103.  
  104.  
  105. NAMESPACE_END
Add Comment
Please, Sign In to add comment