| 05-31-2006, 03:59 AM | #1 |
Let say I wanted to make a list. I could use gamecache, or I could hijack a location. The list api is retardedly simple and it would work as follows If I used a gc, then I need to make it a node class, with two functions Head (car/getdata), and Tail (cdr/getnext). As far as a null list, I could simply create a special gc object that when passed to a function isNull returns true. For locations its actually a bit easier: function car takes location l returns integer return GetLocatonX(l) return 0 endfunction Tail=GetY function cdr takes location l returns location return GetLocationY(l) return null endfunction function IsNull takes location l returns boolean return l==null endfunction Vex says most of the slowdown of gamecache is return bug, but what about other data structures. I'm only wrapping GetX with integer since almost everybody uses H2I. |
| 05-31-2006, 04:27 AM | #2 |
Okay actually locations seem to be pretty fucked up, check out this sample code: JASS:function H2R takes handle h returns real return h return 0.0 endfunction function ItoR takes integer i returns real return i return 0. endfunction function car takes location list returns integer return GetLocationX(list) return 0 endfunction function cdr takes location list returns location return GetLocationY(list) return null endfunction function IsNull takes location list returns boolean return list==null endfunction function cons takes integer d, location l returns location return Location(ItoR(d),H2R(l)) endfunction function PrintList takes location l returns nothing if(not IsNull(l))then call BJDebugMsg(I2S(car(l))) call PrintList(cdr(l)) endif endfunction function Test takes nothing returns nothing local location l=cons(5,null) set l=cons(7,l) set l=cons(23,l) set l=cons(0,l) if(car(cdr(l))==203 and car(cdr(l))==0)then call BJDebugMsg("Wow this is fubared!") else call PrintList(l) endif endfunction |
| 05-31-2006, 04:35 AM | #3 |
Well the fix is pretty silly but I read what pipedream said, and I figured it out I realize that this is a triple post but I figure this is worth nothing. The idea is you have to do store the values as explicit whatevers whenever you use real as your dummy data spot. To get around this I simply built generic typecasters, and then I create a local version in the calls car and cdr this fixes the problem. I still have no idea WHY IsNull worked perfectly, when car and cdr would cause such bizzare problems. JASS:function H2R takes handle h returns real return h return 0.0 endfunction function R2H takes real r returns handle return r return null endfunction function ItoR takes integer i returns real return i return 0. endfunction function RtoI takes real r returns integer return r return 0 endfunction function car takes location list returns integer local integer i= RtoI(GetLocationX(list)) return i endfunction function cdr takes location list returns location local handle h=R2H(GetLocationY(list)) return h endfunction function IsNull takes location list returns boolean return list==null endfunction function cons takes integer d, location l returns location return Location(ItoR(d),H2R(l)) endfunction function PrintList takes location l returns nothing if(not IsNull(l))then call BJDebugMsg(I2S(car(l))) call PrintList(cdr(l)) endif endfunction |
| 05-31-2006, 05:32 AM | #4 |
Maybe it's the not operator that makes it happy. If you want list behavior, it should be about the same speedwise. I'd go with the locations since you can deallocate 100% of the memory and you won't have a first time I2S hit. JASS:function cdr takes location list returns location local handle h=R2H(GetLocationY(list)) return h endfunction JASS:function cdr takes location list returns location local integer h=RtoI(GetLocationY(list)) return h return null endfunction For sanity and consistency I've started using "to" instead of "2" for all return bugging casting. |
| 06-01-2006, 03:24 AM | #5 |
the closest thing we had to return bug exploiter naming standard was the 2 |
| 06-01-2006, 03:28 AM | #6 |
yeah, but then what about Real->Int bugged caster? We can't really call it R2I. |
| 06-01-2006, 04:08 AM | #7 |
no wonder why I hate return bug exploiters. to is just to long so long that we could go for more verbose and readable ones instead like RealToInt , we could go r2i and use lower case for return bug exploiters. We could see lower case as for reference type conversions and Upper case for the value conversions. But well not like we would ever have an standard for this. Edit: If you only need a single linked list, locations would be better. Is the most slow part of the handle variables and similar behaviours, but gamecache is still very slow and a list that uses locations should be faster than one that uses gamecache. |
