找回密码
 点一下
查看: 3340|回复: 18

数组储存系统

[复制链接]
发表于 2008-12-28 23:08:47 | 显示全部楼层 |阅读模式
序:
我似乎好久都没有发过有价值的帖子了....
最多也是少量的发2个水贴...
其实 原因是因为 最近发生了很多不愉快的事情...
所以 心情很差...

今天这个系统...
其实 很早以前似乎也就看到过别人 写过...
如果你们看到过..
就可以无视了...
这个系统也是1个多月前 我写的...
一直没有机会发上来...


系统目的:
替代游戏缓存,实现数据传递,提高效率,避免BUG...

代码:
[jass]globals
timer array udg_timer
integer array udg_timer_H2I
integer udg_MAX = 0
//===========数据储存空间=========
//===整数===
integer array udg_Int1
integer array udg_Int2
integer array udg_Int3
integer array udg_Int4
integer array udg_Int5
integer array udg_Int6
integer array udg_Int7
integer array udg_Int8
integer array udg_Int9
integer array udg_Int10
endglobals

function H2I takes handle h returns integer
return h
return 0
endfunction

//=================数组储存系统======================
function DeTimerofID takes integer ID returns nothing
call DestroyTimer(udg_timer[ID])
set udg_timer[ID] = null      
call DisplayTimedTextToPlayer( Player(0), 0, 0, 30, "a" )
  if (ID == udg_MAX - 1) then
   set udg_MAX = udg_MAX - 1
  endif
endfunction

function GetTimerID takes timer t returns integer
local integer i = 0
local integer id = H2I(t)
loop
exitwhen (i > udg_MAX - 1)  
   if (id == udg_timer_H2I) then
    return i
   endif
set i = i + 1
endloop
return 0
endfunction

function GetTimer takes nothing returns timer
local integer i = 0
loop              
exitwhen (i > udg_MAX)  
   if (udg_timer == null) then
     if (i == udg_MAX) then
      set udg_MAX = udg_MAX + 1
     endif
    set udg_timer = CreateTimer()
    set udg_timer_H2I = H2I(udg_timer)
    return udg_timer
   endif
set i = i + 1
endloop
return null
endfunction

function GetTimerofID takes nothing returns integer
local integer i = 0
loop              
exitwhen (i > udg_MAX)  
   if (udg_timer == null) then
     if (i == udg_MAX) then
      set udg_MAX = udg_MAX + 1
     endif
    set udg_timer = CreateTimer()
    set udg_timer_H2I = H2I(udg_timer)
    return i
   endif
set i = i + 1
endloop
return 0
endfunction[/jass]

这里是第二个函数(改进版)
[jass]
globals
integer FIRST_TIMER_H2I
timer array TIMER
integer array TIMER_STATE
endglobals

function GetTimerofID takes nothing returns integer
local integer i = 0
loop
if (TIMER_STATE == 0) then
   set TIMER_STATE = 1
   return i  
endif
set i = i + 1
endloop
return 0
endfunction

function GetTimerID takes timer t returns integer
return H2I(t) - FIRST_TIMER_H2I
endfunction

function RecTimerofID takes integer id returns nothing
call PauseTimer(TIMER[id])
set TIMER_STATE[id] = 0
endfunction

function ITS takes nothing returns nothing
local integer i = 1
set TIMER[0] = CreateTimer()
set TIMER_STATE[0] = 0
set FIRST_TIMER_H2I = H2I(TIMER[0])
loop
exitwhen (i > 8000)
set TIMER = CreateTimer()
set TIMER_STATE = 0
set i = i + 1
endloop
endfunction
[/jass]

原理简述:
本系统其实就短短几个函数....
原理应该也不难理解...
以上代码 其实 只是介绍方法...
可以扩展成任何绑定数据的传递...
这里是以Timer绑定 来传递数据的代码

首先介绍函数的作用
GetTimer 函数:获取一个系统分配的timer
GetTimerofID函数:获取一个系统分配的timer的ID(效果其实和GetTimer()和GetTimer()连用相同,不过直接用这个效率更高)
GetTimerID:获取一个系统分配的timer的ID,不过这个函数是在已经有timer的情况下,获取ID的;而GetTimerofID,是直接分配timer并直接返回ID
DeTimerofID:利用ID来回收已经分配的timer
其实还可以有一个DeTimer
就是直接用timer来回收timer
不过其实实际情况下,反正肯定要知道ID,会有多此一举的情况...所以直接用ID好拉

