HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Attaching System, need opinions

03-03-2009, 03:56 PM#1
Vestras
Hello.

I made this system, a struct attachment system, which I have benchmarked. The (JAPI) benchmarks tells me it is just about as fast as TimerUtils Blue in getting data and a little bit slower in setting.

I think it is safer than the most systems out there, but is that true? Is there anything good about it, besides that? Is it submit-worthy?

Please tell me your opinions.
Collapse JASS:
library GeneralData
//********************************************************
//*      GeneralData 
//*     - Made by Vestras
//*
//*    This is a data attaching system which stores data in 
//* arrays based on calculations which are made depending
//* on the handle's id.
//*
//*    This system is, AFAIK, the safest system out there, 
//* and if you exceed the limit the data will be stored
//* in gamecache. At that point gamecache will be faster
//* than any other available system, according to my 
//* benchmarks.
//*
//*    Benchmark tests have shown me that this system is
//* about 10% - 15% slower than TimerUtils (Blue) in 
//* setting data and a tiny, tiny (0.01 milisecond) bit
//* slower in getting data.
//*
//*    This concludes this documentation.
//********************************************************


    globals
        //* The only 'configurable' global in this system, which you most likely wouldn't want to edit:
        private constant integer HASH = 0x30C4
        //* This is used in the following lines:
        //* set i = H2I(h)
        //* set i = i - (i / HASH) * HASH

        //* This value is the ABSOLUTE maximum value
        //* This value is a hex code because my benchmark tests showed me that hex codes were 40% faster than normal integers
        //* 30C4 = 12484

        //* The maximum number of stored structs/data at a time is approx. 125000
        //* When the maximum storage space is exceeded, the data will be stored in a gamecache
        //* If you have exceeded this value, gamecache will most likely be faster than any other available data attaching system

        
        //* The handle and integer arrays usesd for storing
        private handle array Handlex01
        private handle array Handlex02
        private handle array Handlex03
        private handle array Handlex04
        private handle array Handlex05
        private handle array Handlex06
        private handle array Handlex07
        private handle array Handlex08
        private handle array Handlex09
        private handle array Handlex10
        
        private integer array Datax01
        private integer array Datax02
        private integer array Datax03
        private integer array Datax04
        private integer array Datax05
        private integer array Datax06
        private integer array Datax07
        private integer array Datax08
        private integer array Datax09
        private integer array Datax10
        
        //* Gamecache used when a user extends the maximum storage space
        private gamecache SafetyCache = InitGameCache("generaldatasafety.w3v")
        
        //* Globals acting as locals
        private integer i 
        //* This:
        //* globals
        //* private integer i
        //* endglobals
        //* (...)
        //* set i = 2
        //* will be about 2 times as fast executed as
        //* local integer i = 2
        //* (This benchmarking test was done by Jesus4Lyf)
    endglobals

    private function H2I takes handle h returns integer
        return h
        return 0
    endfunction
    
    function SetData takes handle h, integer d returns nothing
        set i = H2I(h)
        set i = i - (i / HASH) * HASH
        
        if Handlex01[i] == h or Handlex01[i] == null then
            set Datax01[i] = d
            set Handlex01[i] = h
        elseif Handlex02[i] == h or Handlex02[i] == null then
            set Datax02[i] = d
            set Handlex02[i] = h
        elseif Handlex03[i] == h or Handlex03[i] == null then
            set Datax03[i] = d
            set Handlex03[i] = h
        elseif Handlex04[i] == h or Handlex04[i] == null then
            set Datax04[i] = d
            set Handlex04[i] = h
        elseif Handlex05[i] == h or Handlex05[i] == null then
            set Datax05[i] = d
            set Handlex05[i] = h
        elseif Handlex06[i] == h or Handlex06[i] == null then
            set Datax06[i] = d
            set Handlex06[i] = h
        elseif Handlex07[i] == h or Handlex07[i] == null then
            set Datax07[i] = d
            set Handlex07[i] = h
        elseif Handlex08[i] == h or Handlex08[i] == null then
            set Datax08[i] = d
            set Handlex08[i] = h
        elseif Handlex09[i] == h or Handlex09[i] == null then
            set Datax09[i] = d
            set Handlex09[i] = h
        elseif Handlex10[i] == h or Handlex10[i] == null then
            set Datax10[i] = d
            set Handlex10[i] = h
        else
            debug call BJDebugMsg("GeneralData: fatal error - maximum storage space exceeded!")
            call StoreInteger(SafetyCache, "safety", I2S(i), d)
        endif
    endfunction

    function GetData takes handle h returns integer
        set i = H2I(h)
        set i = i - (i / HASH) * HASH
        
        if Handlex01[i] == h or Handlex01[i] == null then
            return Datax01[i]
        elseif Handlex02[i] == h or Handlex02[i] == null then
            return Datax02[i]
        elseif Handlex03[i] == h or Handlex03[i] == null then
            return Datax03[i]
        elseif Handlex04[i] == h or Handlex04[i] == null then
            return Datax04[i]
        elseif Handlex05[i] == h or Handlex05[i] == null then
            return Datax05[i]
        elseif Handlex06[i] == h or Handlex06[i] == null then
            return Datax06[i]
        elseif Handlex07[i] == h or Handlex07[i] == null then
            return Datax07[i]
        elseif Handlex08[i] == h or Handlex08[i] == null then
            return Datax08[i]
        elseif Handlex09[i] == h or Handlex09[i] == null then
            return Datax09[i]
        elseif Handlex10[i] == h or Handlex10[i] == null then
            return Datax10[i]
        else
            return GetStoredInteger(SafetyCache, "safety", I2S(i))
        endif
        
        return 0
    endfunction

    function RemoveData takes handle h returns nothing
        set i = H2I(h)
        set i = i - (i / HASH) * HASH
        
        if Handlex01[i] == h then
            set Handlex01[i] = Handlex02[i]
            set Datax01[i] = Datax02[i]
            set Handlex02[i] = null
            set Datax02[i] = 0
        elseif Handlex02[i] == h then
            set Handlex02[i] = Handlex03[i]
            set Datax02[i] = Datax03[i]
            set Handlex03[i] = null
            set Datax03[i] = 0
        elseif Handlex03[i] == h then
            set Handlex03[i] = Handlex04[i]
            set Datax03[i] = Datax04[i]
            set Handlex04[i] = null
            set Datax04[i] = 0
        elseif Handlex04[i] == h then
            set Handlex04[i] = Handlex05[i]
            set Datax04[i] = Datax05[i]
            set Handlex05[i] = null
            set Datax05[i] = 0
        elseif Handlex05[i] == h then
            set Handlex05[i] = Handlex06[i]
            set Datax05[i] = Datax06[i]
            set Handlex06[i] = null
            set Datax06[i] = 0
        elseif Handlex06[i] == h then
            set Handlex06[i] = Handlex07[i]
            set Datax06[i] = Datax07[i]
            set Handlex07[i] = null
            set Datax07[i] = 0
        elseif Handlex07[i] == h then
            set Handlex07[i] = Handlex08[i]
            set Datax07[i] = Datax08[i]
            set Handlex08[i] = null
            set Datax08[i] = 0
        elseif Handlex08[i] == h then
            set Handlex08[i] = Handlex09[i]
            set Datax08[i] = Datax09[i]
            set Handlex09[i] = null
            set Datax09[i] = 0
        elseif Handlex09[i] == h then
            set Handlex09[i] = Handlex10[i]
            set Datax09[i] = Datax10[i]
            set Handlex10[i] = null
            set Datax10[i] = 0
        elseif Handlex10[i] == h then
            set Handlex10[i] = null
            set Datax10[i] = 0
        else
            call FlushStoredInteger(SafetyCache, "safety", I2S(i))
        endif
    endfunction

