BlackHornet
Member
|
Struggling with sorting
Hi,
I'm struggling a little bit with the following situtation:
class propeties:
Map<UID, NetProxy> Proxies(ProxyCreate, ProxyCompare);
Memc<NetProxy*> ProxiesToSync;
now i'm adding certain NetProxies from the Map to the Memc and want to sort them by NetProxy.Priority.
But defining the compare function makes me crazy:
Code:
Int CompareProxyPriority(C NetProxy* &a, C NetProxy* &b)
{
if (a.Priority < b.Priority) return -1;
if (a.Priority > b.Priority) return +1;
return 0;
}
was my thought but this don't compile...does anybody got a clue for me?
|
|
11-21-2012 01:01 PM |
|
fatcoder
Member
|
RE: Struggling with sorting
Code:
Int CompareProxyPriority(C NetProxy& a, C NetProxy& b)
{
if (a.Priority < b.Priority) return -1;
if (a.Priority > b.Priority) return +1;
return 0;
}
|
|
11-21-2012 02:27 PM |
|
Esenthel
Administrator
|
RE: Struggling with sorting
to sort the Memc use
Code:
Int CompareProxyPriority(NetProxy*C &a, NetProxy*C &b)
{
if (a.Priority < b.Priority) return -1;
if (a.Priority > b.Priority) return +1;
return 0;
}
|
|
11-21-2012 05:21 PM |
|
BlackHornet
Member
|
RE: Struggling with sorting
Thank you Esenthel, many thanks. Is there any chance on how to iterate a map? Or should i have to use a Meml (only to iterate) AND a Map to use/lookup key/values?
|
|
11-21-2012 05:44 PM |
|
Esenthel
Administrator
|
RE: Struggling with sorting
Map.h
Code:
Int elms ( )C; // get number of elements in container
void lock ( ) ; // lock elements container, unlock must be called after locking container
KEY & lockedKey ( Int i ) ; // access i-th element key from container, this can be used after locking and before unlocking the container
DATA& lockedData( Int i ) ; // access i-th element data from container, this can be used after locking and before unlocking the container
void unlock ( ) ; // unlock elements container, this must be called after locking the container
|
|
11-21-2012 05:52 PM |
|
BlackHornet
Member
|
RE: Struggling with sorting
ah, must be blinded...thanks alot
Code:
Proxies.lock();
FREPA(Proxies) Proxies.lockedData(i).Update(DeltaTime);
Proxies.unlock();
|
|
11-21-2012 05:59 PM |
|
wakin001@gmail.com
Member
|
RE: Struggling with sorting
(11-21-2012 05:21 PM)Esenthel Wrote: to sort the Memc use
Code:
Int CompareProxyPriority(NetProxy*C &a, NetProxy*C &b)
{
if (a.Priority < b.Priority) return -1;
if (a.Priority > b.Priority) return +1;
return 0;
}
I checked the definition of sort:
Code:
Memc& sort(Int compare(C TYPE& a, C TYPE &b));
So I think the compare function should be
Code:
Int CompareProxyPriority(C NetProxy &a, C NetProxy &b)
Why should I define it as
Code:
Int CompareProxyPriority(NetProxy*C &a, NetProxy*C &b)
{
if (a.Priority < b.Priority) return -1;
if (a.Priority > b.Priority) return +1;
return 0;
}
And what does "NetProxy*C &a" means?
|
|
06-30-2016 07:12 AM |
|
wakin001@gmail.com
Member
|
RE: Struggling with sorting
(06-30-2016 10:17 PM)aceio76 Wrote: Reference to a const pointer.
Thank you.
But for the definition of
Code:
Int compare(C TYPE& a, C TYPE &b);
Why should I define it as
Code:
Int CompareProxyPriority(C NetProxy &a, C NetProxy &b)
??
And for the same problem maybe, in
Code:
Memc<TYPE>::removeData(C TYPE* elm, bool keey_order)
If I define Class as
Code:
class Test
{
};
Memc<Test*> tests;
Test* test = new Test;
tests.addData(test);
tests.removeData(test); // ERROR! the error message is: you cannot change type from Test* to Test* const *.
Who knows the reason?
Thanks in advance.
|
|
07-01-2016 08:30 AM |
|