Solved

Please validate function...

Posted on 2008-06-16
17
145 Views
Last Modified: 2010-04-21
Please have a look over the following function. I've tested it and it seems fine, but it would be nice just to make sure...

Thanks,
Uni
/*********************************************************************************
This returns true if the needle was found in the haystack and the
index is given in the aFoundIndex parameter. If the needle wasn't
found then the method returns false and aFoundIndex is undefined.
This method is bound safe.
*********************************************************************************/
bool findNeedleInHaystack(vector<BIT> &aHaystack, unsigned int aStartIndex, vector<BIT> &aNeedle, unsigned int &aFoundIndex){
	if(aStartIndex>=aHaystack.size())
		return false;
	vector<BIT>::iterator searchResult=search(aHaystack.begin()+aStartIndex, aHaystack.end(), aNeedle.begin(), aNeedle.end());
	if(searchResult==aHaystack.end())
		return false;
	aFoundIndex=searchResult-aHaystack.begin();
	return true;
}
/********************************************************************************/

Open in new window

0
Comment
Question by:Unimatrix_001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 4
  • 4
17 Comments
 
LVL 53

Accepted Solution

by:
Infinity08 earned 100 total points
ID: 21796334
That looks good, yes. So, you've gone with indexes instead of iterators then :)
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 21796354
Cheers, yeah - the iterators were causing all sorts of problems. Shame because I'd have liked to keep it pure STL without resorting to indexes. Clearly though as the other question shows it's not going to work without a nasty fight... Oh well. :)

Thanks again,
Uni
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21796439
Heh :) Good old indexes never let you down eh :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:Unimatrix_001
ID: 21796981
They're strong (and as pretty) as a rock... :)
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21796994
Now you're getting all poetic ... what's up today ? ;)
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 21797024
Haha, I don't know what you mean... now where did I leave that Shakespeare sonnet volume...
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 21797054
/me hides ... This is getting too much for me lol
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 21797073
:D
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21797951
I don't mean to be picky, but I'm gonna :)

You are passing in unsigned int, really the correct type should be vector<BIT>::size_type and the reason for this is that size_type might have a different value on different platforms. For example, on a 64 bit platform it might be a 64 bit type (same as size_t). By using unsigned int you might not be able to address the full range.

Like I said, I'm being picky :)
0
 
LVL 3

Author Closing Comment

by:Unimatrix_001
ID: 31467713
Sorry, just realised I hadn't closed this question!
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 21797963
Hiya rix, yeah I know what you mean although this application is purely for me, so I'm not too worried, although I'll bare that in mind...
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21797975
No worries... I couldn't find anything else to object to :)
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 21797985
:)
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21797992
Come on Uri... post more questions... I'm bored and EE is quiet tonight :)

*slap* :-s
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 21798011
Hahahaha! :D I'm all out of them at the mo... trying to figure out why something silly isn't working... :( Try your hand at... erm I dunno *looks at profile*... hardware?... or give yourself something to do for work tomorrow and create a uber-virus? ;)
0
 
LVL 40

Expert Comment

by:evilrix
ID: 21798029
uber-virus, you know that wouldn't not go down to well with my employer :)

I'm currently working on my CV atm... actually, more correctly my Wife is currently working on my CV!

I'm off to be in 5 anyway, have a good night my friend, until the next time.
0
 
LVL 3

Author Comment

by:Unimatrix_001
ID: 21798049
>>uber-virus, you know that wouldn't not go down to well with my employer :)
Think of it more of a form as job security... ;)

>>I'm off to be in 5 anyway, have a good night my friend, until the next time.
Catch you later mate... I'm planning on knocking off about now (I said that an hour ago though!) as well. Don't want to run past midnight if I can help it...

Laters. :)
Uni
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Getting IP address 8 100
Unresolved External Symbols 3 129
draw a Christmas tree by using a nested loop? 26 92
Are the two lines the same? If not what is the difference? 2 29
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question