注意这里的ID,并非timer的H2I值哦...看下去就知道了

系统原理是
先建立一个 timer 数组 作为可以分配的数组
只要 在同一时间里, 你使用的timer 不超过魔兽中的 数组上限,好像是8000多...反正基本上不会超过的拉
GetTimer函数的原理就是
循环判断timer数组 里哪一个 元素是空的...
如果是空的,就建立一个新的计时器,并返回这个元素,就是返回了那个timer
而GetTimerofID
其实就是直接返回 元素的索引

而GetTimerID
就是在知道timer的情况下,逆向的获取元素的索引
这个索引就是ID
原理就是
不断判断 2个timer之间(2个是指:参数中的timer和timer数组中的各个元素)的H2I值
如果相同...
就返回这个元素的索引

DeTimerofID
就是通过ID来清空这个元素,使得系统可以再次分配,并清楚那个数组..来排泄
至于
udg_timer_H2I
udg_MAX
这2个变量,是为了提高搜索效率的...具体请分析函数
其实udg_MAX就是记录可能有你需要的元素的索引上限
udg_timer_H2I就是直接记录已经分配timer的H2I值,不必每次搜索都调用H2I函数

还有就是 这个系统的 数据储存空间 全部要自己写...
比如上面代码里的
udg_Int1
udg_lnt2
...
都是数组
如果你想要 储存实数
你就写一个 实数数组就可以了....
好了函数的原理介绍完了...
之后就说函数的应用

之前在系统目的出已经说了 这个系统是为了替代游戏缓存来达到传递数据的作用
这里就说下方法

比如请看下面这个代码
[jass]
function b takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer ID = GetTimerID(t)//这样你就得到了那个timer的ID
local integer I = set udg_Int1(ID)//这个时候你又通过ID获取了这个数据了,好了目标实现
call DeTimerofID(ID)//这样你就回收了这个timer了哦.很方便吧
call DestroyTimer(t)
set t = null
endfucntion

function a takes nothing returns nothing
local integer ID = GetTimerofID()//这里就获取了一个timer,并以ID方式直接返回,你得到的就是那个timer的数组索引
local integer I = 2 //这个是要传递的数据
set udg_Int1(ID) = I //利用ID来储存这个数据
call TimerStart(udg_timer(ID),0.1,false,function b)//大家看到了 udg_timer(ID) 就是你可以用的timer
endfunction
[/jass]


好了这样就完成了数据的传递了...
就可以摒弃缓存了...
这样你以后做的技能的效率会大大提高哦....

这里只是给除了 timer 绑定 的数据传输...
其实可以写成其他的...比如绑定给unit
随便你啦....

不知道大家是否明白了....
但是其实如果不明白.....
我可能也很难讲明白了......

thinks....

评分

参与人数 1威望 +32 收起 理由
kook + 32 seems similar somewher ..

查看全部评分

发表于 2008-12-29 18:34:41 | 显示全部楼层
利用时间吗?
没看明白诶
回复

使用道具 举报

发表于 2008-12-30 06:41:12 | 显示全部楼层
我说通俗点`~~
首先SL系统不是什么自动生成存档
他是和忽悠性的加密系统~
其实你打代码的时候其实就是事先设计好的公式
从公式中反读取 记录内容
   什么意思捏
比如记录代码是ABC
那么其实
内部先设计好的就是
A是一个内容比如 大法
B是一个内容比如 回程卷轴
C是英雄级别数 比如9
然后你输入后就截取然后反过来公式一读~
想对应的变量设计 就OK
但是实际中公式绝对不会这么简单
这系统最好别用演示的
因为不复杂很容易就被破解还是自己设计套公式比较好`
回复

使用道具 举报

发表于 2008-12-30 06:43:01 | 显示全部楼层
再说明白点 就是
     其实你输入的直接就是 大法 回程 和9
