Changeset 2109
- Timestamp:
- Nov 22, 2012, 2:05:40 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lol/core/map.h
r2108 r2109 21 21 { 22 22 23 /* A stupidly linear map for now */23 /* A stupidly linear map for now. */ 24 24 template<typename K, typename V> class Map : protected Hash<K> 25 25 { 26 26 public: 27 /* I choose to make this inline because passing the key by reference 28 * is usually suboptimal. */ 27 29 inline V const& operator[] (K const &key) const 28 30 { 31 /* Look for the hash in our table and return the value. */ 29 32 uint32_t hash = ((Hash<K> const &)*this)(key); 30 33 for (int i = 0; i < m_array.Count(); ++i) … … 32 35 if (m_array[i].m2 == key) 33 36 return m_array[i].m3; 37 /* XXX: this in an error! */ 34 38 return V(); 35 39 } … … 37 41 inline V & operator[] (K const &key) 38 42 { 39 return const_cast<V &>((const_cast<Map<K,V> const &>(*this))[key]); 40 } 41 42 inline V & Set(K const &key, V const &val) 43 { 43 /* Look for the hash in our table and return the value if found. */ 44 44 uint32_t hash = ((Hash<K> const &)*this)(key); 45 45 for (int i = 0; i < m_array.Count(); ++i) 46 46 if (m_array[i].m1 == hash) 47 47 if (m_array[i].m2 == key) 48 { 49 m_array[i].m3.~V(); 50 return m_array[i].m3 = val; 51 } 52 53 m_array.Push(hash, key, val); 48 return m_array[i].m3; 49 /* If not found, insert a new value. */ 50 m_array.Push(hash, key, V()); 54 51 return m_array.Last().m3; 55 52 } … … 67 64 } 68 65 66 inline bool HasKey(K const &key) 67 { 68 uint32_t hash = ((Hash<K> const &)*this)(key); 69 for (int i = 0; i < m_array.Count(); ++i) 70 if (m_array[i].m1 == hash) 71 if (m_array[i].m2 == key) 72 return true; 73 return false; 74 } 75 69 76 private: 70 77 Array<uint32_t, K, V> m_array; -
trunk/test/Makefile.am
r2098 r2109 23 23 unit/vector.cpp unit/matrix.cpp unit/half.cpp unit/trig.cpp \ 24 24 unit/build.cpp unit/real.cpp unit/image.cpp unit/quat.cpp unit/cmplx.cpp \ 25 unit/array.cpp unit/rotation.cpp unit/string.cpp 25 unit/array.cpp unit/rotation.cpp unit/string.cpp unit/map.cpp 26 26 testsuite_CPPFLAGS = @LOL_CFLAGS@ 27 27 testsuite_LDFLAGS = $(top_builddir)/src/liblol.a @LOL_LIBS@ -
trunk/test/testsuite.vcxproj
r1535 r2109 42 42 <ClCompile Include="unit\half.cpp" /> 43 43 <ClCompile Include="unit\image.cpp" /> 44 <ClCompile Include="unit\map.cpp" /> 44 45 <ClCompile Include="unit\matrix.cpp" /> 45 46 <ClCompile Include="unit\quat.cpp" /> 46 47 <ClCompile Include="unit\real.cpp" /> 47 48 <ClCompile Include="unit\rotation.cpp" /> 49 <ClCompile Include="unit\string.cpp" /> 48 50 <ClCompile Include="unit\trig.cpp" /> 49 51 <ClCompile Include="unit\vector.cpp" />
Note: See TracChangeset
for help on using the changeset viewer.