易截截图软件、单文件、免安装、纯绿色、仅160KB

Delphi中的THashTable

在Delphi中,Inifiles单元中有一个TStringHash的类,不过它的Value仅支持Integer(其实也不是问题,有其它类型可以将变量变为Pointer),有点不舒服,今天没事做就把它替换为variant了,其中Key的名称大小写无关,就是为了加快开发速度!
使用Hashtable,查找和删除复杂度都是常数级别的!
type
PPHashItem = ^PHashItem;
PHashItem = ^THashItem;
THashItem = record
Next: PHashItem;
Key: String;
Value: Variant;
end;
THashTable = class
private
Buckets: array of PHashItem;
protected
function Find(const Key: String): PPHashItem;
function HashOf(const Key: String): Cardinal; virtual;
public
constructor Create(Size: Cardinal = 256);
destructor Destroy; override;
procedure Put(const Key: String; Value: Variant);
procedure Clear;
procedure Remove(const Key: String);
function Modify(const Key: String; Value: Variant): Boolean;
function Get(const Key: String): Variant;
function ContainKey(const Key: String):boolean;
end;
procedure THashTable.Clear;
var
I: Integer;
P, N: PHashItem;
begin
for I := 0 to Length(Buckets) - 1 do
begin
P := Buckets[I];
while P <> nil do
begin
N := P^.Next;
Dispose(P);
P := N;
end;
Buckets[I] := nil;
end;
end;
function THashTable.ContainKey(const Key: String): boolean;
var
P: PHashItem;
begin
P := Find(Key)^;
if P <> nil then
begin
Result := True;
end
else
Result := False;
end;
constructor THashTable.Create(Size: Cardinal);
begin
inherited Create;
SetLength(Buckets, Size);
end;
destructor THashTable.Destroy;
begin
Clear;
inherited Destroy;
end;
function THashTable.Find(const Key: String): PPHashItem;
var
Hash: Integer;
begin
Hash := HashOf(Key) mod Cardinal(Length(Buckets));
Result := @Buckets[Hash];
while Result^ <> nil do
begin
if Result^.Key = Key then
Exit
else
Result := @Result^.Next;
end;
end;
functio


相关文档:

Delphi 相关记录

1、TStringList支持的最大行数是多少?(http://topic.csdn.net/t/20060209/14/4547405.html)
楼主结论:“TStringList的LoadfromFile函数应该只能读取15万行以内的数据,但TStringList和TList的Add函数可以加到几百万行(甚至更多)也不会出错。程序出错的原因应该是Add非法内存指针导致的,正如tanlim(求学者) &nb ......

在Delphi中解密Magento加密的信用卡号

问题背景:
       公司希望使用Magento来进行接单,而后把订单导入到一个ERP系统中(订单处理引擎)。
问题:
       在使用WebService从Magento中获取Payment信息时,信用卡是被加密的(法律规定不允许在数据库中存储信用卡的明文信息)!
      ......

delphi技巧记录


#13回车换行
将form2内容加入到form1列表框:在form2里:form1.listbox1.items.add(edit1.text)
listbox1.items.loadfromfile('chinese.txt')将chinese.txt文件内容载入列表框中。但前提是要整个窗体创建时候加载导入,双击整个窗体procedure TForm1.FormCreate(Sender: TObject)
listbox1.items.savetofile('chinese. ......

air,java,Delphi递归获得文件夹及其子文件信息

把以前做过的项目总结一下!参加工作以来一共用三种不同语言实现了获得文件夹及其子文件信息。为了方便以后使用总结一下
air实现: 
private function getfile(filelist:File):Array{  
  var list:Array = filelist.getDirectoryListing();
  var count:uint=list.length;
  ......

delphi与sqlite




from : http://zhyhero.googlepages.com/heartset
file:0 前言
       本文的目的在于采用流水账方式来记录学习delphi访问嵌入式数据库sqlite中的一些点滴。欢迎各位同好共同学习和批评指正。
file:1 准备工作part1
 & ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号