无非把这加密~让人看不出来`~~
回复

使用道具 举报

发表于 2008-12-30 12:31:39 | 显示全部楼层
LS发错帖子了?
回复

使用道具 举报

发表于 2008-12-30 13:13:10 | 显示全部楼层
不错的系统,的确能代替缓存实现数据的存储和传递,像TIMER这种频繁使用的场合,使用缓存的确效率很低~~~
但是个人感觉这种根据timer的handle值进行顺序查找来确定序号的算法效率不高
Vexorian也有个类似的系统   TimerUtil    计时器的序号是这样确定的
在地图初始化时先建立N个计时器,取第一个创建的计时器的handle为offset,这样以后每个计时器的序号就可以这样取得:
H2I(t) - offset
回收计时器时不用删除,直接暂停就可以了
回复

使用道具 举报

 楼主| 发表于 2008-12-30 13:18:00 | 显示全部楼层
的确呢...
没有想到..连续创建的 timer
H2I值也是连续的..
回复

使用道具 举报

发表于 2008-12-30 13:19:49 | 显示全部楼层
Vexorian 的 TimerUtil,和LZ的计时器储存系统类似,仅作参考
效率很高,前提是要初始化一定数量的计时器(保证句柄值连续)
  1. library_once TimerUtils initializer redInit
  2. //*********************************************************************
  3. //* TimerUtils (Red flavor)
  4. //* ----------
  5. //*
  6. //*  To implement it , create a custom text trigger called TimerUtils
  7. //* and paste the contents of this script there.
  8. //*
  9. //*  To copy from a map to another, copy the trigger holding this
  10. //* library to your map.
  11. //*
  12. //* (requires vJass)   More scripts: htt://www.wc3campaigns.net
  13. //*
  14. //* For your timer needs:
  15. //*  * Attaching
  16. //*  * Recycling (with double-free protection)
  17. //*
  18. //* set t=NewTimer()      : Get a timer (alternative to CreateTimer)
  19. //* ReleaseTimer(t)       : Relese a timer (alt to DestroyTimer)
  20. //* SetTimerData(t,2)     : Attach value 2 to timer
  21. //* GetTimerData(t)       : Get the timer's value.
  22. //*                         You can assume a timer's value is 0
  23. //*                         after NewTimer.
  24. //*
  25. //* Red flavor: Fastest, method in existence for timer attaching,
  26. //*             only takes an array lookup, H2I and subtraction.
  27. //*             However, all the code in your map requires extra care
  28. //*             not to forget to call ReleaseTimer. It also requires
  29. //*             to preload a lot of timers at map init, they use
  30. //*             memory and handle ids.
  31. //*
  32. //********************************************************************
  33. //================================================================
  34.     globals
  35.         private constant integer QUANTITY   = 256
  36.         private constant integer ARRAY_SIZE = 8191 //changing this to a higher value would effectively
  37.                                                    //cripple the performance making this thing irrelevant
  38.     endglobals
  39.     //=================================================================================================
  40.     private function H2I takes handle h returns integer
  41.         return h
  42.         return 0
  43.     endfunction
  44.     //==================================================================================================
  45.     globals
  46.         private integer array data[ARRAY_SIZE]
  47.         private integer OFFSET
  48.     endglobals
  49.     //It is dependent on jasshelper's recent inlining optimization in order to perform correctly.
  50.     function SetTimerData takes timer t, integer value returns nothing
  51.         debug if(H2I(t)-OFFSET<0) then
  52.         debug     call BJDebugMsg("SetTimerData: Wrong handle id, only use SetTimerData on timers created by NewTimer")
  53.         debug endif
  54.         set data[H2I(t)-OFFSET]=value
  55.     endfunction
  56.     function GetTimerData takes timer t returns integer
  57.         debug if(H2I(t)-OFFSET<0) then
  58.         debug     call BJDebugMsg("GetTimerData: Wrong handle id, only use GetTimerData on timers created by NewTimer")
  59.         debug endif
  60.         return data[H2I(t)-OFFSET]
  61.     endfunction
  62.     //==========================================================================================
  63.     globals
  64.         private timer array tT
  65.         private integer tN = 0
  66.         private constant integer HELD=0x28829022
  67.         //use a totally random number here, the more improbable someone uses it, the better.
  68.     endglobals
  69.     //==========================================================================================
  70.     function NewTimer takes nothing returns timer
  71.         if (tN==0) then
  72.             //If this happens then the QUANTITY rule has already been broken, try to fix the
  73.             // issue, else fail.
  74.             debug call BJDebugMsg("NewTimer: Warning, Exceeding TimerUtils_QUANTITY, please increase it for your map, fix your map's timer leaks or switch to blue flavor when applicable")
  75.             set tT[0]=CreateTimer()
  76.             if (H2I(tT[0])-OFFSET<0) or (H2I(tT[0])-OFFSET>=ARRAY_SIZE) then
  77.                 //all right, couldn't fix it
  78.                 call BJDebugMsg("NewTimer: Unable to allocate a timer, you should probably switch to the blue flavor or fix timer leaks.")
  79.                 return null
  80.             endif
  81.         else
  82.             set tN=tN-1
  83.         endif
  84.         call SetTimerData(tT[tN],0)
  85.      return tT[tN]
  86.     endfunction
  87.     //==========================================================================================
  88.     function ReleaseTimer takes timer t returns nothing
  89.         if(t==null) then
  90.             debug call BJDebugMsg("Warning: attempt to release a null timer")
  91.             return
  92.         endif
  93.         if (tN==8191) then
  94.             debug call BJDebugMsg("Warning: Timer stack is full, destroying timer!!")
  95.             //stack is full, the map already has much more troubles than the chance of bug
  96.             call DestroyTimer(t)
  97.         else
  98.             call PauseTimer(t)
  99.             if(GetTimerData(t)==HELD) then
  100.                 debug call BJDebugMsg("Warning: ReleaseTimer: Double free!")
  101.                 return
  102.             endif
  103.             call SetTimerData(t,HELD)
  104.             set tT[tN]=t
  105.             set tN=tN+1
  106.         endif   
  107.     endfunction
  108.     private function redInit takes nothing returns nothing
  109.      local integer i
  110.      local integer last
  111.      local boolean correct
  112.         loop
  113.             set tT[0] = CreateTimer()
  114.             set OFFSET=H2I(tT[0] )
  115.             set i=1
  116.             set correct=true
  117.             loop
  118.                 exitwhen (i==QUANTITY)
  119.                 set tT[i] = CreateTimer()
  120.                 if(H2I(tT[i])-OFFSET<0) or (H2I(tT[i])-OFFSET>=ARRAY_SIZE) then
  121.                     debug call BJDebugMsg("TimerUtils_redInit: Failed a initializing attempt")
  122.                     set correct=false
  123.                     exitwhen true
  124.                 endif
  125.                 set i=i+1
  126.             endloop
  127.             exitwhen correct
  128.         endloop
  129.         set tN=QUANTITY
  130.     endfunction
  131. endlibrary
复制代码
回复

使用道具 举报

发表于 2008-12-30 13:25:02 | 显示全部楼层
刚才代码贴错了,汗……现在改过来了
不过单位什么的就无法按那种方法绑定数据了,只能用LZ的方法
回复

使用道具 举报

发表于 2008-12-30 16:28:02 | 显示全部楼层
[codes=jass]globals
integer I
handle H
integer array hashi

//===========数据储存空间=========
//===整数===
integer array udg_Int1
integer array udg_Int2
integer array udg_Int3
integer array udg_Int4
integer array udg_Int5
integer array udg_Int6
integer array udg_Int7
integer array udg_Int8
integer array udg_Int9
integer array udg_Int10
endglobals
function hash takes integer I,handle H,boolean b returns integer
local integer ha=I-I/8191*8191
local integer hb=(I/1987+1)*1987-I
local integer n=0
local integer val
if(b)then
    set val=0
else
    set val=I
endif
loop
    exitwhen(hashi[ha]==val)or(n>499)
    set ha=ha+hb
    set n=n+1
    if(ha>=8191)then
        set ha=ha-8191
    endif
endloop
if(n>499)then
    return -1
else
    if(b)then
        set hashi[ha]=I
    endif
endif
return ha
endfunction[/codes]

需要存储数据的时候。
[codes=jass]function aaa takes nothing returns nothing
local timer t=CreateTimer()
local integer ID=hash(0,t,true)
if(ID!=-1)then
set udg_Int1[ID]='XXXX'
......等等就可以了。
else
call DestroyTimer(t)
endif
set t=null
endfunction

function bbb takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer ID =hash(0,t,false)//这个计时器可是存储过的,ID不会是-1了。
local integer i = udg_Int1[ID]//这个时候你就通过ID获取了这个数据了,好了目标实现


set hashi[ID]=0//这样就回收了一个空位,很简单。
call DestroyTimer(t)
set t = null
endfunction[/codes]

我觉得使用这个方法就不错哇,不需要提前占位,也不用逐个比较的。
回复

使用道具 举报

 楼主| 发表于 2008-12-30 16:43:27 | 显示全部楼层
如果LS的方法的话...
获得ID的效率未必很高把....

关键是获得ID的效率
因为分配Timer 只要调用一次...
而获得ID可能调用几百次.....

以上我第二个函数中
获得ID
return H2I(t) - FIRST_TIMER_H2I
这样效率比较高..

所以个人认为..还是promise6522 说的方法好...
回复

使用道具 举报

发表于 2008-12-30 21:48:05 | 显示全部楼层
引用第10楼冰块于2008-12-30 16:43发表的  :
如果LS的方法的话...
获得ID的效率未必很高把....

关键是获得ID的效率
因为分配Timer 只要调用一次...
.......

非也,这个ID分配的时候与获取的时候使用的步数是一样的。
而分配时需要的步数在排泄良好的情况下也就在1-2之间,效率可是很高的。
回复

使用道具 举报

 楼主| 发表于 2008-12-30 21:52:38 | 显示全部楼层
我知道你那个分配和获得ID的时候效率是相同的啊..
这也正是问题所在..
只要 你那个的效率
没有
return H2I(t) - FIRST_TIMER_H2I
这个高....
就说明这个函数效率还是不高..
因为 获得ID 是重点...
如果分配效率相当高
也就是调用一次罢了...
而 获得ID 效率
决定了这个系统的效率...
而且
return H2I(t) - FIRST_TIMER_H2I
不会效率不会变化...
回复

使用道具 举报

发表于 2008-12-30 22:02:38 | 显示全部楼层
LZ在顶楼贴出了他的第一个办法和改进后的方法。现在仅说第二种方法的特点。
首先,在地图初始化时连续创建8000个计时器,以得到8000个连续的地址并且使用一个计时器数组存储下来。
在地图需要计时器时,首先判断另外一个整数数组的值是否为0,如果是0,则可以返回改计时器,否则查看下一个。
在计时器执行时,可以获取到到期的计时器的Handle值,通过一次减法运算即可知其ID,这一步效率很高。

而我说的方法呢,初始时不需要创建任何东西。
在地图需要计时器时,可以立即创建一个,然后通过Hash函数得到一个唯一的ID。这需要在循环中跑若干圈。
在计时器执行时,亦是通过调用Hash函数得到其ID。经过与上步相同的圈数。

比较而言,LZ的方法在获取ID时的优势确实明显。但是同时运行的计时器越多,则分配ID的效率越低,不过获取ID的效率依然不变。
而我的办法的效率在分配和获取时的效率是相同的。在一张地图不做排泄的情况下,生成的计时器的Handle值是不断增长的,但是在直到需分配的计时器大于第一个8191时,才存在需求值两次的情况。而你如果注意排泄的话,这个情况是完全可以避免的,也就是分配与获取都是高效率的。
同时,我的方法是可以以任意元素(除code,integer,real,boolean外)作为绑定数据的key,范围是相当广的。远胜于LZ的方法。

当然,各有所好,LZ若要坚持自己的方法,我也有一个意见提出,嗯,就是应当提高一下分配ID时的效率。代码如下:

[codes=jass]globals
integer FIRST_TIMER_H2I
integer array TIMER_DATA
integer TIMER_maxN=-1
endglobals

function H2I takes handle h returns integer
return h
return 0
endfunction

function I2Tm takes integer i returns timer
return i
return null
endfunction

function GetTimerofID takes nothing returns integer
set TIMER_maxN=TIMER_maxN+1
return TIMER_DATA[TIMER_maxN]
endfunction

function GetTimerID takes timer t returns integer
return H2I(t) - FIRST_TIMER_H2I
endfunction
//或者使用        //! define GetTimerID(t) (H2I(t)-FIRST_TIMER_H2I)
//在实际应用中为    set id=GetTimerID(t)

function RecTimerofID takes integer id returns nothing
call PauseTimer(I2Tm(FIRST_TIMER_H2I+id))
set TIMER_DATA[TIMER_maxN]=id
if TIMER_maxN>=0 then
    set TIMER_maxN=TIMER_maxN-1
endif
endfunction

function ITS takes nothing returns nothing
local integer i = 1
set FIRST_TIMER_H2I = H2I(CreateTimer())
loop
    exitwhen (i > 511)
    call CreateTimer()
    set TIMER_DATA = i
    set i = i + 1
endloop
endfunction[/codes]

增加了一个整数,用于记录计时器的数量。TIMER_STATE 也不要记录0和1了,浪费资源,改记录待分配的ID,这样分配ID时也只需要一步了。效率会高不少,LZ以为如何。
回复

使用道具 举报

发表于 2008-12-30 22:25:43 | 显示全部楼层
8000多个计时器,确实好多啊~~~
感觉几百个就够用了,毕竟这些计时器都是可复用的,应该不会存在同时运行几百个以上计时器的情况~~如果那样,那么地图离BUG也不远了
回复

使用道具 举报

 楼主| 发表于 2008-12-30 22:27:22 | 显示全部楼层
话说 LS的hash表算法...本人对这个算法一窍不通..
不过看了下函数
有几个疑问
第一那个 handle H 参数 有何意义?
难道就是 在没有计时器的时候 在那个参数里写 CreateTimer()么?
还有就是请问 参数 i 的作用....

我只觉得 如果 调用2此 你那个函数 参数 都是 0,t,true
返回值都是0
而且这个值 和t毫无关系...
回复

使用道具 举报

 楼主| 发表于 2008-12-30 22:35:25 | 显示全部楼层
你不觉得...

[jass]function aaa takes nothing returns nothing
local timer t=CreateTimer()
local integer ID=hash(0,t,true)
if(ID!=-1)then
set udg_Int1[ID]='XXXX'
......等等就可以了。
else
call DestroyTimer(t)
endif
set t=null
endfunction

function bbb takes nothing returns nothing
local timer t = GetExpiredTimer()
local integer ID =hash(0,t,false)//这个计时器可是存储过的,ID不会是-1了。
local integer i = udg_Int1[ID]//这个时候你就通过ID获取了这个数据了,好了目标实现


set hashi[ID]=0//这样就回收了一个空位,很简单。
call DestroyTimer(t)
set t = null
endfunction[/jass]

这个aaa函数 比如是一个技能..
如果同时使用2次..
而且在第2次使用的时候
第一个计时器还没有到期...
这个时候
2次运行的中
ID 都是 0
这样数据不会覆盖么....

还是请CCTV同学来解释一下用法吧.,..
回复

使用道具 举报

发表于 2008-12-30 23:11:58 | 显示全部楼层
嗯,一些回答在13楼。可以改进你的方法中分配ID的效率问题。
15楼的疑问请看Renee大大的Union Bug,你就可以理解这个参数的调用了,返回值不会每次都是0的。
这里的 I 就是H2I(H)以后相同的结果,这个方法也就是依据其handle的唯一性实施的。
同时,对Hash方法的使用有疑问的话,请看http://www.islga.org/bbs/read.php?tid=21595
是我做的钩肥的演示。
回复

使用道具 举报

发表于 2008-12-30 23:31:41 | 显示全部楼层
[codes=jass]globals
integer array hashi

//===========数据储存空间=========
//===整数===
integer array udg_Int1
integer array udg_Int2
integer array udg_Int3
integer array udg_Int4
integer array udg_Int5
integer array udg_Int6
integer array udg_Int7
integer array udg_Int8
integer array udg_Int9
integer array udg_Int10
endglobals
function H2I takes handle h returns integer
    return h
    return 0
endfunction
function hash takes handle h,boolean b returns integer
local integer I=H2I(h)
local integer ha=I-I/8191*8191
local integer hb=(I/1987+1)*1987-I
local integer n=0
local integer val
if(b)then
      set val=0
else
      set val=I
endif
loop
      exitwhen(hashi[ha]==val)or(n>499)
      set ha=ha+hb
      set n=n+1
      if(ha>=8191)then
            set ha=ha-8191
      endif
endloop
if(n>499)then
      return -1
else
      if(b)then
            set hashi[ha]=I
      endif
endif
return ha
endfunction[/codes]

恩,把hash修改成这个样子比较不容易误会了吧。
hash的原理就是将任意元素先转变为整数,然后对其用8191取模,求得一个小于等于8191的数作为记录数据的下角标。因为这样可能导致下脚标的冲突,所以使用重hash来避免,同时由于增长值(就是hb)不能等于0,所以对整数用1987取模再做差就满足条件了,剩下的就是再循环中寻址了。
调用参数中有个boolean值,用于控制是分配或者获取ID。
LZ若听取我的意见修改了你方法中分配ID的方法后,我的方法在速度上确实会比你的方法慢,但我觉得不会差多少,而且我的方法应用的范围可不仅仅只是在timer范围内。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-5-2 21:35 , Processed in 0.149653 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表