⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 algorithms.inc_h

📁 delphi的范型代码库
💻 INC_H
字号:
(*
 * DGL(The Delphi Generic Library)
 *
 * Copyright (c) 2004
 * HouSisong@263.net
 *
 * This material is provided "as is", with absolutely no warranty expressed
 * or implied. Any use is at your own risk.
 *
 * Permission to use or copy this software for any purpose is hereby granted
 * without fee, provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 *
 *)

//------------------------------------------------------------------------------
// DGL库的算法的声明
// Create by HouSisong, 2004.09.01
//------------------------------------------------------------------------------

//Algorithms.inc_h ; Algorithms.inc_pas

{$ifndef  __Algorithms_inc_h_}
{$define  __Algorithms_inc_h_}

{$I DGLIntf.inc_h}
{$I PointerItBox.inc_h}

  type
    __private_Algorithms_PValueType_Iterators=array [0..maxint div (sizeof(_ValueType))-1] of _ValueType;
    _PValueType_Iterator = ^__private_Algorithms_PValueType_Iterators;

  {$ifndef  _DGL_Compare}
    function _IsEqual(const Value0,Value1:_ValueType):boolean; {$ifdef _DGL_Inline} inline; {$endif} //todo: Warning inline on if _ValueType if "object" then error!!!
    function _IsLess(const Value0,Value1:_ValueType):boolean; {$ifdef _DGL_Inline} inline; {$endif}  //todo: Warning inline on if _ValueType if "object" then error!!!
  {$endif}
  {$ifndef  _DGL_Compare_Value}
    function _IsEqual_Value(const Value0,Value1:_ValueType):boolean; {$ifdef _DGL_Inline} inline; {$endif}  //todo: Warning inline on if _ValueType if "object" then error!!!
    function _IsLess_Value(const Value0,Value1:_ValueType):boolean; {$ifdef _DGL_Inline} inline; {$endif}   //todo: Warning inline on if _ValueType if "object" then error!!!
  {$endif}

type
  TGenerateFunction         = function (): _ValueType;
  TGenerateFunctionOfObject = function (): _ValueType of object;
  TTansfromFunction         = function (const Value: _ValueType): _ValueType;
  TTansfromFunctionOfObject = function (const Value: _ValueType): _ValueType of object;
  TTansfromBinaryFunction         = function (const Value0,Value1: _ValueType): _ValueType;
  TTansfromBinaryFunctionOfObject = function (const Value0,Value1: _ValueType): _ValueType of object;
  TVisitProc         = procedure (const Value: _ValueType);
  TVisitProcOfObject = procedure (const Value: _ValueType) of object;
  TTestFunction         = function (const Value:_ValueType):Boolean;
  TTestFunctionOfObject = function (const Value:_ValueType):Boolean Of Object;
  TTestBinaryFunction         = function (const Value0,Value1:_ValueType):Boolean;
  TTestBinaryFunctionOfObject = function (const Value0,Value1:_ValueType):Boolean Of Object;

  TRandomGenerateFunction         = function (const Range: Integer):integer; //0<=result<Range
  TRandomGenerateFunctionOfObject = function (const Range: Integer):integer Of Object;


type                             
  _TAlgorithms = class(TObject)
  public
  //todo: private
    class procedure SwapValue(const It0,It1:_PValueType_Iterator);overload;  {$ifdef _DGL_Inline} inline; {$endif}
    class procedure SwapValue(const It:_PValueType_Iterator;const Index0,Index1: integer);overload;   {$ifdef _DGL_Inline} inline; {$endif}
    class procedure SwapValue(const It0:_PValueType_Iterator;const Index0: integer;const It1:_PValueType_Iterator;const Index1: integer);overload; {$ifdef _DGL_Inline} inline; {$endif}
    class procedure Sort(const ItBegin,ItEnd:_PValueType_Iterator); overload;
    class procedure Sort(const ItBegin,ItEnd:_PValueType_Iterator;const TestBinaryFunction:TTestBinaryFunction); overload;
    class procedure Sort(const ItBegin,ItEnd:_PValueType_Iterator;const TestBinaryFunction:TTestBinaryFunctionOfObject); overload;
    class function  IsSorted(const ItBegin,ItEnd:_PValueType_Iterator):boolean; overload;
    class function  IsSorted(const ItBegin,ItEnd:_PValueType_Iterator;const TestBinaryFunction:TTestBinaryFunction):boolean; overload;
    class function  IsSorted(const ItBegin,ItEnd:_PValueType_Iterator;const TestBinaryFunction:TTestBinaryFunctionOfObject):boolean; overload;
    class function  LowerBound(const ItBegin,ItEnd:_PValueType_Iterator;const Value:_ValueType):_PValueType_Iterator; overload;
    class function  LowerBound(const ItBegin,ItEnd:_PValueType_Iterator;const Value:_ValueType;const TestBinaryFunction:TTestBinaryFunction):_PValueType_Iterator; overload;
    class function  LowerBound(const ItBegin,ItEnd:_PValueType_Iterator;const Value:_ValueType;const TestBinaryFunction:TTestBinaryFunctionOfObject):_PValueType_Iterator; overload;
  public
      {$I _Algorithms_Base.inc_h}
    {$define _DGL_VectorItType}
      {$I _Algorithms_Base.inc_h}
    {$undef  _DGL_VectorItType}
  end;
       
{$endif } // __Algorithms_inc_h_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -