You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
map operator[] (both non-templated versions) don't provide a proper hint to the rbtree DoInsertKey(true_type, const_iterator position, const key_type& key) #592
both version of map operator[] (map.h line 184 and 185) use lower_bound(key) to detect if a lower bound already exists and then attempt to use it as a hint for faster insertion, both call down into the rbtree base_type::DoInsertKey(true_type(), itLower, key) or the same thing but eastl::move(key) for the rvalue version. DoInsertKey(...) then calls DoGetKeyInsertionPositionUniqueKeysHint(...) in order to potentially (hopefully) use the provided iterator hint to quickly find the parent node for very fast insertion. The issue is that DoGetKeyInsertionPositionUniqueKeysHint(...) expects the hint to be immediately less than the incoming key, and lower_bound provides an iterator that is >= the key.
by modifying line 559 of map.h in master branch to:
I can successfully trigger line 1534 in red_black_tree.h inside DoGetKeyInsertionPositionUniqueKeysHint(...), by inserting on key 7 in belows example, to provide a parent hint in order to prevent another log base 2 search from needing to take place. Perhaps this would be a fix for this? Also maybe if itLower == begin() attempting a hint would just be a waste of time?
Here is the test code I used:
eastl::map<int, char> map1;
for (uint32_t i = 0; i < 15; i+=2)
{
map1.insert(eastl::make_pair(i, 'A' + i));
}
map1[7] = 'Z';
I reproduced this: with a counting comparator on a 100k-element map<int,int>, a missing-key operator[] averages 38.2 comparisons against 18.1 for lower_bound alone, so the hint is rejected and the tree is searched twice. I opened #603, which passes the predecessor as the hint (20.6 comparisons per miss), with a regression test. (EA CLA signed.)
This was investigated and written with an AI coding agent (Claude) working on my behalf.
Activity
devteamaegis commentedon Nov 4, 2026
I reproduced this: with a counting comparator on a 100k-element
map<int,int>, a missing-keyoperator[]averages 38.2 comparisons against 18.1 forlower_boundalone, so the hint is rejected and the tree is searched twice. I opened #603, which passes the predecessor as the hint (20.6 comparisons per miss), with a regression test. (EA CLA signed.)This was investigated and written with an AI coding agent (Claude) working on my behalf.