473,387 Members | 1,290 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,387 software developers and data experts.

STL find & compare

Tom
Hi,
I need some help with stl maps.

I am using a std::map that is sorted in a very special way.
Therefore I am using my own sort function. That works fine.
But this is only half the problem. Additionally "map.find()" should
use a different comparison function.

My map is like:
map < myString, Whatever>
As far as I know "find" uses operators from the key (myString).
Therefore I wrote my own operator== ,operator< and operator>
Nothing worked. Does anybody know which comparison
function uses "find" or know any other solution while
using std functionality ?

thanks a lot T.

Jul 22 '05 #1
4 2700

"Tom" <Th************@epost.de> wrote in message
news:bq**********@news.mch.sbs.de...
Hi,
I need some help with stl maps.

I am using a std::map that is sorted in a very special way.
Therefore I am using my own sort function. That works fine.
But this is only half the problem. Additionally "map.find()" should
use a different comparison function.

My map is like:
map < myString, Whatever>
As far as I know "find" uses operators from the key (myString).
Therefore I wrote my own operator== ,operator< and operator>
Nothing worked. Does anybody know which comparison
function uses "find" or know any other solution while
using std functionality ?


Maintain another index, sorted by the "real" value you want to find by.

By index I mean map. I usually put my elements in a set, ordered by pri
key, and add a map<2nd key, item *> index. Otherwise you'll end up
iterating through them all looking for a certain value.

Of course this all depends on the details of exactly what you are doing
too. If you elaborate a little more into the details, perhaps we can help
you better.



Jul 22 '05 #2
"Tom" <Th************@epost.de> wrote in message
news:bq**********@news.mch.sbs.de...
| I am using a std::map that is sorted in a very special way.
| Therefore I am using my own sort function. That works fine.
| But this is only half the problem. Additionally "map.find()" should
| use a different comparison function.
|
| My map is like:
| map < myString, Whatever>
| As far as I know "find" uses operators from the key (myString).
| Therefore I wrote my own operator== ,operator< and operator>
| Nothing worked. Does anybody know which comparison
| function uses "find" or know any other solution while
| using std functionality ?

map.find() uses the comparison function that is used for sorting
( an item that comes neither before nor after is considered equal).
This allows the search to be performed in O(logN) time using
the map's tree structure.

If you want to use another equality criterion, you can use
the std::find function:
std::find( map.begin(), map.end(), MyPredicate(someKey) );
Note that this search will take linear O(N) time.
The predicate object is very much like a sort function:
its operator() shall take a MyMap::value_type& as a reference,
and return true if the item matches your search criterion.

hth -Ivan
--
http://ivan.vecerina.com
Jul 22 '05 #3
Tom wrote:
Hi,
I need some help with stl maps.

I am using a std::map that is sorted in a very special way.
Therefore I am using my own sort function. That works fine.
But this is only half the problem. Additionally "map.find()" should
use a different comparison function.

My map is like:
map < myString, Whatever>
As far as I know "find" uses operators from the key (myString).
Therefore I wrote my own operator== ,operator< and operator>
Nothing worked. Does anybody know which comparison
function uses "find" or know any other solution while
using std functionality ?


There is an optional compare template parameter to std::map - see.

http://www.sgi.com/tech/stl/Map.html

Jul 22 '05 #4
Tom
I am not quite sure if nesting maps will really helps in my case.
I am using my own sort function, which works fine.

What I need is a find function, that returns equity if a character in the
key
is a dot "." (Nr. 46 in ASCII table). And it should return the first entry
that fits.

A simplified example would be:

Keys in Map are (in the correct order)
"PEBKACyesitisme382"
"PEBKAC....382"

if my search-string is "PEBCAKyesitisme382" & it should find
"PEBKACyesitisme382"

if the order is v.v.
"PEBKAC....382"
"PEBKACyesitisme382"

it is should find "PEBKAC....382" for "PEBCAKyesitisme382"

it would be great if any of You knows a generic solution using stl
implements.

Thanks a lot
Thomas

"c wood" <re******@verizon.net> wrote in message
news:XY*******************@nwrddc02.gnilink.net...

"Tom" <Th************@epost.de> wrote in message
news:bq**********@news.mch.sbs.de...
Hi,
I need some help with stl maps.

I am using a std::map that is sorted in a very special way.
Therefore I am using my own sort function. That works fine.
But this is only half the problem. Additionally "map.find()" should
use a different comparison function.

My map is like:
map < myString, Whatever>
As far as I know "find" uses operators from the key (myString).
Therefore I wrote my own operator== ,operator< and operator>
Nothing worked. Does anybody know which comparison
function uses "find" or know any other solution while
using std functionality ?
Maintain another index, sorted by the "real" value you want to find

by.
By index I mean map. I usually put my elements in a set, ordered by pri key, and add a map<2nd key, item *> index. Otherwise you'll end up
iterating through them all looking for a certain value.

Of course this all depends on the details of exactly what you are doing too. If you elaborate a little more into the details, perhaps we can help you better.




Jul 22 '05 #5

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

Similar topics

13
by: Ben | last post by:
My company is using VS.Net 2003 to create and maintain asp.net projects on a windows 2003 webserver. The projects are created as applications and subwebs, then via FPE 2002 extensions are added to...
1
by: vertigo | last post by:
Hello i created map<myclass1*,myclass2*> object. I have problem with find function. It only works when myclass1* is string or int (it does not work for char* and myclass1*). Is it normal or i...
9
by: vertigo | last post by:
Hello I have strange problem, i have map<myclass1*,myclass2*,Compare>. Code: std::map<myclass1*,myclass2*,Compare> m=mymap; std::map<myclass1*,myclass2*,Compare>::const_iterator ci; ...
10
by: Peter Dunker | last post by:
Hi, I will check a String which should contain a HEX value. I know that strtol is the right function for this job. But what happens when I will check a hex string with 8 bytes? That I can...
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
10
by: lchian | last post by:
Hi, For two stl strings s1 and s2, I got different results from strcmp(s1.c_str(), s2.c_str()) and s1.compare(s2) can someone explain what these functions do? It seems that strcmp gives...
3
by: divya | last post by:
Hi, I have a table tblbwday with 2 fields Name and Birthday.I have written this script for displaying evryday names of the people on that day. <% set objConn...
9
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T');...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.