-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathutils.pp
43 lines (33 loc) · 856 Bytes
/
utils.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
unit Utils;
{$mode objfpc}{$H+}
interface
uses
{$if fpc_fullversion >= 20701}
ghashmap
{$else fpc_fullversion >= 20701}
fgl
{$endif fpc_fullversion >= 20701}
,Classes, SysUtils;
type
{$if fpc_fullversion >= 20701}
{ TStringHash }
TStringHash = class
class function hash(s: String; n: Integer): Integer;
end;
generic TStringHashMap<T> = class(specialize THashMap<String,T,TStringHash>) end;
{$else fpc_fullversion >= 20701}
generic TStringHashMap<T> = class(specialize TFPGMap<String,T>) end;
{$endif fpc_fullversion >= 20701}
implementation
{$if fpc_fullversion >= 20701}
class function TStringHash.hash(s: String; n: Integer): Integer;
var
c: Char;
begin
Result := 0;
for c in s do
Inc(Result,Ord(c));
Result := Result mod n;
end;
{$endif fpc_fullversion >= 20701}
end.