comparing a number to an undefined number of values

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 36
Reputation: mostermand is an unknown quantity at this point 
Solved Threads: 1
mostermand mostermand is offline Offline
Light Poster

comparing a number to an undefined number of values

 
0
  #1
Sep 19th, 2009
Hi I have a problem, I hope you can help me with.

I have a number, which I need to compare to some values.

I do not wish to go through all the values, and compare them individually, as I there are too many for it to be efficient.

Neither do I want to create an array with the size of the range of numbers, as it can anything from 0 UINT_MAX

So I am hoping that you might have a better solution.

Here is an example of what I have tried, but didn't work,
because I get the values dynamicly

  1. class Mother
  2. {
  3. public:
  4. Mother(){}
  5. ~Mother(){}
  6.  
  7. template<int msg> inline void HandleMessage(){};
  8.  
  9. template<> inline void HandleMessage<10>()
  10. {
  11. std::cout<<"It works!\n";
  12. }
  13. };
All i've got is a slice of pi
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,819
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: comparing a number to an undefined number of values

 
0
  #2
Sep 19th, 2009
Originally Posted by mostermand View Post
Hi I have a problem, I hope you can help me with.

I have a number, which I need to compare to some values.

I do not wish to go through all the values, and compare them individually, as I there are too many for it to be efficient.

Neither do I want to create an array with the size of the range of numbers, as it can anything from 0 UINT_MAX

So I am hoping that you might have a better solution.

Here is an example of what I have tried, but didn't work,
because I get the values dynamicly

  1. class Mother
  2. {
  3. public:
  4. Mother(){}
  5. ~Mother(){}
  6.  
  7. template<int msg> inline void HandleMessage(){};
  8.  
  9. template<> inline void HandleMessage<10>()
  10. {
  11. std::cout<<"It works!\n";
  12. }
  13. };

I think you'll have to be a bit more specific about what you're after, what needs to be compared, stuff like that. I don't know what to make of the code snippet, as it has no comparisons. off the top of my head, if you have ordered data, use a binary search so you don't have to compare every element, but again, without having any idea what kind of data you have or what kind of comparisons you need to make, it's hard to speculate.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 36
Reputation: mostermand is an unknown quantity at this point 
Solved Threads: 1
mostermand mostermand is offline Offline
Light Poster

Re: comparing a number to an undefined number of values

 
0
  #3
Sep 19th, 2009
Well it is an integer, compared to a list of integers.
All i've got is a slice of pi
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,819
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: comparing a number to an undefined number of values

 
0
  #4
Sep 19th, 2009
Originally Posted by mostermand View Post
Well it is an integer, compared to a list of integers.
Any reason a binary search won't work?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 36
Reputation: mostermand is an unknown quantity at this point 
Solved Threads: 1
mostermand mostermand is offline Offline
Light Poster

Re: comparing a number to an undefined number of values

 
0
  #5
Sep 19th, 2009
Too time consuming. I would rather not do it at all then

And about the code snippet, if I create an instance of Mother,
and call HandleMessage<10> it would print "It works!\n".

But if I call it with any other value it would do nothing,
the reason I am not doing this, is that I don't know the values at compile time.
All i've got is a slice of pi
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,235
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 153
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Nearly a Posting Virtuoso

Re: comparing a number to an undefined number of values

 
0
  #6
Sep 19th, 2009
Originally Posted by mostermand View Post
Too time consuming. I would rather not do it at all then

And about the code snippet, if I create an instance of Mother,
and call HandleMessage<10> it would print "It works!\n".

But if I call it with any other value it would do nothing,
the reason I am not doing this, is that I don't know the values at compile time.
Care to give a little more background?
I give up! 
1) What word becomes shorter if you add a letter to it? [ Solved by : niek_e ]
2) What does this sequence  equal to :  (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
3) What is the 123456789 prime numer?
Ask4Answer
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 36
Reputation: mostermand is an unknown quantity at this point 
Solved Threads: 1
mostermand mostermand is offline Offline
Light Poster

Re: comparing a number to an undefined number of values

 
0
  #7
Sep 19th, 2009
Ok I am building a GUI Framework, where there is a Widget class,
which can both have mother widgets and be a mother widget.

When some event happens, the widget receives a message, in the form of an integer value(win32).
I want the widgets to be able to say to their children "I want to know when this happens", and then the mother widget's mother to be able do the same.

The alternative to this subscribe behavior, is to send some of the messages to the widget's mother
All i've got is a slice of pi
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC