平时写程序时经常要把一些Key与Value保存起来,但一般数据量都不大,故不想用TStringHash来做。而用TStringList来做,还要写一个"=",挺别扭!而且数据类型还有限制。自己从VCL中找了一段,感觉挺好用的,以后用它玩一玩!不过对Key值的搜索采用遍历方式,数据量大就慢了,建议采用HashTable。

注:Key与Value均不受数据类型限制!

TLookupList = class(TObject)
private
FList: TList;
public
constructor Create;
destructor Destroy; override;
procedure Add(const AKey, AValue: Variant);
procedure Clear;
function ValueOfKey(const AKey: Variant): Variant;
end;
{ TLookupList }
constructor TLookupList.Create;
begin
FList := TList.Create;
end;
destructor TLookupList.Destroy;
begin
if FList <> nil then Clear;
FList.Free;
end;
procedure TLookupList.Add(const AKey, AValue: Variant);
var
ListEntry: PLookupListEntry;
begin
New(ListEntry);
ListEntry.Key := AKey;
ListEntry.Value := AValue;
FList.Add(ListEntry);
end;
procedure TLookupList.Clear;
var
I: Integer;
begin
for I := to FList.Count - do
Dispose(PLookupListEntry(FList.Items[I]));
FList.Clear;
end;
function TLookupList.ValueOfKey(const AKey: Variant): Variant;
var
I: Integer;
begin
Result := Null;
if not VarIsNull(AKey) then
for I := to FList.Count - do
if PLookupListEntry(FList.Items[I]).Key = AKey then
begin
Result := PLookupListEntry(FList.Items[I]).Value;
Break;
end;
end;

测试

var
Demo:TLookupList;
begin
Demo:=TLookupList.Create;
try
Demo.Add('aa','bbb');
ShowMessage(Demo.ValueOfKey('aa'));
finally
Demo.Free;
end;
end;

小数据量的Key-Value查找类的实现的更多相关文章

  1. Win环境下Oracle小数据量数据库的物理备份

    Win环境下Oracle小数据量数据库的物理备份 环境:Windows + Oracle 单实例 数据量:小于20G 重点:需要规划好备份的路径,建议备份文件和数据库文件分别存在不同的存储上. 1.开 ...

  2. windows 系统下,小数据量Oracle用户物理备份

    环境:windows Server 2003 oracle 10g,系统间备份 目标系统创建共享文件,原系统挂载共享目录 写批处理脚本,用任务计划定时调用 Rem * 由于系统实时性要求不是很高,数据 ...

  3. hihocoder #1062 : 最近公共祖先·一(小数据量 map+set模拟+标记检查 *【模板】思路 )

    #1062 : 最近公共祖先·一 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho最近发现了一个神奇的网站!虽然还不够像58同城那样神奇,但这个网站仍然让小Ho乐在 ...

  4. Java实现本地小数据量缓存尝试与实践&设计思考

    话不多说先贴代码 /** * 缓存工具 */ public class ConcurrentHashMapCacheUtils{ /** * 当前缓存个数 */ public static Integ ...

  5. poj 1679 The Unique MST 【次小生成树+100的小数据量】

    题目地址:http://poj.org/problem?id=1679 2 3 3 1 2 1 2 3 2 3 1 3 4 4 1 2 2 2 3 2 3 4 2 4 1 2 Sample Outpu ...

  6. poj The Settlers of Catan( 求图中的最长路 小数据量 暴力dfs搜索(递归回溯))

    The Settlers of Catan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1123   Accepted: ...

  7. 小数据量csv文件数据导入数据库(思路)

    大致写写思路,因为sqlserver提供了可以直接导入的图形界面. 1.private static string GetConnectionString(string folderPath)  // ...

  8. WebService - 怎样提高WebService性能 大数据量网络传输处理

    直接返回DataSet对象 返回DataSet对象用Binary序列化后的字节数组 返回DataSetSurrogate对象用Binary序列化后的字节数组 返回DataSetSurrogate对象用 ...

  9. MySQL大数据量快速分页实现(转载)

    在mysql中如果是小数据量分页我们直接使用limit x,y即可,但是如果千万数据使用这样你无法正常使用分页功能了,那么大数据量要如何构造sql查询分页呢?     般刚开始学SQL语句的时候,会这 ...

随机推荐

  1. 【MySQL】5.6.x InnoDB Error Table mysql.innodb_table_stats not found

    [问题描述]: 检查error log的时候发现大量warnings: [Warning] InnoDB Error Table mysql.innodb_index_stats not found ...

  2. 普通new和placement new的重载

    对于自定义对象,我们可以重载普通new操作符,这时候使用new Test()时就会调用到我们重载的普通new操作符. 示例程序: #include <iostream> #include ...

  3. JAXB性能优化

    前言: 之前在查阅jaxb相关资料的同时, 也看到了一些关于性能优化的点. 主要集中于对象和xml互转的过程中, 确实有些实实在在需要注意的点. 这边浅谈jaxb性能优化的一个思路. 案列: 先来构造 ...

  4. [opencvjichu]cv::Mat::type() 返回值

    opencv opencv中Mat存在各种类型,其中mat有一个type()的函数可以返回该Mat的类型.类型表示了矩阵中元素的类型以及矩阵的通道个数,它是一系列的预定义的常量,其命名规则为CV_(位 ...

  5. C#语法-虚方法详解 Virtual 虚函数

    虚方法 / Virtual 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享. ...

  6. Gym - 101002H: Jewel Thief (背包,分组,DP决策单调性)

    pro:给定N,M.输入N个物品,(si,vi)表示第i个物品体积为si,价值为vi,s<=300,vi<=1e9: N<1e6:现在要求,对于背包体积为1到M时,求出最大背包价值. ...

  7. CodeForces - 441E:Valera and Number (DP&数学期望&二进制)

    Valera is a coder. Recently he wrote a funny program. The pseudo code for this program is given belo ...

  8. CCF-棋局评估 201803-04(版本 2.0)------(之前写了一个臃肿的1.0版 ,还沾沾自喜 233)

    核心 : 博弈搜索树     双方得分互为相反数 dfs (x,y,player): 玩家player下完(x,y)之后的得分最大值 易错: 先判断输赢,再判断平局 待改进: check() 函数写的 ...

  9. 【状压DP】【HDOJ1074】

    http://acm.hdu.edu.cn/showproblem.php?pid=1074 Doing Homework Time Limit: 2000/1000 MS (Java/Others) ...

  10. Eclipse实现数据库反向生成实体类(pojo)-------(插件安装和实现步骤的说明)

    一.插件安装 1.下载插件: http://jaist.dl.sourceforge.net/sourceforge/jboss/HibernateTools-3.2.4.Beta1-R2008103 ...