Help needed c++ multimap

Joined
Nov 6, 2008
Messages
1
Reaction score
0
hello friends:!:
My 1st post in the forum and desperately need suggestion:oops:

The code: I am trying build a class to store particle in their coordinate using multimap.

Coordinate Particle level(unique)
(1,2,3) -----> 1
(3,5,6)------> 2
(1,2,3)------> 3
.
.
.

and so on.
I hope using multimap will be more efficient than using 4d array to retrieve information from time to time. But got stuck to some point for which i need help. I'll put up the whole code and appreciate suggestion.

1st the Cordinate Class:
typedef class container store;
typedef std:: pair<const store, int> Pair;
typedef std:: multimap< store, int > Box;

// 1st class container definition
class container
{
private:
int _i;
int _j;
int _k;
public:
container():_i(0),_j(0),_k(0){} //constructor

container(const int&i, const int&j, const int&k)
:_i(i),_j(j),_k(k){} //constructor

container(const container& t) //copy constructor
{ _i=t._i;
_j=t._j;
_k=t._k;}

bool operator>(const container& t)const
{ return k>t._k||_j>t._j||_i>t._i;} // need to understand

bool operator<(const container& t)const
{return _k<t._k||_j<t._j||_i<t._i;} // need to understand

bool operator()(const container& __x, const container& __y) const
{ return __x < __y; }

container & operator=(const container & t) //Assignment Operator
{
if (this == &t) // object assigned to itself
return *this; // all done
_i=t._i;
_j=t._j;
_k=t._k;
return *this;
}

friend std::eek:stream & operator<<(std::eek:stream & os, const container & t)
{
os << "(" << t._i << "," <<_j<<","<<t._k<<")";
return os;
}
~container(){}
};

The class store make the triplet. Next i write the code for map.

class _Map
{
private:
Box xx;

public:
_Map(){} //default constructor
void int_insert(const store &HOLD, const int &the_number)
{xx.insert(Pair(HOLD,the_number));} //HOLD is the index where the number is inserted

int WholeEraseByKey(const store &HOLD) //it also returns the number of erased elements
{
Box::size_type n;
n = xx.erase(HOLD);
return n;
}


void ShowMap()
{
Box::iterator pos;
std::cout.setf(std::ios::left, std::ios::adjustfield);

for (pos=xx.begin(); pos!=xx.end(); ++pos) {
std::cout << pos->first << " ->"
<< pos->second << std::endl;
}
}

~_Map(){}
};

I need to add certain more function to the class _Map. which are:


4. Searches the map for a specific Particle level, target
returns the key if target is found.
returns -1 if not found

5. union
places join at the end of arr
returns 1 if ok, and -1 if not .

6. free a particular Particle frm its present key (confused)
suppose i have this:
(1,2,3)--> 4
(1,2,3)--->9

i want to free particle 9 and later i'll assign it a new level.

I am totally clueless abt how to achieve these functionality
any help will be appreciated.

thanks
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,922
Messages
2,570,047
Members
46,475
Latest member
RacheleGri

Latest Threads

Top