Questions about structs

NoobImbaPro

You can change this now in User CP.
Reaction score
60
Lets say I have a empty struct A for beggining
I call A.create() and do some actions inside (using methods)
1)What actually .create() method does? Does it create an empty ram space? Or does it use an already created space for that struct ?
2)I saw in some system using thistype(0) for some reason, what is that, the first ram space for that struct?
3)Let's say I use the created A stuct in "this" variable and then i set this = 1, what I've done ?
4)I saw systems using this.next/prev struct types. What is their purpose?
 

Sevion

The DIY Ninja
Reaction score
413
1. It simply returns the first unused struct instance number.
2. thistype(0) is equivalent to myArray[0]
3. You've effectively set this = thistype(1)
4. To have a doubly linked list.
 

Dirac

22710180
Reaction score
147
This works if none of the structs have been indexed yet
JASS:
method fun takes fun returns fun
set this=thistype.allocate()
//this is now equal to 1
set this=thistype.allocate()
//this is now equal to 2
set this=anothertype.allocate()
//this is now equal to 1
endmethod
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
"4. To have a doubly linked list."
This answer is too general :D

I mean what do they accomplish with that?

Also let's say I have this

JASS:
struct x[300]
endstruct


I initialize 300 array positions in a row like from thistype(0) to thistype(300)? or is it now extended to array?

OFF TOPIC: Sevion when I rep you and for what??
 

tooltiperror

Super Moderator
Reaction score
231
Imagine you have this.

610px-Doubly-linked-list.svg.png

The arrow pointing forward is a nodes "this.next" and the arrow pointing backwards is a nodes "this.prev". If you start from the left most node and move to the right using [ljass]this.next[/ljass], you can go through every node. This saves you some math from using an array, simplifies code, and is usually faster.
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
Yes I understand that from the names already. But what I should care when I use them ?
Should I set this.next.prev = this and this.prev.next = this, if my next struct is a null one, how can I set its previous to the one I have now?
And if I've got the first array how should I know that there no previous than this?
On destroy what should I take in mind? What does destroy actually do?
 

Dirac

22710180
Reaction score
147
I think you're confusing something, prev and next are NOT incorporated in vJass, they're set manually according to what you write.
JASS:
struct chain
thistype next
thistype prev
endstruct

this.prev.next= sets an instance as the next instance of the previous instance in the chain
this.next.prev= sets an instance as the previous instance of the next instance in the chain
this.next= sets an instance as the next instance of instance "this" in the chain
this.prev= sets an instance as the previous instance of instance "this" in the chain
 

Sevion

The DIY Ninja
Reaction score
413
"4. To have a doubly linked list."
This answer is too general :D

I mean what do they accomplish with that?

Also let's say I have this

JASS:
struct x[300]
endstruct


I initialize 300 array positions in a row like from thistype(0) to thistype(300)? or is it now extended to array?

OFF TOPIC: Sevion when I rep you and for what??

The question is too general >_> You asked what the members do. They allow a doubly linked list.

Array structs aren't declared like that FYI. They're defined as [ljass]struct myStruct extends array[/ljass] and then you declare them as [ljass]myStruct foo[/ljass] and use them like [ljass]foo[300][/ljass].

I don't know. There's no such listing in my control panel.

Yes I understand that from the names already. But what I should care when I use them ?
Should I set this.next.prev = this and this.prev.next = this, if my next struct is a null one, how can I set its previous to the one I have now?
And if I've got the first array how should I know that there no previous than this?
On destroy what should I take in mind? What does destroy actually do?

-->

The arrow pointing forward is a nodes "this.next" and the arrow pointing backwards is a nodes "this.prev". If you start from the left most node and move to the right using this.next, you can go through every node. This saves you some math from using an array, simplifies code, and is usually faster.
 

NoobImbaPro

You can change this now in User CP.
Reaction score
60
JassHelper Manual:
Code:
For some reason, the 8190 instances limit is not enough for us, we need 10000 instances ! so:

struct X[10000]
    integer a
    integer b
endstruct

Q)In debug mode I got sometimes messages like "Double free of type: A_Interface" what is not ok now?
Is one member of the interface's I extended to mus struct got prob?

"They allow a doubly linked list." I didn't understand what does this mean at the first time :p

"this.prev.next= sets a struct as the next struct of the previous struct in the chain
this.next.prev= sets a struct as the previous struct of the next struct in the chain"

I got what does it mean, I said if I use this.next.prev = this and this.next is non-allocated struct will it take effect?
 

Sevion

The DIY Ninja
Reaction score
413
I've never seen that method of declaration before. I've never needed more than 8190 instances.

It's because you're destroying some variable of type A_Interface twice.

If you [ljass]set this.next.prev = this[/ljass] when this.next is not allocated, it'll do nothing. It may crash the thread, methinks.
 

Ayanami

칼리
Reaction score
288
Just a bit more information about a doubly linked list.

Generally, a doubly linked list can be imagine as a circle, everything always comes back to the main node (it's called a head i believe). This "head" is [ljass]thistype(0)[/ljass]. When you create a struct instance, you assign an index to that struct instance. This instance starts from 1 and all the way to 8190 instances. [ljass]thistype(0)[/ljass] basically means the instance which has the index of 0, which isn't used. Thus, it can be used as the "head". So let's say you have an "empty" struct.

JASS:
struct MyStruct
    thistype next
    thistype prev

    private static method create takes nothing returns nothing
        local thistype this = thistype.allocate() // creates a new struct instance (index 1)
        set thistype(0).next.prev = this // this doesn't really do anything for now since your struct was initially "empty"
        set this.next = thistype(0).next = // this basically sets this instance's (1) next as the instance 0
        set thistype(0).next = this // sets the 0 instance's next to this instance (1)
        set this.prev = thistype(0) // sets this instance's (1) prev as instance 0

        // currently, your link list would look like:
        // 0 -> 1 -> 0
    endmethod
endstruct


Now let's say you create another instance.

JASS:
struct MyStruct
    thistype next
    thistype prev

    private static method create takes nothing returns nothing
        local thistype this = thistype.allocate() // creates a new struct instance (now index 2)
        set thistype(0).next.prev = this // thistype(0).next refers to instance 1, thus this is setting instance 1's prev to this instance (2)
        set this.next = thistype(0).next = // sets this instance's (2) next as instance 0's next (which is instance 1)
        set thistype(0).next = this // sets the 0 instance's next to this instance (2)
        set this.prev = thistype(0) // sets this instance's (2) prev as instance 0

        // now, your link list would look like:
        // 0 -> 2 -> 1 -> 0
    endmethod
endstruct


That's what it basically does. Then you also need to delink these instances when you destroy them.

JASS:
struct MyStruct
    thistype next
    thistype prev

    private method destroy takes nothing returns nothing
        // imagine you're destroying instance 2
        set this.next.prev = this.prev // sets this.next's (which is instance 1) prev as this.prev (which is instance 0)
        // this would link back instance 1's prev to instance 0
        set this.prev.next = this.next // sets this.prev's (which is instance 0) next as this.next (which is instance 1)
        // this would link back instance 0's next to instance 1

        // then your link will be back to:
        // 0 -> 1 -> 0
    endmethod
endstruct


That's basically how a doubly linked list work. You can use a doubly linked list to iterate through all instances:

JASS:
struct MyStruct
    thistype next
    thistype prev

    private static method iterate takes nothing returns nothing
        local thistype this = thistype(0)

        loop
            set this = this.next
            exitwhen this == 0
  
            // actions
        endloop
    endmethod
endstruct
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top