3
Aiming at the union represented by the figure:
In view of the structure below:
TMyRecord = record
Index: Int64;
Kind: TMyEnum;
Value: String;
end
Having two lists (Generics.Collections.TList<TMyRecord>
) A and B use the following method to achieve the union:
ListA.AddRange(ListB.ToArray);
ListA.TrimExcess;
The problem with this method is that it results in low performance for lengths above 400 elements per list.
Another requirement would be to maintain the order where after the last element of A the first of B is to be found. Such ordination would hinder the use of parallelism.
Therefore, what would be some effective ways to achieve union guaranteeing performance and ordination?
What is the content of the record?
– DH.
Okay I saw you put the record structure, then check what’s equal you’re doing how? (I get that it’s compiler stuff, but I don’t know what you want to do yet, so it doesn’t hurt to ask)
– DH.
There is no such check. I should simply concatenate the two lists somehow. It is a part of the Tokens.
– Guill
Well, the index I believe is the ordering of the disposition of your lexemas, so what I suggest to you is this: order both lists, and then iterate step by step, always keeping the A with the lowest index. If the index of A is higher than that of B means that it does not have the lexema, and then you can add it in the middle of the list, in the position before the current of your iteration. Even with the extra sorting step, if the sorting is given by the index you will probably get better performance.
– DH.
I don’t think you understand the question.
– Guill
Oh right, I reread it two more times and finally understood what you want. This is a very common problem of using lists... The method of
AddRange
is usually not optimized in any language... The first thing I would try to do is tofor each
of List B givingAdd
in List A. Very stupid, but maybe I’ll give you some performance gain.– DH.
I believe you don’t have much to do, because adding a list to another is an On operation, where n is the amount of elements on your list, as you have to go through all the elements on your list, the more elements on your list, the longer the operation will be
– Passella
You tried to use the
addRange
without converting theListaB
to arrray? Gave some difference?– EMBarbosa