Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [0, 1, 2, 4, 5, 28, 199]
- type
- TSetType = set of TEnumType;
- function HighestMember(const s: TSetType): TEnumType;
- begin
- for Result := High(Result) downto Low(Result) do
- if Result in s then
- exit;
- raise Exception.Create('empty sets have no highest member');
- end;
- type
- TByteSet = set of Byte;
- function HighestElement(const ByteSet: TByteSet): Byte;
- type
- TSetBytes = array[0..SizeOf(TByteSet) - 1] of Byte;
- var
- I, J: Integer;
- B: Byte;
- SetBytes: TSetBytes;
- begin
- if ByteSet <> [] then
- begin
- SetBytes := TSetBytes(ByteSet);
- // Start at the top and work down, one byte at a time
- for I := SizeOf(TByteSet) - 1 downto 0 do
- begin
- // Any bits set here
- B := SetBytes[I];
- if B <> 0 then
- begin
- Result := I * 8;
- for J := 0 to 7 do
- if (B shr J) and 1 <> 0 then
- begin
- Result := Result + J;
- Exit;
- end;
- end;
- end;
- end else
- // No elements set
- end;
Add Comment
Please, Sign In to add comment