找回密码
 点一下
查看: 1865|回复: 1

郁闷中,给Struct赋值,错乱问题

[复制链接]
发表于 2009-8-9 12:29:57 | 显示全部楼层 |阅读模式
[codes=jass]
library HS initializer Init requires ReturnBugSystem
    globals
        private boolean  array hashmap [8192]
        private integer  maxLength  =   8191
        private linklist array key     [8192]
        private linklist array value   [8192]
    endglobals
   
    struct linklist
        integer array list [8192]
           
        static method create takes nothing returns linklist
            return linklist.allocate()
        endmethod
    endstruct
   
    //初始化
    private function Init takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i == 8192
            set hashmap = false
            set key = linklist.create()
            set value = linklist.create()
            set i = i + 1
        endloop
    endfunction
   
    function DebugInt takes string s, integer i returns nothing
        call BJDebugMsg(s+I2S(i))
    endfunction
   
    //获得Struct将要保存的索引
    private function GetStoreIndex takes integer startIndex, integer address returns integer
        local integer i = 0
        loop
            exitwhen key[startIndex].list == 0 or i > maxLength
            set i = i + 1
        endloop
        set key[startIndex].list = address
        return i
    endfunction
   
    //将一个Struct绑定到一个Handdle上
    public function SetHashInteger takes handle h, integer s returns boolean
        local integer address = H2I(h)
        local integer startIndex = 0
        local integer storeIndex = 0
        call DebugInt("保存内存地址:",address)
        if ( address == 0 ) then
            return false
        endif
        set startIndex = address - (address / 8191) * 8191
        call DebugInt("保存主链位置:",startIndex)
        if ( hashmap[startIndex] == false ) then
            call BJDebugMsg("SetTrue")
            set hashmap[startIndex] = true
        endif
        set storeIndex = GetStoreIndex(startIndex,address)
        call DebugInt("子链键值:",key[startIndex].list[storeIndex])
        call DebugInt("保存子链位置:",storeIndex)
        set value[startIndex].list[storeIndex] = s
        call DebugInt("子链键值2:",key[startIndex].list[storeIndex])
        return true
    endfunction
   
    //获得保存的Struct保存索引
    private function GetStoredIndex takes integer startIndex, integer address returns integer
        local integer i = 0
        loop
            exitwhen key[startIndex].list == address or i > maxLength
            set i = i + 1
        endloop
        return i
    endfunction
   
    //获得Hanlde值绑定的Struct
    public function GetHashInteger takes handle h returns integer
        local integer address = H2I(h)
        local integer startIndex = 0
        local integer storedIndex = 0
        if ( address == 0 ) then
            return 0
        endif
        call DebugInt("取出内存地址:",address)
        set startIndex = address - (address / 8191) * 8191
        if ( hashmap[startIndex] == false )then
            call BJDebugMsg("HASH发生错误")
            return 0
        endif
        call DebugInt("取出主链地址:",startIndex)
        call DebugInt("测试:",key[startIndex].list[0])
        set storedIndex = GetStoredIndex(startIndex,address)
        call DebugInt("取出子链地址:",storedIndex)
        set key[startIndex].list[storedIndex] = 0
        return value[startIndex].list[storedIndex]
    endfunction
   
endlibrary
[/codes]
没事弄着玩  发现出错了 主要在这个位置
[codes=jass]
        call DebugInt("子链键值:",key[startIndex].list[storeIndex])
        call DebugInt("保存子链位置:",storeIndex)
        set value[startIndex].list[storeIndex] = s
        call DebugInt("子链键值2:",key[startIndex].list[storeIndex])
[/codes]
我给结构value 的数组list 赋值 结果结构key的数组list也跟着把值改变了

测试结果.jpg
发表于 2009-8-9 13:48:56 | 显示全部楼层
vj不讨论
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-4 12:21 , Processed in 0.166238 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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