Advertisement
runewalsh

Интерфейс факторизации уровня /dr/

Apr 25th, 2016
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.88 KB | None | 0 0
  1. type
  2.   Factorizer = class;
  3.  
  4.   InterceptionResult = (ContinueFactorization, ContinueAndReport);
  5.   Interception = class
  6.     constructor Create(theFact: Factorizer);
  7.     function Intercept: InterceptionResult;
  8.     function GetReport: TObject;
  9.     procedure Reported;
  10.   private
  11.     fact: Factorizer;
  12.   end;
  13.  
  14.   Algorithm = interface
  15.     function Factor(const n: BigInt; interception: Interception): BigInt;
  16.     function CreateReport: TObject;
  17.   end;
  18.  
  19.   Reporter = interface
  20.     procedure Report(rep: TObject);
  21.   end;
  22.  
  23.   PrimeStatus = (ValidPrime, StillNonPrime, DecompositionFailed);
  24.   NumberDecomposition = array of record
  25.     value: BigInt;
  26.     times: integer;
  27.     status: PrimeStatus;
  28.   end;
  29.  
  30.   FactorizationStatus = (FactorizationReady, FactorizationInProgress,
  31.     FactorizationCompleted, FactorizationStopped, FactorizationError);
  32.  
  33.   Factorizer = class
  34.     constructor Create(useAlgo: Algorithm; useReporter: Reporter; completionCallback: TNotifyEvent);
  35.     destructor Destroy; override;
  36.     procedure Run(const value: BigInt);
  37.     function Status: FactorizationStatus;
  38.     function Decomposition: NumberDecomposition;
  39.     function ErrorMessage: string;
  40.     procedure Stop;
  41.   private type
  42.     FactorizationThread = class(TThread)
  43.       constructor Create(theFact: Factorizer);
  44.     protected
  45.       procedure Execute; override;
  46.     private
  47.       fact: Factorizer;
  48.     end;
  49.  
  50.   var
  51.     cs: TRTLCriticalSection;
  52.     algo: Algorithm;
  53.     decomp: NumberDecomposition;
  54.     _reporter: Reporter;
  55.     _report: TObject;
  56.     _status: FactorizationStatus;
  57.     onComplete: TNotifyEvent;
  58.     errmsg: string;
  59.     thread: FactorizationThread;
  60.     procedure Lock;
  61.     procedure Unlock;
  62.     function Intercept: InterceptionResult;
  63.     procedure AddAnswer(const value: BigInt);
  64.     procedure RemoveAnswer(const value: BigInt);
  65.   end;
  66.   EFactorizationStopped = class(Exception) end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement