Anybody know how can I speed up searching int64 array?

Anybody know how can I speed up searching int64 array?

procedure TInt64PointerArray.GetValue(const Key: Int64; out Value: pointer);
var
  i: integer;
  j: integer;
begin
  i := -1;
  for j := 0 to count - 1 do
    if key = Items[j] then begin
      i := j;
 value := FPointers[i];
      Exit;
    end;    
end;

Comments

  1. Short of using a binary array or an hash table,  if Items[j] maps to a method that returns an Int64, you might want to rewrite that using pointers or direct array access.
    Also you don't need the i/j index juggling (the compiler should optimize that away, but then again it may not).

    ReplyDelete
  2. TArray in System.Generics.Collections already has Sort and BinarySearch methods.

    ReplyDelete

Post a Comment