From: John Hodge (sonata) Date: Fri, 7 Nov 2014 08:42:27 +0000 (+0800) Subject: Usermode/libc++ - Implement map::insert and map::erase X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=5cab4c07bc13888dc7956194ef9595508072a4eb;p=tpg%2Facess2.git Usermode/libc++ - Implement map::insert and map::erase --- diff --git a/Usermode/Libraries/libc++.so_src/include_exp/map b/Usermode/Libraries/libc++.so_src/include_exp/map index 7f7e7c3c..455af71f 100644 --- a/Usermode/Libraries/libc++.so_src/include_exp/map +++ b/Usermode/Libraries/libc++.so_src/include_exp/map @@ -193,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