Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » VectorIndex
icon9.gif  VectorIndex [message #24158] Wed, 30 December 2009 10:14 Go to next message
exdatis is currently offline  exdatis
Messages: 7
Registered: December 2009
Location: Vojvodina
Promising Member
Is that right ?

int index_test = 0;
for(Vector<TownLs>::Iterator q = ls_town->Begin(), e = ls_town->End(); q != e; q++)
{
TownLs temp = *q;
if(temp.getName() == "Pancevo")
break;
index_test++;
}
PromptOK(AsString(index_test)); // index

//desc: ls_town is pointer (Vector<TownLs>)

Better method, any?

Thanks.

[Updated on: Wed, 30 December 2009 10:19]

Report message to a moderator

Re: VectorIndex [message #24161 is a reply to message #24158] Wed, 30 December 2009 11:31 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi exdatis,

You can write it without the ugly iterators as
int index_test;
for(index_test = 0; index_test < ls_town->GetCount(); index_test++){
	if((*ls_town)[index_test].getName()=="Pancevo") break;
}
PromptOK(AsString(index_test));

There are probably even better/faster solutions, but those would depend on how TownLs class looks like...

Best regards,
Honza

EDIT:Oups, I missed that ls_town is a pointer Embarassed Corrected now Wink

[Updated on: Wed, 30 December 2009 11:45]

Report message to a moderator

icon14.gif  Re: VectorIndex [message #24162 is a reply to message #24161] Wed, 30 December 2009 12:02 Go to previous messageGo to next message
exdatis is currently offline  exdatis
Messages: 7
Registered: December 2009
Location: Vojvodina
Promising Member
Thank You!
That's right!
//
TownLs is a simple,
id and town_name, ... (db.table) ,couple methods.
and Vector* is arg for others (fill drop_grid in some form/class).
index, just for update(
if(*q.GetId() == int_town_id) break;
), append is easy.
//
Is that ok?

[Updated on: Wed, 30 December 2009 12:18]

Report message to a moderator

Re: VectorIndex [message #24164 is a reply to message #24158] Wed, 30 December 2009 12:06 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
exdatis wrote on Wed, 30 December 2009 04:14

Is that right ?

int index_test = 0;
for(Vector<TownLs>::Iterator q = ls_town->Begin(), e = ls_town->End(); q != e; q++)
{
TownLs temp = *q;
if(temp.getName() == "Pancevo")
break;
index_test++;
}
PromptOK(AsString(index_test)); // index

//desc: ls_town is pointer (Vector<TownLs>)

Better method, any?

Thanks.


Consider using Index instead of Vector...

Mirek
Re: VectorIndex [message #24165 is a reply to message #24164] Wed, 30 December 2009 13:36 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

luzr wrote on Wed, 30 December 2009 12:06

Consider using Index instead of Vector...


That's exactly what I thought by "faster solutions" Smile
Another (maybe easier) way would be VectorMap...

Honza
Re: VectorIndex [message #24169 is a reply to message #24165] Thu, 31 December 2009 01:23 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
dolik.rce wrote on Wed, 30 December 2009 07:36

luzr wrote on Wed, 30 December 2009 12:06

Consider using Index instead of Vector...


That's exactly what I thought by "faster solutions" Smile
Another (maybe easier) way would be VectorMap...

Honza


Well, this slow is like slow recreaction of Index Smile

Speaking about it, there is also slow iteration algorithm in U++ which something similiar, "FindIndex".

Mirek
Previous Topic: FtpClient use with Progress FIX
Next Topic: ptr
Goto Forum:
  


Current Time: Sat Apr 27 03:30:23 CEST 2024

Total time taken to generate the page: 3.90084 seconds