改良版TStringList类
2008-04-09 04:21:32来源:互联网 阅读 ()
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.mozilla.org/NPL/NPL-1_1Final.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: mwStringHashList.pas, released December 18, 2000.
The Initial Developer of the Original Code is Martin Waldenburg
(Martin.Waldenburg@T-Online.de).
Portions created by Martin Waldenburg are Copyright (C) 2000 Martin Waldenburg.
All Rights Reserved.
Contributor(s): ___________________.
Last Modified: 18/12/2000
Current Version: 1.1
Notes: This is a very fast Hash list for strings.
The TinyHash functions should be in most cases suffizient
Known Issues:
-----------------------------------------------------------------------------}
unit mwStringHashList;
interface
uses Classes, SysUtils;
var
mwHashTable: array[#0..#255] of Byte;
mwInsensitiveHashTable: array[#0..#255] of Byte;
type
TmwStringHash = function (const aString: String): Integer;
TmwStringHashCompare = function (const Str1: String; const Str2: String): Boolean;
TmwHashWord = class
S: String;
constructor Create(aString: String);
end;
PHashPointerList = ^THashPointerList;
THashPointerList = array[1..1] of Pointer;
TmwBaseStringHashList = class(TObject)
FList: PHashPointerList;
fCapacity: Integer;
protected
function Get(Index: Integer): Pointer;
procedure Put(Index: Integer; Item: Pointer);
procedure SetCapacity(NewCapacity: Integer);
public
destructor Destroy; override;
property Capacity: Integer read fCapacity;
property Items[Index: Integer]: Pointer read Get write Put; default;
end;
TmwHashStrings = class(TList)
public
destructor Destroy; override;
procedure AddString(S: String);
end;
TmwHashItems = class(TmwBaseStringHashList)
public
procedure AddString(S: String);
end;
TmwStringHashList = class(TmwBaseStringHashList)
private
fHash: TmwStringHash;
fCompare: TmwStringHashCompare;
public
constructor Create(aHash: TmwStringHash; aCompare: TmwStringHashCompare);
procedure AddString(S: String);
function Hash(S: String): Boolean;
function HashEX(S: String; HashValue: Integer): Boolean;
end;
function SimpleHash(const aString: String): Integer;
function ISimpleHash(const aString: String): Integer;
function TinyHash(const aString: String): Integer;
function ITinyHash(const aString: String): Integer;
function HashCompare(const Str1: String; const Str2: String): Boolean;
function IHashCompare(const Str1: String; const Str2: String): Boolean;
implementation
procedure InitTables;
var
I: Char;
begin
for I:= #0 to #255 do
begin
mwHashTable[I]:= Ord(I);
mwInsensitiveHashTable[I]:= Ord(UpperCase(String(I))[1]);
end;
end;
function SimpleHash(const aString: String): Integer;
var
I: Integer;
begin
Result:= Length(aString);
for I:= 1 to Length(aString) do
inc(Result, mwHashTable[aString[I]]);
end;
function ISimpleHash(const aString: String): Integer;
var
I: Integer;
begin
Result:= Length(aString);
for I:= 1 to Length(aString) do
inc(Result, mwInsensitiveHashTable[aString[I]]);
end;
function TinyHash(const aString: String): Integer;
var
I: Integer;
begin
Result:= Length(aString);
for I:= 1 to Length(aString) do
begin
inc(Result, mwHashTable[aString[I]]);
if I = 2 then Break;
end;
end;
function ITinyHash(const aString: String): Integer;
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
var
I: Integer;
begin
Result:= Length(aString);
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:角点检测算子的代码描述
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash