Linked Lists

emjlr3

Change can be a good thing
Reaction score
395
as I don't quite get what is going on here, I would appreciate it if someone could learn me sumpin'

extracted from T32x:

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


what exactly is [ljass]thistype(0)[/ljass] referring to?

same thing in the [ljass]PeriodicLoop[/ljass] method

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


I was trying to use a similar approach, with the addition of a stop check for the periodic timer

JASS:
if thistype(0).prev==0 then
    call PauseTimer(TIMER)
endif


just doesn't quite cut it....
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
thistype(<integer>) == structName(<integer>), since the default vJass allocator use the index 1 to 8190, Jesus4Lyf just use the index 0 for the head of the linked list (he could use a static member instead).

VJass does implicit typecasting when you use a struct instance as an integer, though you can explicit it with integer(<structInstance>).
But if you want to use an integer as a struct instance you have to explicit it, using thistype() or structName().
 

Sevion

The DIY Ninja
Reaction score
413
[ljass]thistype(0)[/ljass] refers to the head (top, front, first, what-have-you).

It's literally the starting point of the list.

That first snippet

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


Think of it like this image that I whipped up:

explaininglinkedlists.png


The second snippet

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


Is making a variable (named this) point to the first non-null instance in the list (the second instance if you count thistype(0)).

As for the third part, [ljass]thistype(0).prev[/ljass] should always be 0 as long as it's not a doubly linked list (meaning first and last are linked together to make a full circle).

If you need more help explaining linked lists you can add me on MSN ([email protected]). It'd be a lot easier.
 

emjlr3

Change can be a good thing
Reaction score
395
if i get this right

when [ljass]thistype(0)==0[/ljass] the list should be empty?
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
no

structs are really made out of arrays in vjass

when you typecast a struct instance to an integer, you're getting the array index the struct uses

eg:
JASS:
    MyStruct(41).stringVariable = &quot;blah&quot;
    // translates to
    MyStruct__stringVariable[41] = &quot;blah&quot;

    // therefore
    (thistype(0) == 0)
    // becomes
    (0 == 0)
    // and will always return true


    // to check if the list is empty, you want to check if the head node exists
    (thistype(0).next == 0)
    // will return true if list is empty
 

Sevion

The DIY Ninja
Reaction score
413
When [ljass]thistype(0).next == 0[/ljass] the list should be empty.

And Narks, I hate to nit pick, but [ljass]MyStruct(41).stringVariable = "blah"[/ljass] translates to [ljass]si__MyStruct_stringVariable[41] = "blah"[/ljass] and [ljass](thistype(0) == 0)[/ljass] translates to [ljass](si_MyStruct[0] == 0)[/ljass] :p
 

emjlr3

Change can be a good thing
Reaction score
395
so the head basically does not count in this case? you never actually use it to run a spell from?
 

Sevion

The DIY Ninja
Reaction score
413
Never. It just serves as a starting point. The first node that actually is used is [ljass]thistype(0).next[/ljass] (which is typically [ljass]thistype(1)[/ljass]).
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
JASS:
(si_MyStruct[0] == 0)

wat
what's si_MyStruct? an integer array containing the index of the struct on each index? if so... wat

thistype(0) isn't used as a node - it's not part of the list, jesus was just using thistype(0).next as a head variable

think of it like:

JASS:
private static thistype head;
private thistype next;

function iterateThroughList()
{
    thistype node = head;
    while (node != 0)
    {
        node.doStuff();
        node = node.next;
    }
}

// and the version jesus4lyf used:
private thistype next;

function iterateThroughList()
{
    // instead of using a static head variable:
    thistype node = thistype(0).next;
    while (node != 0)
    {
        node.doStuff();
        node = node.next;
    }
}
 

tooltiperror

Super Moderator
Reaction score
231
so the head basically does not count in this case? you never actually use it to run a spell from?

Pretty much. Normally you would have to keep saving the head as a static variable in the struct. Instead, you just reserve 0 ([ljass]thistype(0)[/ljass]) to be the head always.
 

Sevion

The DIY Ninja
Reaction score
413
I never said [ljass]thistype(0)[/ljass] was used as a node... If you read my posts I never once said that. I've been saying that [ljass]thistype(0)[/ljass] was the head.
 

emjlr3

Change can be a good thing
Reaction score
395
I never said [ljass]thistype(0)[/ljass] was used as a node... If you read my posts I never once said that. I've been saying that [ljass]thistype(0)[/ljass] was the head.

i didnt know you meant the head was just a marker, and contained no data, I assumed it was also sued to store data, but was referred to as the head because it was the first node too
 

Sevion

The DIY Ninja
Reaction score
413
Sevion said:
Never. It just serves as a starting point. The first node that actually is used is [ljass]thistype(0).next[/ljass] (which is typically [ljass]thistype(1)[/ljass]).

:rolleyes:
 

emjlr3

Change can be a good thing
Reaction score
395
well yea that is where I finally got it, prior to the aforementioned comment
 

Sevion

The DIY Ninja
Reaction score
413
Post 12 was more directed at Narks than you :p

To explain why [ljass]thistype(0)[/ljass] translates to [ljass]si_MyStruct[0][/ljass]: thistype(0) is still a node. It's just the "first" node. It's simply the first instance of the array (at index 0).

If [ljass]thistype(0)[/ljass] translated to 0, then the entirety of structs wouldn't work in vJASS.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top