Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- Factorizer = class;
- InterceptionResult = (ContinueFactorization, ContinueAndReport);
- Interception = class
- constructor Create(theFact: Factorizer);
- function Intercept: InterceptionResult;
- function GetReport: TObject;
- procedure Reported;
- private
- fact: Factorizer;
- end;
- Algorithm = interface
- function Factor(const n: BigInt; interception: Interception): BigInt;
- function CreateReport: TObject;
- end;
- Reporter = interface
- procedure Report(rep: TObject);
- end;
- PrimeStatus = (ValidPrime, StillNonPrime, DecompositionFailed);
- NumberDecomposition = array of record
- value: BigInt;
- times: integer;
- status: PrimeStatus;
- end;
- FactorizationStatus = (FactorizationReady, FactorizationInProgress,
- FactorizationCompleted, FactorizationStopped, FactorizationError);
- Factorizer = class
- constructor Create(useAlgo: Algorithm; useReporter: Reporter; completionCallback: TNotifyEvent);
- destructor Destroy; override;
- procedure Run(const value: BigInt);
- function Status: FactorizationStatus;
- function Decomposition: NumberDecomposition;
- function ErrorMessage: string;
- procedure Stop;
- private type
- FactorizationThread = class(TThread)
- constructor Create(theFact: Factorizer);
- protected
- procedure Execute; override;
- private
- fact: Factorizer;
- end;
- var
- cs: TRTLCriticalSection;
- algo: Algorithm;
- decomp: NumberDecomposition;
- _reporter: Reporter;
- _report: TObject;
- _status: FactorizationStatus;
- onComplete: TNotifyEvent;
- errmsg: string;
- thread: FactorizationThread;
- procedure Lock;
- procedure Unlock;
- function Intercept: InterceptionResult;
- procedure AddAnswer(const value: BigInt);
- procedure RemoveAnswer(const value: BigInt);
- end;
- EFactorizationStopped = class(Exception) end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement