Re: identifying same element



Forget my previous comments. This is the crucial comment:

> Value: Integer; // where 1 < Value < 20

Because of the small range this can be implemented very efficiently and
wih linear complexity. A sample follows below.

If the range would be larger a similar solution with a hash table would
possible; here this is not even needed.

const
ITEMREC_MAX_VALUE = 20;
ITEMREC_MIN_VALUE = 1;

type
TItemRec = record
Value: Integer; // where 1 < Value < 20
Marker: Boolean;
end;

TSampleItems = array[1..50] of TItemRec;

procedure MarkDuplicates(var SampleItems: TSampleItems);
var
I: Integer;
ValueCount: array[ITEMREC_MIN_VALUE..ITEMREC_MAX_VALUE] of Integer;
begin
FillChar(ValueCount, SizeOf(ValueCount), $00);
for I := Low(SampleItems) to High(SampleItems) do
Inc(ValueCount[SampleItems[I].Value]);
for I := Low(SampleItems) to High(SampleItems) do
SampleItems[I].Marker := ValueCount[SampleItems[I].Value] > 1;
end;
.