• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 154
  • Last Modified:

Please validate function...

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
Unimatrix_001
Asked:
Unimatrix_001
  • 9
  • 4
  • 4
1 Solution
 
Infinity08Commented:
That looks good, yes. So, you've gone with indexes instead of iterators then :)
0
 
Unimatrix_001Author Commented:
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
 
Infinity08Commented:
Heh :) Good old indexes never let you down eh :)
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Unimatrix_001Author Commented:
They're strong (and as pretty) as a rock... :)
0
 
Infinity08Commented:
Now you're getting all poetic ... what's up today ? ;)
0
 
Unimatrix_001Author Commented:
Haha, I don't know what you mean... now where did I leave that Shakespeare sonnet volume...
0
 
Infinity08Commented:
/me hides ... This is getting too much for me lol
0
 
Unimatrix_001Author Commented:
:D
0
 
evilrixSenior Software Engineer (Avast)Commented:
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
 
Unimatrix_001Author Commented:
Sorry, just realised I hadn't closed this question!
0
 
Unimatrix_001Author Commented:
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
 
evilrixSenior Software Engineer (Avast)Commented:
No worries... I couldn't find anything else to object to :)
0
 
Unimatrix_001Author Commented:
:)
0
 
evilrixSenior Software Engineer (Avast)Commented:
Come on Uri... post more questions... I'm bored and EE is quiet tonight :)

*slap* :-s
0
 
Unimatrix_001Author Commented:
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
 
evilrixSenior Software Engineer (Avast)Commented:
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
 
Unimatrix_001Author Commented:
>>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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 9
  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now