473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

LCA of two map::const_iterators



The lowest common ancestor of two nodes in a red black tree can be
computed
in O(log n) time. Is there an implementation of LCA for two map
iterators? If not,
does anyone know how to implement this on std::map? Has anyone else
done
something similar?

Thanks,
--j
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jan 3 '07 #1
3 1835
On 2007-01-03 14:57, John wrote:
>
The lowest common ancestor of two nodes in a red black tree can be
computed in O(log n) time. Is there an implementation of LCA for two
map iterators? If not, does anyone know how to implement this on
std::map? Has anyone else done something similar?
Do you have any guarantee that std::map will use a red-black tree? Sure,
it probably is but I don't think that there is anything in the
specification saying that it should be. So if such an implementation
existed it would have to be purely platform-specific. You might have
better luck in a forum specific for you platform.

Out of curiosity, why would you want such a thing? It seems to me you
are misusing std::map, if you want a tree-structure you have to make one
your self, std::map is an associative container, not a tree-structure.

--
Erik Wikström

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jan 3 '07 #2
John wrote:
>
The lowest common ancestor of two nodes in a red black tree can be
computed
in O(log n) time. Is there an implementation of LCA for two map
iterators? If not,
does anyone know how to implement this on std::map? Has anyone else
done
something similar?

Thanks,
--j

This is all implementation dependent and therefore there's no portable
solution. While it's typically the case, there's no requirement that a
map be implemented as a red-black tree, and in any event the tree
structure is not visible from the map interface.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jan 3 '07 #3
Erik Wikström schreef:
On 2007-01-03 14:57, John wrote:

The lowest common ancestor of two nodes in a red black tree can be
computed in O(log n) time. Is there an implementation of LCA for two
map iterators? If not, does anyone know how to implement this on
std::map? Has anyone else done something similar?

Do you have any guarantee that std::map will use a red-black tree? Sure,
it probably is but I don't think that there is anything in the
specification saying that it should be.
There isn't. The only requirement is on the complexity of each member.

Now, I'm fairly certain that it's possible to put more than one map
element
in each node of a tree, e.g. 1 to 4 elements (this adds only O(1)
complexity,
due to the finite upper bound) in which case the 'ancestor' really
makes no
sense. Would that make sense? Perhaps for a std::map with 4 byte keys,
to improve locality.

Michiel Salters
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jan 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: john smith | last post by:
Hi, I have a question about map and classes that contain maps. My problem is declaring any class methods const that would do something to the map. Presumably it's because when operator is...
12
by: Christof Krueger | last post by:
Hello, I'm quite new to C++ so maybe there's something I miss. I write a simple board game. It has a board class. This class has a method that returns the count of pieces a player has on the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.