CN103778180A - 一种基于Hash的字符串存储方法 - Google Patents

一种基于Hash的字符串存储方法 Download PDF

Info

Publication number
CN103778180A
CN103778180A CN201310569923.4A CN201310569923A CN103778180A CN 103778180 A CN103778180 A CN 103778180A CN 201310569923 A CN201310569923 A CN 201310569923A CN 103778180 A CN103778180 A CN 103778180A
Authority
CN
China
Prior art keywords
character string
hash
character
int
resource
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Withdrawn
Application number
CN201310569923.4A
Other languages
English (en)
Inventor
陈洋
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Dalian Chuangda Technology Trade Market Co Ltd
Original Assignee
Dalian Chuangda Technology Trade Market Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Dalian Chuangda Technology Trade Market Co Ltd filed Critical Dalian Chuangda Technology Trade Market Co Ltd
Priority to CN201310569923.4A priority Critical patent/CN103778180A/zh
Publication of CN103778180A publication Critical patent/CN103778180A/zh
Withdrawn legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/901Indexing; Data structures therefor; Storage structures
    • G06F16/9014Indexing; Data structures therefor; Storage structures hash tables

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明涉及一种基于Hash的字符串存储方法,用于解决存储客户端中大量的字符数据而造成的内存浪费问题,其并采用hash数据结构的字符串管理技术,重复性很高的字符串,在内存中只占用一个全集的nameHash,而使用地方只需要存储index即可,这样,字符串的占用资源的大小跟他的复杂度和使用次数基本无关,大大提高减少了内存占用率,同时,采用index的对比,可以快速的定位同名字符串,避开了繁琐的字符串比对操作,提高了程序的执行效率。

Description

一种基于Hash的字符串存储方法
 
技术领域
    本发明涉及一种字符存储技术,用于解决存储客户端中大量的字符数据而造成的内存浪费问题。
背景技术
随着网络游戏的不断发展,用户对游戏画质的要求也不断提升。在技术人员不断提升客户端渲染效率和效果的同时,客户端的资源量也逐渐增多。
对于激增的大量资源,除了造成客户端容量变大之外,五花八门顶点命名也给美工人员和策划人员带来了困扰。如果命名太过随意和简短,很容易产生重名,也不利于策划和美工人员根据名字快速定位资源。这觉导致了在现在的客户端资源中,每个资源的名字字符串都很长。再加上客户端资源量的增大,资源名字符串在资源包的存储中已经占用了很大一部分。在资源序列化到内存之后,也是一笔不小的内存开销。
本发明针对此问题,提出了一种基于垃圾回收,并采用hash数据结构的字符串管理技术,最大程度的减少资源量,加快字符串比对。
发明内容
鉴于现有技术存在的问题,本发明的目的是要提供一种基于Hash的字符串存储方法,其并采用hash数据结构的字符串管理技术,最大程度的减少资源量,加快字符串比对。
为了实现上述目的,本发明所采用的技术方案为一种基于Hash的字符串存储技术,其步骤如下:
    步骤1:建立字符串HASH表。选取合适的HASH函数;
建立一个hash函数为int appstrhash(char*);把一个字符串转换为了一个Int值,HASH表的主键为Int的键值,而对应的容器中为各个字符串的字符值;
    步骤2)加载资源时,对资源名进行HASH;
对资源名进行拆分HASH,如果一个物件的名字为Map1_AM_StaticMesh,那么这个物件就可以表示成三个键值的Int集合;如结构体:
Struct ResIndex
{
   Int KeyIndex;
   Int HashIndex;
}
Struct ResName
{
  ResIndex ResName;
ResIndex MakerName;
ResIndex KindName;
};
具体的字符串,只需要查找对应的hash表即可获得;
    步骤3:字符按照使用周期的垃圾回收;
    当资源的生存周期结束后,对字符hash表进行适时的回收;所述回收分为两个方式:动态回收和固定回收;动态回收:把对应hash表中的字符串删除,对应的容器index不发生改变;固定回收:整个字符串hash结构重构,删除不用的字符,同时重新生成Index值。
    本发明的优点在于:重复性很高的字符串,在内存中只占用一个全集的nameHash,而使用地方只需要存储index即可,这样,字符串的占用资源的大小跟他的复杂度和使用次数基本无关,大大提高减少了内存占用率,同时,采用index的对比,可以快速的定位同名字符串,避开了繁琐的字符串比对操作,提高了程序的执行效率。
具体实施方式
一种基于Hash的字符串存储方法,其步骤如下:
    步骤1:建立字符串HASH表。选取合适的HASH函数;
建立一个hash函数为int appstrhash(char*);把一个字符串转换为了一个Int值,HASH表的主键为Int的键值,而对应的容器中为各个字符串的字符值;
    步骤2)加载资源时,对资源名进行HASH;
对资源名进行拆分HASH,如果一个物件的名字为Map1_AM_StaticMesh,那么这个物件就可以表示成三个键值的Int集合;如结构体:
Struct ResIndex
{
   Int KeyIndex;
   Int HashIndex;
}
Struct ResName
{
  ResIndex ResName;
ResIndex MakerName;
ResIndex KindName;
};
具体的字符串,只需要查找对应的hash表即可获得;
    步骤3:字符按照使用周期的垃圾回收;
    当资源的生存周期结束后,对字符hash表进行适时的回收;所述回收分为两个方式:动态回收和固定回收;动态回收:把对应hash表中的字符串删除,对应的容器index不发生改变;固定回收:整个字符串hash结构重构,删除不用的字符,同时重新生成Index值。

Claims (1)

1.一种基于Hash的字符串存储方法,其步骤如下:
    步骤1:建立字符串HASH表;
 选取合适的HASH函数;
建立一个hash函数为int appstrhash(char*);把一个字符串转换为了一个Int值,HASH表的主键为Int的键值,而对应的容器中为各个字符串的字符值;
    步骤2)加载资源时,对资源名进行HASH;
对资源名进行拆分HASH,如果一个物件的名字为Map1_AM_StaticMesh,那么这个物件就可以表示成三个键值的Int集合;如结构体:
Struct ResIndex
{
   Int KeyIndex;
   Int HashIndex;
}
Struct ResName
{
  ResIndex ResName;
ResIndex MakerName;
ResIndex KindName;
};
具体的字符串,只需要查找对应的hash表即可获得;
    步骤3:字符按照使用周期的垃圾回收;
    当资源的生存周期结束后,对字符hash表进行适时的回收;所述回收分为两个方式:动态回收和固定回收;动态回收:把对应hash表中的字符串删除,对应的容器index不发生改变;固定回收:整个字符串hash结构重构,删除不用的字符,同时重新生成Index值。
CN201310569923.4A 2013-11-16 2013-11-16 一种基于Hash的字符串存储方法 Withdrawn CN103778180A (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201310569923.4A CN103778180A (zh) 2013-11-16 2013-11-16 一种基于Hash的字符串存储方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201310569923.4A CN103778180A (zh) 2013-11-16 2013-11-16 一种基于Hash的字符串存储方法

Publications (1)

Publication Number Publication Date
CN103778180A true CN103778180A (zh) 2014-05-07

Family

ID=50570415

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201310569923.4A Withdrawn CN103778180A (zh) 2013-11-16 2013-11-16 一种基于Hash的字符串存储方法

Country Status (1)

Country Link
CN (1) CN103778180A (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104462322A (zh) * 2014-12-01 2015-03-25 北京国双科技有限公司 字符串比对方法和装置

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1357836A (zh) * 2000-12-07 2002-07-10 华为技术有限公司 提高短消息调度中心消息处理能力的方法
CN1464436A (zh) * 2002-06-26 2003-12-31 联想(北京)有限公司 嵌入式系统的数据存放及其查找组合方法
CN1658702A (zh) * 2005-03-25 2005-08-24 北京北方烽火科技有限公司 一种gmlc中用户标识的快速转换算法
CN1866203A (zh) * 2005-05-20 2006-11-22 腾讯科技(深圳)有限公司 一种字符串引用方法
CN101102286A (zh) * 2006-07-05 2008-01-09 阿里巴巴公司 一种在即时通信系统中引用用户信息的方法及装置

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1357836A (zh) * 2000-12-07 2002-07-10 华为技术有限公司 提高短消息调度中心消息处理能力的方法
CN1464436A (zh) * 2002-06-26 2003-12-31 联想(北京)有限公司 嵌入式系统的数据存放及其查找组合方法
CN1658702A (zh) * 2005-03-25 2005-08-24 北京北方烽火科技有限公司 一种gmlc中用户标识的快速转换算法
CN1866203A (zh) * 2005-05-20 2006-11-22 腾讯科技(深圳)有限公司 一种字符串引用方法
CN101102286A (zh) * 2006-07-05 2008-01-09 阿里巴巴公司 一种在即时通信系统中引用用户信息的方法及装置

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104462322A (zh) * 2014-12-01 2015-03-25 北京国双科技有限公司 字符串比对方法和装置
CN104462322B (zh) * 2014-12-01 2018-02-02 北京国双科技有限公司 字符串比对方法和装置

Similar Documents

Publication Publication Date Title
Feller et al. Performance and energy efficiency of big data applications in cloud environments: A Hadoop case study
JP5576455B2 (ja) Bimデータファイルに含まれたデータを提供する方法、それを記録した記録媒体、およびそれを含むシステム
CN103379159B (zh) 一种分布式Web站点数据同步的方法
RU2014109361A (ru) Отслеживание " грязных" областей энергонезависимых носителей
MY155867A (en) Scheduling collections in a scheduler
JP2014524090A5 (zh)
JP2010186391A (ja) データベース処理システム、計算機及びデータベース処理方法
Cheah et al. Milieu: Lightweight and configurable big data provenance for science
CN102243592A (zh) 在Loader系统中实现多种升级的方法和机顶盒
WO2019141289A3 (en) Methods and devices for data traversal
CN102023891A (zh) 基于Java虚拟机的并发垃圾收集器框架
CN103778251A (zh) 面向大规模rdf图数据的sparql并行查询方法
CN103390007A (zh) 数据获取方法和装置
CN103455964B (zh) 一种基于案件信息的案件线索分析系统及方法
CN104778252A (zh) 索引的存储方法和装置
CN103473271B (zh) 一种针对大量数据的优化储存方法
CN103778180A (zh) 一种基于Hash的字符串存储方法
CN104376086B (zh) 数据处理方法和装置
CN106227857B (zh) 数据推送和加载方法和装置
CN107239568A (zh) 分布式索引实现方法及装置
CN105740997A (zh) 一种控制任务流程的方法、装置及数据库管理系统
CN103714142A (zh) 一种数据查找方法及装置
CN103763615A (zh) 一种剧集选择的交互方法及设备
CN105991312B (zh) 一种网络资源的排重方法及装置
WO2016135874A1 (ja) 計算機及びデータベースの管理方法

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
WW01 Invention patent application withdrawn after publication

Application publication date: 20140507

WW01 Invention patent application withdrawn after publication