2
0

IdHashElf.pas 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. { $HDR$}
  2. {**********************************************************************}
  3. { Unit archived using Team Coherence }
  4. { Team Coherence is Copyright 2002 by Quality Software Components }
  5. { }
  6. { For further information / comments, visit our WEB site at }
  7. { http://www.TeamCoherence.com }
  8. {**********************************************************************}
  9. {}
  10. { $Log: 10181: IdHashElf.pas
  11. {
  12. { Rev 1.0 2002.11.12 10:40:14 PM czhower
  13. }
  14. unit IdHashElf;
  15. interface
  16. uses
  17. Classes,
  18. IdHash;
  19. type
  20. TIdHashElf = class(TIdHash32)
  21. public
  22. function HashValue(AStream: TStream): LongWord; override;
  23. end;
  24. implementation
  25. { TIdHashElf }
  26. function TIdHashElf.HashValue(AStream: TStream): LongWord;
  27. var
  28. i: Integer;
  29. LByte: Byte;
  30. LTemp: LongWord;
  31. begin
  32. Result := 0;
  33. AStream.Position := 0;
  34. // Faster than a while - While would read .Size which is slow
  35. for i := 1 to AStream.Size do begin
  36. AStream.ReadBuffer(LByte, SizeOf(LByte));
  37. Result := (Result shl 4) + LByte;
  38. LTemp := Result and $F0000000;
  39. if LTemp <> 0 then begin
  40. Result := Result xor (LTemp Shr 24);
  41. end;
  42. Result := Result and not LTemp;
  43. end;
  44. end;
  45. end.