Y
Yves Dhondt
Hello,
I've got the following UML design :
C
|
A _____|______ B
So 2 objects A and B are connected through a relation C. (For example an
employment scheme : person A1 worked for company B1 at time C1, person
A1 worked for company B2 at time C2, person A2 worked for company B1 at
time C3, ...)
My current implementation exists of :
public class objectA { ... }
public class objectB { ... }
public class relationC {
private objectA A;
private objectB B;
// other things about the relation
}
I use a list with all relationCs in it. This takes not much memory but
if I want to check which objectB's are connected to an objectA or vice
versa, I need to check every relationC.
ArrayList result = new ArrayList();
foreach (relationC c in list)
{
if (c.getA().equals(A))
{
result.Add(c.getB())
}
}
Considering the fact I have about 10000 objectA's and 25 objectB's I can
have up to 250000 relationC's to check which makes my implementation
rather slow.
I considered adding direct links from A to B :
public class objectA {
private ArrayList objectBs
// ...
}
and the same the other way around but then the amount of memory used
goes up pretty fast.
I wonder if someone has an idea on how to make this faster without
needing a huge memory chunk.
TIA
Yves
I've got the following UML design :
C
|
A _____|______ B
So 2 objects A and B are connected through a relation C. (For example an
employment scheme : person A1 worked for company B1 at time C1, person
A1 worked for company B2 at time C2, person A2 worked for company B1 at
time C3, ...)
My current implementation exists of :
public class objectA { ... }
public class objectB { ... }
public class relationC {
private objectA A;
private objectB B;
// other things about the relation
}
I use a list with all relationCs in it. This takes not much memory but
if I want to check which objectB's are connected to an objectA or vice
versa, I need to check every relationC.
ArrayList result = new ArrayList();
foreach (relationC c in list)
{
if (c.getA().equals(A))
{
result.Add(c.getB())
}
}
Considering the fact I have about 10000 objectA's and 25 objectB's I can
have up to 250000 relationC's to check which makes my implementation
rather slow.
I considered adding direct links from A to B :
public class objectA {
private ArrayList objectBs
// ...
}
and the same the other way around but then the amount of memory used
goes up pretty fast.
I wonder if someone has an idea on how to make this faster without
needing a huge memory chunk.
TIA
Yves