सीधा जवाब TBits
वर्ग
http://docwiki.embarcadero.com/Libraries/Seattle/en/System.Classes.TBits.Bits
नोट होगा::
function ValidateInSet(AIntValue: integer; const AIntSet: TArray<Integer>): Boolean;
var
N: Integer;
begin
{ option1 : if AIntSet is always sorted }
result := TArray.BinarySearch(AIntSet, AIntValue, N);
{ option 2: works for any array }
result := false;
for N in AIntSet do begin
if AIntValue = N then begin
result := true;
Break;
end;
end;
if not Result then begin
// ...
end;
end;
कॉलिंग केवल एक सेट (श्रेणियों के लिए छोड़कर) के साथ के रूप में ही है यह केवल डेल्फी XE4 के साथ शुरू किया जा सकता है - http://qc.embarcadero.com/wc/qcmain.aspx?d=108829
हालांकि के लिए
अपने सबसे फुलाया मामले में "पूर्णांकों का सेट" यह स्मृति के 2^31/8
बाइट्स ले जाएगा (क्योंकि पूर्णांक के नकारात्मक मान भी विचार नहीं किया जाएगा), और कहा कि एक बहुत होगा ... तो मैं आशा है कि आप कभी भी पूर्ण पूर्णांक का सेट नहीं करना चाहेंगे। या आपको इसके बजाय स्पैर्स Arrays में निवेश करना चाहिए।
function ValidateInSet(const AIntValue: integer; const AIntSet: TBits): Boolean;
begin
Result := (AIntValue >= 0) and (AIntValue < AIntSet.Size);
if Result then
Result := AIntSet.Bits[AIntValue];
if not Result then ...
v-a-l-i-d-a-t-e
end;
या बल्कि
function ValidateInSet(const AIntValue: integer; const AIntSet: TBits): Boolean;
begin
Result := false;
if AIntValue < 0 then exit; // Validation criterion #1
if AIntValue >= AIntSet.Size then exit; // Validation criterion #2
if not AIntSet.Bits[AIntValue] then exit; // Validation criterion #3
if .... then exit; // Validation criterion #4
if .... then exit; // Validation criterion #5
if .... then exit; // Validation criterion #6
Result := true;
end;
या शायद
TSetTestCriterion = TFunc<Integer, Boolean>;
TSetTestCriteria = TArray<TFunc<Integer, Boolean>>;
function ValidateInSet(const AIntValue: integer;
const AIntSet: TBits; const Tests: TSetTestCriteria = nil): Boolean;
var ExtraTest: TSetTestCriterion;
begin
Result := false;
if AIntValue < 0 then exit; // Validation criterion #1
if AIntValue >= AIntSet.Size then exit; // Validation criterion #2
if not AIntSet.Bits[AIntValue] then exit; // Validation criterion #3
if Tests <> nil then // Validation criteria #4, #5, #6, ...
for ExtraTest in Tests do
if not ExtraTest(AIntValue) then exit;
Result := true;
end;
http://docwiki.embarcadero.com/Libraries/Seattle/en/System.SysUtils.TFunc
अब - बस डेमो के लिए, वास्तविक अनुप्रयोग में आप उन की स्थापना की और सरणी एक बार और कैश के लिए पैदा करेगा लंबे (हमेशा के लिए, या कम से कम जब तक कि कॉन्फ़िगरेशन परिवर्तन उन्हें पुनर्निर्माण की मांग नहीं करेगा)।
Type FuncIDs = (FUNCT_3 = 3, FUNCT_2 = 127, FUNCT_1 = 224);
var MysticGlobalFlag: Boolean;
function ValidateFuncID(const lFuncID: FuncIDs): Boolean;
var map: TBits;
begin
map := TBits.Create;
try
map.Size := High(lFuncID) + 1;
map.Bits[ Ord(Func_1) ] := True;
map.Bits[ Ord(Func_2) ] := True;
map.Bits[ Ord(Func_3) ] := True;
Result := ValidateInSet(Ord(lFuncID), map,
TSetTestCriteria.Create(
function(lFuncID: integer) : Boolean
begin
Result := MysticGlobalFlag or (lFuncID <> Ord(FuncIDs.FUNC_2))
end
,
function(lFuncID: integer) : Boolean
begin
Result := (lFuncID <> Ord(FuncIDs.FUNC_3)) or (DayOfTheWeek(Now()) = 4)
end
)
);
finally
map.Destroy;
end;
if not Result then // from the original question code
... // seems like a placeholder for error handling or object creation and registration
end;
Spring4D एक THashSet है: http://www.devjetsoftware.com/docs/spring4d/index.htm?Spring .Collections.Sets.THashSet% 28T% 29.IsSupersetOf.htm – Johan
मजेदार है कि एफपीसी में AFAIR एक बड़े सेट के रूप में बना सकता है क्योंकि स्मृति में प्रबंधन होता है। हालांकि मुझे यकीन नहीं है कि यह विशिष्ट डेल्फी सीमा वास्तव में एक लाभ नहीं है ... –
आप जेनेरिक सेट [यहां] (http://stackoverflow.com/a/19524788/576719) का उपयोग कर सकते हैं। –