X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FLibraries%2Flibc%2B%2B.so_src%2Finclude_exp%2Fmap;h=455af71f5be71001904d4b9ff15a46f5f3bd1ef3;hb=5cab4c07bc13888dc7956194ef9595508072a4eb;hp=7a1cf3e6744c01aaa25f3ed1c4215582649a9c25;hpb=2cd79a3fd753af70c822c72a4a1c64b5ba510779;p=tpg%2Facess2.git diff --git a/Usermode/Libraries/libc++.so_src/include_exp/map b/Usermode/Libraries/libc++.so_src/include_exp/map index 7a1cf3e6..455af71f 100644 --- a/Usermode/Libraries/libc++.so_src/include_exp/map +++ b/Usermode/Libraries/libc++.so_src/include_exp/map @@ -59,9 +59,11 @@ public: return !(*this == x); } value_type& operator*() { + _libcxx_assert(m_index < m_map->m_size); return m_map->m_items[m_index]; } value_type* operator->() { + _libcxx_assert(m_index < m_map->m_size); return &m_map->m_items[m_index]; } }; @@ -171,7 +173,6 @@ public: iterator it = upper_bound(k); if( it == end() || m_comp(k, it->first) ) { // if k < it->first, no match insert_at(it.m_index, value_type(k,mapped_type()) ); - ++ it; } return it->second; } @@ -192,14 +193,52 @@ public: // Modifiers // - insert - pair insert(const value_type& val); + pair insert(const value_type& val) + { + const key_type& k = val.first; + iterator it = upper_bound(k); + if( it == end() || m_comp(k, it->first) ) { // if k < it->first, no match + insert_at(it.m_index, value_type(k,mapped_type()) ); + return pair(it, true); + } + else { + return pair(it, false); + } + } iterator insert(iterator position, const value_type& val); template void insert(InputInterator first, InputInterator last); // - erase - void erase(iterator position); - size_type erase(const key_type& k); - void erase(iterator first, iterator last); + void erase(iterator position) + { + auto pos = position; + erase(pos, ++position); + } + size_type erase(const key_type& k) + { + auto it = find(k); + if( it != end() ) { + erase(it); + return 1; + } + else { + return 0; + } + } + void erase(iterator first, iterator last) + { + _libcxx_assert(first.m_index <= last.m_index); + unsigned int ofs = first.m_index; + unsigned int count = last.m_index - first.m_index; + for( unsigned int i = 0; i < count; i ++ ) + { + // Construct new item + m_alloc.destroy(&m_items[ofs]); + m_size --; + // Move following items down + shift_items(&m_items[ofs+1], &m_items[ofs], m_size-ofs); + } + } // - swap void swap(map& x); // - clear @@ -319,6 +358,7 @@ private: pos_out = pos; return false; #else + //::_sys::debug("map::_search (m_size=%i)", m_size); for( size_type pos = 0; pos < m_size; pos ++ ) { const key_type& item_key = m_items[pos].first; @@ -326,22 +366,24 @@ private: continue; } else if( m_comp(k, item_key) ) { + //::_sys::debug("map::_search - Passed %i", pos); pos_out = pos; return false; } else { + //::_sys::debug("map::_search - Found %i", pos); pos_out = pos; return true; } } + //::_sys::debug("map::_search - Off end %i", m_size); pos_out = m_size; return false; #endif } void insert_at(size_type ofs, const value_type& val) { - //assert( ofs == 0 || m_comp(m_items[ofs-1].first, val.first) ); - //assert( ofs == m_size || m_comp(m_items[ofs].first, val.first) ); - ::_sys::debug("map::insert_at(%i,)", ofs); + //_libcxx_assert( ofs == 0 || m_comp(m_items[ofs-1].first, val.first) ); + //_libcxx_assert( ofs == m_size || m_comp(m_items[ofs].first, val.first) ); // Resize up reserve( m_size + 1 ); // Move following items up