JoinToString, IndicesOf
This commit is contained in:
parent
c742d0bf3e
commit
98af0d324e
|
|
@ -15,7 +15,7 @@ internal static class RevisionClass
|
|||
public const string Major = "3";
|
||||
public const string Minor = "6";
|
||||
public const string Build = "0";
|
||||
public const string Revision = "2319";
|
||||
public const string Revision = "2326";
|
||||
|
||||
public const string MainVersion = Major + "." + Minor;
|
||||
public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
%MINOR%=6
|
||||
%REVISION%=2319
|
||||
%COREVERSION%=0
|
||||
%REVISION%=2326
|
||||
%MINOR%=6
|
||||
%MAJOR%=3
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -5,7 +5,7 @@
|
|||
<param name="Keyword" value="ForEach">
|
||||
<param name="Keyword" value="Incremental">
|
||||
<param name="Keyword" value="Interleave">
|
||||
<param name="Keyword" value="JoinIntoString">
|
||||
<param name="Keyword" value="JoinToString">
|
||||
<param name="Keyword" value="LastMaxBy">
|
||||
<param name="Keyword" value="LastMinBy">
|
||||
<param name="Keyword" value="MaxBy">
|
||||
|
|
@ -74,9 +74,9 @@
|
|||
<br> Чередует элементы трех последовательностей</td></tr>
|
||||
<tr><td><code><b>function</b> Interleave<T>(Self: <b>sequence </b> <b>of</b> T; a, b, c: <b>sequence </b> <b>of</b> T): <b>sequence </b> <b>of</b> T;</code>
|
||||
<br> Чередует элементы четырех последовательностей</td></tr>
|
||||
<tr><td><code><b>function</b> JoinIntoString<T>(Self: <b>sequence </b> <b>of</b> T; delim: string): string;</code>
|
||||
<tr><td><code><b>function</b> JoinToString<T>(Self: <b>sequence </b> <b>of</b> T; delim: string): string;</code>
|
||||
<br> Преобразует элементы последовательности в строковое представление, после чего объединяет их в строку, используя delim в качестве разделителя</td></tr>
|
||||
<tr><td><code><b>function</b> JoinIntoString<T>(Self: <b>sequence </b> <b>of</b> T): string;</code>
|
||||
<tr><td><code><b>function</b> JoinToString<T>(Self: <b>sequence </b> <b>of</b> T): string;</code>
|
||||
<br> Преобразует элементы последовательности в строковое представление, после чего объединяет их в строку, используя пробел в качестве разделителя</td></tr>
|
||||
<tr><td><code><b>function</b> LastMaxBy<T, TKey>(Self: <b>sequence </b> <b>of</b> T; selector: T->TKey): T;</code>
|
||||
<br> Возвращает последний элемент последовательности с максимальным значением ключа</td></tr>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<HTML><HEAD><object type="application/x-oleobject" classid="clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e">
|
||||
<param name="Keyword" value="Between">
|
||||
<param name="Keyword" value="IndicesOf">
|
||||
<param name="Keyword" value="InRange">
|
||||
<param name="Keyword" value="Inverse">
|
||||
<param name="Keyword" value="IsMatch">
|
||||
|
|
@ -26,6 +27,8 @@
|
|||
</HEAD><body><H1>Ìåòîäû ðàñøèðåíèÿ òèïà string</H1>
|
||||
<table border=0 cellpadding=5><tr><td><code><b>function</b> Between(Self: string; a, b: string): boolean;</code>
|
||||
<br> Âîçâðàùàåò True åñëè çíà÷åíèå íàõîäèòñÿ ìåæäó äâóìÿ äðóãèìè</td></tr>
|
||||
<tr><td><code><b>function</b> IndicesOf(Self, SubS: string; overlay: boolean := False): <b>array</b> <b>of</b> integer;</code>
|
||||
<br> Âîçâðàùàåò ìàññèâ èíäåêñîâ âõîæäåíèé ïîäñòðîêè â îñíîâíóþ ñòðîêóÏàðàìåòð overlay îïðåäåëÿåò, ðàçðåøåíû ëè ïåðåêðûòèÿ âõîæäåíèé ïîäñòðîê</td></tr>
|
||||
<tr><td><code><b>function</b> InRange(Self: string; a,b: string): boolean;</code>
|
||||
<br> Âîçâðàùàåò True åñëè çíà÷åíèå íàõîäèòñÿ ìåæäó äâóìÿ äðóãèìè</td></tr>
|
||||
<tr><td><code><b>function</b> Inverse(Self: string): string;</code>
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
3.6.0.2319
|
||||
3.6.0.2326
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
!define VERSION '3.6.0.2319'
|
||||
!define VERSION '3.6.0.2326'
|
||||
|
|
|
|||
|
|
@ -13,19 +13,28 @@
|
|||
|
||||
///
|
||||
///Код переведён отсюда:
|
||||
/// https://github.com/KhronosGroup/OpenCL-Headers/tree/master/CL
|
||||
/// https://github.com/KhronosGroup/OpenCL-Headers/tree/master/CL
|
||||
///
|
||||
///Спецификации всех версий:
|
||||
/// https://www.khronos.org/registry/OpenCL/
|
||||
/// https://www.khronos.org/registry/OpenCL/
|
||||
///
|
||||
///Если не хватает функции, перечисления, или найдена ошибка - писать сюда:
|
||||
/// https://github.com/SunSerega/POCGL/issues
|
||||
/// https://github.com/SunSerega/POCGL/issues
|
||||
///
|
||||
unit OpenCL;
|
||||
|
||||
uses System;
|
||||
uses System.Runtime.InteropServices;
|
||||
|
||||
{$region Debug}
|
||||
|
||||
{ $define DebugMode}
|
||||
{$ifdef DebugMode}
|
||||
|
||||
{$endif DebugMode}
|
||||
|
||||
{$endregion Debug}
|
||||
|
||||
{$region Основные типы}
|
||||
|
||||
type
|
||||
|
|
@ -37,19 +46,23 @@ type
|
|||
cl_mem = IntPtr;
|
||||
cl_program = IntPtr;
|
||||
cl_kernel = IntPtr;
|
||||
cl_event = IntPtr;
|
||||
cl_sampler = IntPtr;
|
||||
{$ifndef DebugMode}
|
||||
cl_event = IntPtr;
|
||||
{$endif !DebugMode}
|
||||
|
||||
///0 = false, остальное = true
|
||||
cl_bool = UInt32;
|
||||
cl_bitfield = UInt64;
|
||||
|
||||
type
|
||||
OpenCLException = class(Exception)
|
||||
OpenCLException = sealed class(Exception)
|
||||
|
||||
constructor(text: string) :=
|
||||
public constructor(text: string) :=
|
||||
inherited Create($'Ошибка OpenCL: "{text}"');
|
||||
|
||||
public constructor(err_code: UInt32);
|
||||
|
||||
end;
|
||||
|
||||
{$endregion Основные типы}
|
||||
|
|
@ -134,8 +147,10 @@ type
|
|||
res.Name.ToWords('_').Select(w->w[1].ToUpper+w.Substring(1).ToLower).JoinIntoString;
|
||||
end;
|
||||
|
||||
public function IS_ERROR := val<>SUCCESS;
|
||||
|
||||
public procedure RaiseIfError :=
|
||||
if val<>SUCCESS then raise new OpenCLException(self.ToString);
|
||||
if IS_ERROR then raise new OpenCLException(self.ToString);
|
||||
|
||||
end;
|
||||
|
||||
|
|
@ -906,6 +921,9 @@ type
|
|||
$'CommandExecutionStatus[{self.val}]';
|
||||
end;
|
||||
|
||||
public procedure RaiseIfError :=
|
||||
if val<0 then ErrorCode.Create(val).RaiseIfError;
|
||||
|
||||
end;
|
||||
|
||||
//SR
|
||||
|
|
@ -1388,6 +1406,29 @@ type
|
|||
|
||||
{$endregion Перечисления}
|
||||
|
||||
{$region Debug}
|
||||
|
||||
{$ifdef DebugMode}
|
||||
|
||||
type
|
||||
cl_event = record
|
||||
public val: IntPtr;
|
||||
public constructor := exit;
|
||||
public static Zero := new cl_event;
|
||||
public static Size := sizeof(cl_event);
|
||||
|
||||
private function GetRefCount: IntPtr;
|
||||
public property RefCount: IntPtr read GetRefCount;
|
||||
|
||||
private function GetState: CommandExecutionStatus;
|
||||
public property State: CommandExecutionStatus read GetState;
|
||||
|
||||
end;
|
||||
|
||||
{$endif DebugMode}
|
||||
|
||||
{$endregion Debug}
|
||||
|
||||
{$region Делегаты}
|
||||
|
||||
type
|
||||
|
|
@ -1632,18 +1673,18 @@ type
|
|||
external 'opencl.dll' name 'clEnqueueReadBuffer';
|
||||
static function EnqueueReadBuffer(command_queue: cl_command_queue; buffer: cl_mem; blocking_read: cl_bool; offset: UIntPtr; size: UIntPtr; ptr: IntPtr; num_events_in_wait_list: UInt32; event_wait_list: ^cl_event; &event: ^cl_event): ErrorCode;
|
||||
external 'opencl.dll' name 'clEnqueueReadBuffer';
|
||||
static function EnqueueReadBuffer(command_queue: cl_command_queue; buffer: cl_mem; blocking_read: cl_bool; offset: UIntPtr; size: UIntPtr; ptr: pointer; num_events_in_wait_list: UInt32; [MarshalAs(UnmanagedType.LPArray)] event_wait_list: array of cl_event; var &event: cl_event): ErrorCode;
|
||||
static function EnqueueReadBuffer(command_queue: cl_command_queue; buffer: cl_mem; blocking_read: cl_bool; offset: UIntPtr; size: UIntPtr; [MarshalAs(UnmanagedType.LPArray)] data: &Array; num_events_in_wait_list: UInt32; [MarshalAs(UnmanagedType.LPArray)] event_wait_list: array of cl_event; var &event: cl_event): ErrorCode;
|
||||
external 'opencl.dll' name 'clEnqueueReadBuffer';
|
||||
static function EnqueueReadBuffer(command_queue: cl_command_queue; buffer: cl_mem; blocking_read: cl_bool; offset: UIntPtr; size: UIntPtr; ptr: pointer; num_events_in_wait_list: UInt32; event_wait_list: ^cl_event; &event: ^cl_event): ErrorCode;
|
||||
static function EnqueueReadBuffer(command_queue: cl_command_queue; buffer: cl_mem; blocking_read: cl_bool; offset: UIntPtr; size: UIntPtr; [MarshalAs(UnmanagedType.LPArray)] data: &Array; num_events_in_wait_list: UInt32; event_wait_list: ^cl_event; &event: ^cl_event): ErrorCode;
|
||||
external 'opencl.dll' name 'clEnqueueReadBuffer';
|
||||
|
||||
static function EnqueueWriteBuffer(command_queue: cl_command_queue; buffer: cl_mem; blocking_write: cl_bool; offset: UIntPtr; size: UIntPtr; ptr: IntPtr; num_events_in_wait_list: UInt32; [MarshalAs(UnmanagedType.LPArray)] event_wait_list: array of cl_event; var &event: cl_event): ErrorCode;
|
||||
external 'opencl.dll' name 'clEnqueueWriteBuffer';
|
||||
static function EnqueueWriteBuffer(command_queue: cl_command_queue; buffer: cl_mem; blocking_write: cl_bool; offset: UIntPtr; size: UIntPtr; ptr: IntPtr; num_events_in_wait_list: UInt32; event_wait_list: ^cl_event; &event: ^cl_event): ErrorCode;
|
||||
external 'opencl.dll' name 'clEnqueueWriteBuffer';
|
||||
static function EnqueueWriteBuffer(command_queue: cl_command_queue; buffer: cl_mem; blocking_write: cl_bool; offset: UIntPtr; size: UIntPtr; ptr: pointer; num_events_in_wait_list: UInt32; [MarshalAs(UnmanagedType.LPArray)] event_wait_list: array of cl_event; var &event: cl_event): ErrorCode;
|
||||
static function EnqueueWriteBuffer(command_queue: cl_command_queue; buffer: cl_mem; blocking_write: cl_bool; offset: UIntPtr; size: UIntPtr; [MarshalAs(UnmanagedType.LPArray)] data: &Array; num_events_in_wait_list: UInt32; [MarshalAs(UnmanagedType.LPArray)] event_wait_list: array of cl_event; var &event: cl_event): ErrorCode;
|
||||
external 'opencl.dll' name 'clEnqueueWriteBuffer';
|
||||
static function EnqueueWriteBuffer(command_queue: cl_command_queue; buffer: cl_mem; blocking_write: cl_bool; offset: UIntPtr; size: UIntPtr; ptr: pointer; num_events_in_wait_list: UInt32; event_wait_list: ^cl_event; &event: ^cl_event): ErrorCode;
|
||||
static function EnqueueWriteBuffer(command_queue: cl_command_queue; buffer: cl_mem; blocking_write: cl_bool; offset: UIntPtr; size: UIntPtr; [MarshalAs(UnmanagedType.LPArray)] data: &Array; num_events_in_wait_list: UInt32; event_wait_list: ^cl_event; &event: ^cl_event): ErrorCode;
|
||||
external 'opencl.dll' name 'clEnqueueWriteBuffer';
|
||||
|
||||
static function EnqueueCopyBuffer(command_queue: cl_command_queue; src_buffer: cl_mem; dst_buffer: cl_mem; src_offset: UIntPtr; dst_offset: UIntPtr; size: UIntPtr; num_events_in_wait_list: UInt32; [MarshalAs(UnmanagedType.LPArray)] event_wait_list: array of cl_event; var &event: cl_event): ErrorCode;
|
||||
|
|
@ -1678,9 +1719,9 @@ type
|
|||
static function EnqueueCopyBufferRect(command_queue: cl_command_queue; src_buffer: cl_mem; dst_buffer: cl_mem; src_origin: ^UIntPtr; dst_origin: ^UIntPtr; region: ^UIntPtr; src_row_pitch: UIntPtr; src_slice_pitch: UIntPtr; dst_row_pitch: UIntPtr; dst_slice_pitch: UIntPtr; num_events_in_wait_list: UInt32; event_wait_list: ^cl_event; &event: ^cl_event): ErrorCode;
|
||||
external 'opencl.dll' name 'clEnqueueCopyBufferRect';
|
||||
|
||||
static function EnqueueFillBuffer(command_queue: cl_command_queue; buffer: cl_mem; [MarshalAs(UnmanagedType.LPArray)] pattern: array of byte; pattern_size: UIntPtr; offset: UIntPtr; size: UIntPtr; num_events_in_wait_list: UInt32; [MarshalAs(UnmanagedType.LPArray)] event_wait_list: array of cl_event; var &event: cl_event): ErrorCode;
|
||||
static function EnqueueFillBuffer(command_queue: cl_command_queue; buffer: cl_mem; [MarshalAs(UnmanagedType.LPArray)] pattern: &Array; pattern_size: UIntPtr; offset: UIntPtr; size: UIntPtr; num_events_in_wait_list: UInt32; [MarshalAs(UnmanagedType.LPArray)] event_wait_list: array of cl_event; var &event: cl_event): ErrorCode;
|
||||
external 'opencl.dll' name 'clEnqueueFillBuffer';
|
||||
static function EnqueueFillBuffer(command_queue: cl_command_queue; buffer: cl_mem; [MarshalAs(UnmanagedType.LPArray)] pattern: array of byte; pattern_size: UIntPtr; offset: UIntPtr; size: UIntPtr; num_events_in_wait_list: UInt32; event_wait_list: ^cl_event; &event: ^cl_event): ErrorCode;
|
||||
static function EnqueueFillBuffer(command_queue: cl_command_queue; buffer: cl_mem; [MarshalAs(UnmanagedType.LPArray)] pattern: &Array; pattern_size: UIntPtr; offset: UIntPtr; size: UIntPtr; num_events_in_wait_list: UInt32; event_wait_list: ^cl_event; &event: ^cl_event): ErrorCode;
|
||||
external 'opencl.dll' name 'clEnqueueFillBuffer';
|
||||
static function EnqueueFillBuffer(command_queue: cl_command_queue; buffer: cl_mem; pattern: IntPtr; pattern_size: UIntPtr; offset: UIntPtr; size: UIntPtr; num_events_in_wait_list: UInt32; [MarshalAs(UnmanagedType.LPArray)] event_wait_list: array of cl_event; var &event: cl_event): ErrorCode;
|
||||
external 'opencl.dll' name 'clEnqueueFillBuffer';
|
||||
|
|
@ -2337,4 +2378,29 @@ type
|
|||
|
||||
end;
|
||||
|
||||
{$region Impl}
|
||||
|
||||
constructor OpenCLException.Create(err_code: UInt32) :=
|
||||
Create(ErrorCode.Create(err_code).ToString);
|
||||
|
||||
{$region Debug}
|
||||
|
||||
{$ifdef DebugMode}
|
||||
|
||||
function cl_event.GetRefCount: IntPtr;
|
||||
begin
|
||||
cl.GetEventInfo(self, EventInfoType.REFERENCE_COUNT, new UIntPtr(IntPtr.Size), @Result, nil).RaiseIfError;
|
||||
end;
|
||||
|
||||
function cl_event.GetState: CommandExecutionStatus;
|
||||
begin
|
||||
cl.GetEventInfo(self, EventInfoType.COMMAND_EXECUTION_STATUS, new UIntPtr(4), @Result, nil).RaiseIfError;
|
||||
end;
|
||||
|
||||
{$endif DebugMode}
|
||||
|
||||
{$endregion Debug}
|
||||
|
||||
{$endregion Impl}
|
||||
|
||||
end.
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1549,8 +1549,12 @@ procedure Dec(var c: char);
|
|||
procedure Dec(var c: char; n: integer);
|
||||
/// Возвращает предшествующий x символ
|
||||
function Pred(x: char): char;
|
||||
// Возвращает символ, отстоящий от x на n позиций назад
|
||||
//function Pred(x: char; n: integer): char;
|
||||
/// Возвращает следующий за x символ
|
||||
function Succ(x: char): char;
|
||||
// Возвращает символ, отстоящий от x на n позиций вперёд
|
||||
//function Succ(x: char; n: integer): char;
|
||||
/// Преобразует код в символ в кодировке Windows
|
||||
function ChrAnsi(a: byte): char;
|
||||
/// Преобразует символ в код в кодировке Windows
|
||||
|
|
@ -8601,7 +8605,14 @@ end;
|
|||
|
||||
function Succ(x: char): char;
|
||||
begin
|
||||
Result := System.Convert.ToChar(System.Convert.ToUInt16(x) + 1);
|
||||
//Result := System.Convert.ToChar(System.Convert.ToUInt16(x) + 1);
|
||||
Result := char(integer(x)+1);
|
||||
end;
|
||||
|
||||
function Succ(x: char; n: integer): char;
|
||||
begin
|
||||
//Result := System.Convert.ToChar(System.Convert.ToUInt16(x) + 1);
|
||||
Result := char(integer(x)+n);
|
||||
end;
|
||||
|
||||
function Pred(x: boolean): boolean;
|
||||
|
|
@ -8651,7 +8662,13 @@ end;
|
|||
|
||||
function Pred(x: char): char;
|
||||
begin
|
||||
Result := System.Convert.ToChar(System.Convert.ToUInt16(x) - 1);
|
||||
Result := char(integer(x)-1);
|
||||
//Result := System.Convert.ToChar(System.Convert.ToUInt16(x) - 1);
|
||||
end;
|
||||
|
||||
function Pred(x: char; n: integer): char;
|
||||
begin
|
||||
Result := char(integer(x)-n);
|
||||
end;
|
||||
|
||||
procedure Swap<T>(var a, b: T);
|
||||
|
|
@ -8920,7 +8937,7 @@ begin
|
|||
end;
|
||||
|
||||
/// Преобразует элементы последовательности в строковое представление, после чего объединяет их в строку, используя delim в качестве разделителя
|
||||
function JoinIntoString<T>(Self: sequence of T; delim: string): string; extensionmethod;
|
||||
function JoinToString<T>(Self: sequence of T; delim: string): string; extensionmethod;
|
||||
begin
|
||||
var g := Self.GetEnumerator();
|
||||
var sb := new System.Text.StringBuilder('');
|
||||
|
|
@ -8933,14 +8950,22 @@ begin
|
|||
Result := sb.ToString;
|
||||
end;
|
||||
|
||||
///--
|
||||
function JoinIntoString<T>(Self: sequence of T; delim: string): string; extensionmethod
|
||||
:= Self.JoinToString(delim);
|
||||
|
||||
/// Преобразует элементы последовательности в строковое представление, после чего объединяет их в строку, используя пробел в качестве разделителя
|
||||
function JoinIntoString<T>(Self: sequence of T): string; extensionmethod;
|
||||
function JoinToString<T>(Self: sequence of T): string; extensionmethod;
|
||||
begin
|
||||
if typeof(T) = typeof(char) then
|
||||
Result := Self.JoinIntoString('')
|
||||
else Result := Self.JoinIntoString(' ');
|
||||
end;
|
||||
|
||||
///--
|
||||
function JoinIntoString<T>(Self: sequence of T): string; extensionmethod
|
||||
:= Self.JoinToString();
|
||||
|
||||
/// Применяет действие к каждому элементу последовательности
|
||||
procedure &ForEach<T>(Self: sequence of T; action: T -> ()); extensionmethod;
|
||||
begin
|
||||
|
|
@ -11187,6 +11212,49 @@ begin
|
|||
else Result := Self;
|
||||
end;
|
||||
|
||||
function PrefixFunction(s: string): array of integer;
|
||||
// возвращает массив граней для строки-аргумента
|
||||
begin
|
||||
var n := s.Length;
|
||||
Result := ArrFill(n + 1, 0);
|
||||
for var i := 1 to n - 1 do
|
||||
begin
|
||||
var temp := Result[i];
|
||||
while (temp > 0) and (s[i + 1] <> s[temp + 1]) do
|
||||
temp := Result[temp];
|
||||
Result[i + 1] := s[i + 1] = s[temp + 1] ? temp + 1 : 0
|
||||
end
|
||||
end;
|
||||
|
||||
/// Возвращает массив индексов вхождений подстроки в основную строку
|
||||
///Параметр overlay определяет, разрешены ли перекрытия вхождений подстрок
|
||||
function IndicesOf(Self, SubS: string; overlay: boolean := False): array of integer; extensionmethod;
|
||||
// Реализует КМП-алгоритм.
|
||||
// Возвращает массив начальных позиций вхождений подстроки P в строку
|
||||
// Параметр overlay определяет, разрешены ли перекрытия положений подстрок.
|
||||
begin
|
||||
var L := new List<integer>;
|
||||
var (n, m) := (Self.Length, SubS.Length);
|
||||
var border := PrefixFunction(SubS);
|
||||
var temp := 0;
|
||||
for var i := 1 to n do
|
||||
begin
|
||||
while (temp > 0) and (SubS[temp + 1] <> Self[i]) do
|
||||
temp := border[temp];
|
||||
if SubS[temp + 1] = Self[i] then
|
||||
temp += 1;
|
||||
if temp = m then
|
||||
begin
|
||||
var pos := i - m + 1;
|
||||
if overlay or (L.Count = 0) or (pos >= L[L.Count - 1] + m) then
|
||||
L.Add(pos);
|
||||
temp := border[m]
|
||||
end;
|
||||
end;
|
||||
Result := L.Select(i -> i - 1).ToArray
|
||||
end;
|
||||
|
||||
|
||||
///--
|
||||
function CreateSliceFromStringInternal(Self: string; from, step, count: integer): string;
|
||||
begin
|
||||
|
|
|
|||
|
|
@ -1549,8 +1549,12 @@ procedure Dec(var c: char);
|
|||
procedure Dec(var c: char; n: integer);
|
||||
/// Возвращает предшествующий x символ
|
||||
function Pred(x: char): char;
|
||||
// Возвращает символ, отстоящий от x на n позиций назад
|
||||
//function Pred(x: char; n: integer): char;
|
||||
/// Возвращает следующий за x символ
|
||||
function Succ(x: char): char;
|
||||
// Возвращает символ, отстоящий от x на n позиций вперёд
|
||||
//function Succ(x: char; n: integer): char;
|
||||
/// Преобразует код в символ в кодировке Windows
|
||||
function ChrAnsi(a: byte): char;
|
||||
/// Преобразует символ в код в кодировке Windows
|
||||
|
|
@ -8601,7 +8605,14 @@ end;
|
|||
|
||||
function Succ(x: char): char;
|
||||
begin
|
||||
Result := System.Convert.ToChar(System.Convert.ToUInt16(x) + 1);
|
||||
//Result := System.Convert.ToChar(System.Convert.ToUInt16(x) + 1);
|
||||
Result := char(integer(x)+1);
|
||||
end;
|
||||
|
||||
function Succ(x: char; n: integer): char;
|
||||
begin
|
||||
//Result := System.Convert.ToChar(System.Convert.ToUInt16(x) + 1);
|
||||
Result := char(integer(x)+n);
|
||||
end;
|
||||
|
||||
function Pred(x: boolean): boolean;
|
||||
|
|
@ -8651,7 +8662,13 @@ end;
|
|||
|
||||
function Pred(x: char): char;
|
||||
begin
|
||||
Result := System.Convert.ToChar(System.Convert.ToUInt16(x) - 1);
|
||||
Result := char(integer(x)-1);
|
||||
//Result := System.Convert.ToChar(System.Convert.ToUInt16(x) - 1);
|
||||
end;
|
||||
|
||||
function Pred(x: char; n: integer): char;
|
||||
begin
|
||||
Result := char(integer(x)-n);
|
||||
end;
|
||||
|
||||
procedure Swap<T>(var a, b: T);
|
||||
|
|
@ -8920,7 +8937,7 @@ begin
|
|||
end;
|
||||
|
||||
/// Преобразует элементы последовательности в строковое представление, после чего объединяет их в строку, используя delim в качестве разделителя
|
||||
function JoinIntoString<T>(Self: sequence of T; delim: string): string; extensionmethod;
|
||||
function JoinToString<T>(Self: sequence of T; delim: string): string; extensionmethod;
|
||||
begin
|
||||
var g := Self.GetEnumerator();
|
||||
var sb := new System.Text.StringBuilder('');
|
||||
|
|
@ -8933,14 +8950,22 @@ begin
|
|||
Result := sb.ToString;
|
||||
end;
|
||||
|
||||
///--
|
||||
function JoinIntoString<T>(Self: sequence of T; delim: string): string; extensionmethod
|
||||
:= Self.JoinToString(delim);
|
||||
|
||||
/// Преобразует элементы последовательности в строковое представление, после чего объединяет их в строку, используя пробел в качестве разделителя
|
||||
function JoinIntoString<T>(Self: sequence of T): string; extensionmethod;
|
||||
function JoinToString<T>(Self: sequence of T): string; extensionmethod;
|
||||
begin
|
||||
if typeof(T) = typeof(char) then
|
||||
Result := Self.JoinIntoString('')
|
||||
else Result := Self.JoinIntoString(' ');
|
||||
end;
|
||||
|
||||
///--
|
||||
function JoinIntoString<T>(Self: sequence of T): string; extensionmethod
|
||||
:= Self.JoinToString();
|
||||
|
||||
/// Применяет действие к каждому элементу последовательности
|
||||
procedure &ForEach<T>(Self: sequence of T; action: T -> ()); extensionmethod;
|
||||
begin
|
||||
|
|
@ -11187,6 +11212,49 @@ begin
|
|||
else Result := Self;
|
||||
end;
|
||||
|
||||
function PrefixFunction(s: string): array of integer;
|
||||
// возвращает массив граней для строки-аргумента
|
||||
begin
|
||||
var n := s.Length;
|
||||
Result := ArrFill(n + 1, 0);
|
||||
for var i := 1 to n - 1 do
|
||||
begin
|
||||
var temp := Result[i];
|
||||
while (temp > 0) and (s[i + 1] <> s[temp + 1]) do
|
||||
temp := Result[temp];
|
||||
Result[i + 1] := s[i + 1] = s[temp + 1] ? temp + 1 : 0
|
||||
end
|
||||
end;
|
||||
|
||||
/// Возвращает массив индексов вхождений подстроки в основную строку
|
||||
///Параметр overlay определяет, разрешены ли перекрытия вхождений подстрок
|
||||
function IndicesOf(Self, SubS: string; overlay: boolean := False): array of integer; extensionmethod;
|
||||
// Реализует КМП-алгоритм.
|
||||
// Возвращает массив начальных позиций вхождений подстроки P в строку
|
||||
// Параметр overlay определяет, разрешены ли перекрытия положений подстрок.
|
||||
begin
|
||||
var L := new List<integer>;
|
||||
var (n, m) := (Self.Length, SubS.Length);
|
||||
var border := PrefixFunction(SubS);
|
||||
var temp := 0;
|
||||
for var i := 1 to n do
|
||||
begin
|
||||
while (temp > 0) and (SubS[temp + 1] <> Self[i]) do
|
||||
temp := border[temp];
|
||||
if SubS[temp + 1] = Self[i] then
|
||||
temp += 1;
|
||||
if temp = m then
|
||||
begin
|
||||
var pos := i - m + 1;
|
||||
if overlay or (L.Count = 0) or (pos >= L[L.Count - 1] + m) then
|
||||
L.Add(pos);
|
||||
temp := border[m]
|
||||
end;
|
||||
end;
|
||||
Result := L.Select(i -> i - 1).ToArray
|
||||
end;
|
||||
|
||||
|
||||
///--
|
||||
function CreateSliceFromStringInternal(Self: string; from, step, count: integer): string;
|
||||
begin
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in a new issue