endlibrary
03-03-2009, 05:18 PM#2
emjlr3
isnt that sort of what vJASS does internally with extended arrays?
03-03-2009, 05:25 PM#3
Vestras
Quote:
Originally Posted by emjlr3
isnt that sort of what vJASS does internally with extended arrays?

Tbh I never researched about that :(
So I don't know, but I hope it's not...
03-03-2009, 05:34 PM#4
Captain Griffen
Old. Not used because it sucks for reasons of safety, speed, general sanity and multiinstanceability.
03-03-2009, 06:03 PM#5
Vestras
Quote:
Originally Posted by Captain Griffen
Old. Not used because it sucks for reasons of safety, speed, general sanity and multiinstanceability.

Okay, so my thoughts were wrong. But this uses the same hash and storage stuff thingy as ABC, but is ABC better because it uses gamecache when the storage limit is exceeded or?
03-04-2009, 04:34 AM#6
fX_
How do you appraise the speed of a script?
03-04-2009, 06:31 PM#7
Vestras
Any more opinions? Any ideas on how to improve it?
03-05-2009, 03:47 AM#8
Captain Griffen
If/then/else is actually pretty so I believe.
03-05-2009, 10:16 AM#9
xombie
I'd help ya if I could - nobody really gave you an answer whatsoever.
03-05-2009, 01:18 PM#10
Vestras
Quote:
Originally Posted by Captain Griffen
If/then/else is actually pretty so I believe.

What?

Quote:
Originally Posted by xombie
I'd help ya if I could - nobody really gave you an answer whatsoever.

What should be changed then?

Edit: updated.