Guest User

Untitled

a guest
Jun 18th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. [0, 1, 2, 4, 5, 28, 199]
  2.  
  3. type
  4. TSetType = set of TEnumType;
  5.  
  6. function HighestMember(const s: TSetType): TEnumType;
  7. begin
  8. for Result := High(Result) downto Low(Result) do
  9. if Result in s then
  10. exit;
  11. raise Exception.Create('empty sets have no highest member');
  12. end;
  13.  
  14. type
  15. TByteSet = set of Byte;
  16.  
  17. function HighestElement(const ByteSet: TByteSet): Byte;
  18. type
  19. TSetBytes = array[0..SizeOf(TByteSet) - 1] of Byte;
  20. var
  21. I, J: Integer;
  22. B: Byte;
  23. SetBytes: TSetBytes;
  24. begin
  25. if ByteSet <> [] then
  26. begin
  27. SetBytes := TSetBytes(ByteSet);
  28. // Start at the top and work down, one byte at a time
  29. for I := SizeOf(TByteSet) - 1 downto 0 do
  30. begin
  31. // Any bits set here
  32. B := SetBytes[I];
  33. if B <> 0 then
  34. begin
  35. Result := I * 8;
  36. for J := 0 to 7 do
  37. if (B shr J) and 1 <> 0 then
  38. begin
  39. Result := Result + J;
  40. Exit;
  41. end;
  42. end;
  43. end;
  44. end else
  45. // No elements set
  46. end;
Add Comment
Please, Sign In to add comment