thanks Zach L., I never thought about using pointers in my case...my program is a sequence comparision algorithm...Prelude I know where the performance hit is coming from so I want to get around that...ill give you some details...check out this pseudocode (using only 4 letters here)...Code bottlenecks are marked with ASTERICKS (*)
seq1: ABBADDA (rep. as x-axis)
seq2: ABBCCDDAC (rep. as y-axis)
The result of this comparision is shown in the attachment picture. Please look at it to get a better idea of what i'm doing. If you notice, the first part in the algo. is to produce the match points in the sequences, and the second part is to sort them according to their c value (from y = mx + c) to get points which lie on lines with gradient = 1.
Code:
Define: vector_A
Define: vector_B
Define: vector_C
Define: vector_D
struct COORD
{
int x, y; //for the coordinates
char name; //for which letter it represents
};
//c_value = (y-cord - x-cord)
Define: MULTIMAP with COORD and c_value (key) as pairs
Define: MAP_OF_KEYS of c_value
int counter = 1;
Read seq1 //char by char
{
If A then push counter on vector_A
If B then push counter on vector_B
If C then push counter on vector_C
If D then push counter on vector_D
counter ++; //x-value
}
counter = 1; //reset counter
Read seq2 //char by char
{
If A then
{
for all x in vector_A ***1***
{
c_value = counter - x; //counter is now the y-value
initialize new COORD
coord.x = x;
coord.y = counter;
coord.name = A;
push the pair coord and c_value (as key) on the map;
push c_value on the MAP_OF_KEYS; ***2***
}
}
//similarly for the other letters
}
e.g. At the end of it the 'maps' will look like this:
Code:
MULTIMAP:
[(x=1,y=1) Name=A ] ; Key=0
[(x=2,y=2) Name=B ] ; Key=0
[(x=3,y=3) Name=B ] ; Key=0
[(x=5,y=6) Name=D ] ; Key=1
[(x=6,y=7) Name=D ] ; Key=1
[(x=7,y=8) Name=A ] ; Key=1
MAP_OF_KEYS: //not considering the other element in the pair
Key = 0
Key = 1
***1***: Each time I get an A on the y-axis, I'll have to go through this vector...It's ok right now but when I have let's say 1000 elements in this vector and I get let's say 500 A's on the y-axis (it won't be pretty)
***2***: Why make this map. If I could just collate the same key values from the multimap somehow using map.find(), it would save me a lot of resources.