About Store Forum Documentation Contact



Post Reply 
Struggling with sorting
Author Message
BlackHornet Offline
Member

Post: #1
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
Visit this user's website Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #2
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
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
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
Find all posts by this user Quote this message in a reply
BlackHornet Offline
Member

Post: #4
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
Visit this user's website Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
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
Find all posts by this user Quote this message in a reply
BlackHornet Offline
Member

Post: #6
RE: Struggling with sorting
ah, must be blinded...thanks alot smile

Code:
Proxies.lock();
FREPA(Proxies) Proxies.lockedData(i).Update(DeltaTime);
Proxies.unlock();
11-21-2012 05:59 PM
Visit this user's website Find all posts by this user Quote this message in a reply
wakin001@gmail.com Offline
Member

Post: #7
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?
(This post was last modified: 06-30-2016 07:15 AM by wakin001@gmail.com.)
06-30-2016 07:12 AM
Find all posts by this user Quote this message in a reply
wakin001@gmail.com Offline
Member

Post: #8
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
Find all posts by this user Quote this message in a reply
Post Reply