Home » U++ Library support » U++ Core » Understanding pick behaviour and containers
Understanding pick behaviour and containers [message #15627] |
Thu, 01 May 2008 21:09 |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |
|
|
Let`s say, one needs to have hashed container of some complex objects. OK, taking Index and putting some moveable and optional deep copy flavour to objects contained:
class AAA : public VectorMap<int, int>, public MoveableAndDeepCopyOption<AAA>
{
public:
AAA() {}
AAA(const AAA &, int) {}
unsigned GetHashValue() const {return 0;/*proxy here*/;}
};
CONSOLE_APP_MAIN
{
AAA a;
a.Add(10,1);
AAA a2(a);
Cout() << a2.GetCount();
Index<AAA> ai;
ai.Add(a2);
Cout() << " / " << ai[0].GetCount();
}
Output gives us 1 / 0. First value is OK, since first pick operation succeeded. Second one is zero, which is not right IMO: I added object to Index and it didn`t appear in the container.
When we talk about Vector or even VectorMap - it`s OK, we have AddPick() there, which works in this case.
So, why add operation didn`t work and how to solve this?
P.S. Why (pick_ != const) for MSC compiler?
[Updated on: Thu, 01 May 2008 21:12] Report message to a moderator
|
|
|
|
Re: Understanding pick behaviour and containers [message #15650 is a reply to message #15635] |
Fri, 02 May 2008 08:27 |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |
|
|
Mirek, also I want to suggest add
int AIndex::Find[Prev,Next,Last](unsigned _hash)
functions. What for?
Let`s see typical situation: I have a number of objects and I want them to be in quick access. For a number of reasons, Map doesn`t fit: i.e. key value is a natural part of internal object structure and cannot be taken out as different key object (it is possible but not good solution). Of course your hashed Index container is an ideal solution here.
Of course in some situations I want object to be found quickly and I can compute hash. But all I have in AIndex is AIndex::Find[Prev,Next,Last](const T& x, unsigned _hash)
But I don`t need this x variable, I just want object(s) who`s hash value is _hash. Also this function could make testing (are any objects with such hash value) easier.
[Updated on: Fri, 02 May 2008 08:29] Report message to a moderator
|
|
|
Re: Understanding pick behaviour and containers [message #15657 is a reply to message #15650] |
Fri, 02 May 2008 14:17 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
Mindtraveller wrote on Fri, 02 May 2008 02:27 | Mirek, also I want to suggest add
int AIndex::Find[Prev,Next,Last](unsigned _hash)
functions. What for?
Let`s see typical situation: I have a number of objects and I want them to be in quick access. For a number of reasons, Map doesn`t fit: i.e. key value is a natural part of internal object structure and cannot be taken out as different key object (it is possible but not good solution). Of course your hashed Index container is an ideal solution here.
Of course in some situations I want object to be found quickly and I can compute hash. But all I have in AIndex is AIndex::Find[Prev,Next,Last](const T& x, unsigned _hash)
But I don`t need this x variable, I just want object(s) who`s hash value is _hash. Also this function could make testing (are any objects with such hash value) easier.
|
Maybe you might want to use "HashBase" directly?
Mirek
|
|
|
|
|
Goto Forum:
Current Time: Tue Apr 23 21:42:13 CEST 2024
Total time taken to generate the page: 0.01421 seconds
|