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.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top