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 » Community » Newbie corner » VectorMap picks two vectors
VectorMap picks two vectors [message #38153] Mon, 03 December 2012 02:54 Go to next message
nejnadusho is currently offline  nejnadusho
Messages: 60
Registered: October 2012
Member
Hi,

I can't figure out how to pick two vectors into a VectorMap.
I am even not sure I am expressing myself correctly.
Thus,

#include <Core/Core.h>
#include <iostream>

using namespace std;
using namespace Upp;

CONSOLE_APP_MAIN
{
	
	VectorMap<int , String> myMap;
	Vector<String>  v1;
	Vector<int>  v2;


	
	for (int i = 0; i < 10; ++i){
		
		v1.Add("String " + AsString(i));
		v2.Add(new Integer(i));	
	}
	
	for (int i = 0; i < 10; ++i){
		
		string a = v1[i];	
		cout << a << endl;
		cout << v2[i] << endl;	
	
	}
	
	myMap.AddPick(&v2, &v1);
	
}



I hope this is clear.

How can I push these two vectors into the VectorMap?

Thank you.

Best,
Georgi
Re: VectorMap picks two vectors [message #38155 is a reply to message #38153] Mon, 03 December 2012 04:10 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
		v2.Add(new Integer(i));	

This should not compile. You are supplying a Integer* (provided somewhere there is a class called Integer defined) to a function that expects a int

Simply:
      v2.Add(i);

will do.

As for VectorMap part, I think it's not intended to be used the way you use it. A VectorMap is a map which serves to find a value from a key. In your case you want to find a String from a int, you more likely should do something like this:
	VectorMap<int , String> myMap;


	
	for (int i = 0; i < 10; ++i){
	     myMap.Add(i, String().Cat()<<"String "<<i);	
	}
	


And later on you can efficiently find the String associated with an int or if there is one. Refer to Find(...), FindPtr() for template class AMap (who is the base of VectorMap)
Re: VectorMap picks two vectors [message #38156 is a reply to message #38153] Mon, 03 December 2012 05:56 Go to previous messageGo to next message
nejnadusho is currently offline  nejnadusho
Messages: 60
Registered: October 2012
Member
I am not sure if I expressed myself correctly.


First,I need to merge two vectors/arrays into one map like structure.

Second, being able to find the string by the integer.
However the integer value/key should be different than the position index.


I hope I am getting better in the explanations. Smile

Best
Georgi
Re: VectorMap picks two vectors [message #38157 is a reply to message #38156] Mon, 03 December 2012 06:30 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
OIC. so before merge, the two vectors have exact same number of elements and the ones with same index correspond to each other.

	VectorMap<int, String> myMap;
	Vector<String>  v1;
	Vector<int>  v2;


	
	for (int i = 0; i < 10; ++i){
		
		v1.Add("String " + AsString(i));
		v2.Add(i); // change here!!	
	}
	
	for (int i = 0; i < 10; ++i){
		
		string a = v1[i];	
		cout << a << endl;
		cout << v2[i] << endl;
                myMap.AddPick(v2[i],v1[i]); // do it here one by one
	
	}
	
	//myMap.AddPick(&v2, &v1); // correct me if there is a member function do what you intended in a single call.
	


HTH
Re: VectorMap picks two vectors [message #38159 is a reply to message #38153] Mon, 03 December 2012 06:46 Go to previous messageGo to next message
nejnadusho is currently offline  nejnadusho
Messages: 60
Registered: October 2012
Member
Lance,

Thank you.

I did exactly what you posted and it works.

I thought that there was a constructor that can merge them.

Best,
Georgi
Re: VectorMap picks two vectors [message #38161 is a reply to message #38157] Mon, 03 December 2012 07:18 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Lance wrote on Mon, 03 December 2012 06:30

correct me if there is a member function do what you intended in a single call
This can be done in single call, but only in constructor:
	Vector<String>  v1;
	Vector<int>  v2;

	for (int i = 0; i < 10; ++i){
		v1.Add("String " + AsString(i));
		v2.Add(i);
	}
	
	VectorMap<int, String> myMap(v2,v1);
	
	StdLogSetup(LOG_CERR);
	DUMP(v1.IsPicked());
	DUMP(v2.IsPicked());
	DUMPM(myMap);

Best regards,
Honza
Re: VectorMap picks two vectors [message #38181 is a reply to message #38161] Tue, 04 December 2012 00:49 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Hi Honza:

Thanks. That would suit nejnadusho's needs. He can always construct the VectorMap when both Vectors and ready. This might be a easy way of switching Key and Value in a VectorMap.

Re: VectorMap picks two vectors [message #38235 is a reply to message #38153] Fri, 07 December 2012 17:44 Go to previous message
nejnadusho is currently offline  nejnadusho
Messages: 60
Registered: October 2012
Member
Honza,

Thank you again.

That was exactly what I have been looking for.

Best,
Georgi
Previous Topic: Multi-Threading newbie questions
Next Topic: Fixed Frame Size Dockable Controls
Goto Forum:
  


Current Time: Sat Apr 20 13:34:27 CEST 2024

Total time taken to generate the page: 0.03201 seconds