Moar questions about 'this'

PurgeandFire

zxcvmkgdfg
Reaction score
509
Well, think of it like this. You have a list:
<HEAD NODE> <NEXT 1> <NEXT 2> <NEXT 3> <NEXT 4>
In this case, the <HEAD NODE> is [ljass]thistype(0)[/ljass]. Then it chains into <NEXT 1, 2, 3, 4>. When we insert an instance, where do we insert it?
<HEAD NODE> <INSERT> <NEXT 1> ...

We will insert it at the beginning right after the head node. It is nice to think of it as a table. What you want to do is make the head think its next is the inserted, inserted think its prev is the head, the inserted think its next is next1, and next1 think its previous is the inserted. At first:
thistype(0)'s next = <NEXT 1>
this' next = Not defined.
this' prev = Not defined.
NEXT 1's prev = thistype(0).

At the moment, it is nothing. So now lets begin the process:
JASS:
set thistype(0).next.prev=this


thistype(0)'s next = <NEXT 1>
this' next = Not defined.
this' prev = Not defined.
NEXT 1's prev = this

Now we've made NEXT 1 think its previous is "this". At the moment, thistype(0).next is equal to NEXT 1. Previously thistype(0).next.prev == thistype(0), but now thistype(0).next.prev = this. Basically, NEXT 1's previous is now "this".

JASS:
set this.next=thistype(0).next


thistype(0)'s next = <NEXT 1>
this' next = <NEXT 1>
this' prev = Not defined.
NEXT 1's prev = this

Now we make "this" think its next is NEXT 1. So far, we've made NEXT 1 think it's previous is "this" and "this" think its next is NEXT 1. Now we need to handle the other two parts.

JASS:
set thistype(0).next=this


thistype(0).next = this
this' next = <NEXT 1>
this' prev = Not defined.
NEXT 1's prev = this

Now we made the head node think its next (the first instance in the list) is "this". Notice how when you add an instance, it is essentially shifting the order of things. <NEXT 1> now becomes second in the list, <NEXT 2> becomes third, <NEXT 3> becomes fourth, and so on. Think of basically a kindergartner cutting in front of his class in the line for lunch. Everyone's order after him becomes shifted down.

Now we must finish the insert.

JASS:
set this.prev=thistype(0)


thistype(0).next = this
this' next = <NEXT 1>
this' prev = thistype(0)
NEXT 1's prev = this

Now we've officially inserted it. To answer your questions:

1.) Yes.

2.) Yes.

3.) No, you are making thistype(0) think its next instance is "this". =)

4.) Uhmm....

Now, visualizations are key to understanding these concepts.
linkedlist2.gif

^ A standard list. It simply shows the order of each item. Starting from the head node, it goes on to 1, 2, 3, and 4.

linkedlist3.gif

^ Now a new item comes into the list.

linkedlist4.gif

^ The new item doesn't know its identity. The other items are still considered 1, 2, 3, and 4 of the list. The new item is just randomly there. But once he declares himself as part of the list, letting the head node and the next node (in the pic, it is <- == prev node, -> == next node, despite his facing) that he is part of the list. Each item won't really "know" that the new item is there, but I wanted to just show you that once something comes in and is properly inserted, the list will be now ready again.

So it went from 1, 2, 3, and 4 to 1, 2, 3, 4, and 5. Those are just visual numbers, not really meant to signify anything but the literal order of the list.

Hopefully that'll clear some things up. :D
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
Woah..
Master PurgeandFire..

I have been enlightened O_O
Lemme' see if I can type out the code to let the head and inserted node (?) know their next and previous instances without refering to anything..

Umm..
JASS:
set thistype(0).next.prev = this //We want &#039;NEXT 1&#039; to think that it&#039;s previous instance is this.
set this.next = thistype(0).next //We want this instance to think that it&#039;s next instance is the &#039;head&#039;s next instance

//Now that we&#039;ve done all we needed with node &#039;NEXT 1&#039;, we can over-write any pointers refering to &#039;NEXT 1&#039;, like thistype(0).next
set thistype(0).next = this //To the &#039;HEAD&#039;, the list is complete.
//But not to the &#039;inserted&#039; instance, so..
set this.prev = thistype(0)  //Tadah!

//Now to check..


OMG!
I really understand it now ._.
Thanks, Purge!
Woo hee!!
I finally get it after so long!
(And my WC3 editor had to crash just before I got this knowledge -____-)

So..
New question.
Why are linked lists good for spells like.. "Meat hook" ?
 

Trollvottel

never aging title
Reaction score
262
well, meat hook spells are often done with structs. there you actually CAN use arrays, but the problems are:
1. the array has a limited and not changeable size
2. the max instance limit is reduced by this
if there is 1 hook 40 links long and 1 hook 80 links long, you use at least 160 link instances (the array size is min. 80 so there are 40 link spots unused for the one hook)


now if you use a linked list, you only need one node for each link.
if there is 1 hook 40 links long and 1 hook 80 links long, you need 120 instances
another important point:
its much easier to implement with a linked list. you dont have to care about so many things, just compare my old meathook implementation with Kenny's.
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
*Uses Search Function*
I think I see where this is going, though..

[EDIT]
Let's see..
Yours used an array..
And Kenny's used linked lists..

Umm..
I can't see anything else beyond that =x
(Except that his appears to have more functionality? o.0)

[EDIT=2]
Oh!
And also, his doesn't waste any unused link spots, unlike arrays?
So you can configure how many links you want per cast and not waste any unused variables?
 

Trollvottel

never aging title
Reaction score
262
yep thats kinda it. you see that I had to define

JASS:
private constant integer MAXCHAINS  = 60

(= 136 max instances with max 60 chains)
while he did not have to.


also you will find that his code is much more organized (not only because of the linked list, but it also accounted for this :p) and thus better to edit, read and fix.
 

SineCosine

I'm still looking for my Tangent
Reaction score
77
Mm..
If I could open my WE, I'd know a spell or 2 that I made some time ago that would benefit from this ._.

Garr...
I am so pissed.
I've tried everything, Registry Scanners, re-installing WC3, deleting JNGP and re-downloading it, Defragmenting (Yea, at this point, I'm doing random things), attaching DrWatson and JIT Debuggers, nothing's working or getting me close to resolving this -____-

Maybe I should re-format my PC.
But I don't have an external hard disk to back up to.
And I don't much cash on me at the moment..

Woah, I went off-topic there =/
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top