Help with loop : (

Nestharus

o-o
Reaction score
84
So I've been trying to solve this for like 20 hours now and still can't solve.

I am looping over this type of structure (although it is unknown what's in it).

Code:
head
    link (points to head)
        pointer (points to 0)
            link (points to pointer)
                val (points to 0)
                    link (points to val)
                       val (points to 0)
            link (points to pointer)
                val (points to 0)
                    link (points to val)
                       val (points to 0)
            link (points to pointer)
                val (points to 0)
                    link (points to val)
                       val (points to 0)
    link
        val (points to 0)

The data I showed is entirely random. What is known is that there is a link connecting everything together. It will always go link -> (pointer | val).

Pointers are nodes that are automatically skipped over and are never seen.

Values are there for writing data
Links look at the current parent depth's value. If the value is in the range of the link, then it goes inside of the link.

Code:
Value (15)
    Link (0 to 15) (go inside)
    Link (20 to 30) don't go in)
    Link (15 to 15) (go in)

And within the links, there could be any number of pointers.

The loop I am using to go through this data structure just contains 2 operators and 1 method-

get (get the next node, could be from anywhere but it is the next node in the structure)

skip (skips the current node, meaning it skips all contents in it)

end (end the loop)

So, if the value doesn't fit into the link, skip is used. If the value does fit, get is used to actually get to the val inside and skip isn't used. On every iteration, get is used at the very beginning to get the next node.


While this seems pretty straight forward and easy so far, it really isn't. I need to know what the current parent depth's value is. I am currently using a stack to stack values on to each other. When I go deeper, I add to the stack and update the value. When I go out, I pop off from the stack. Again, straight forward, but I could be going out any amount.

To see how far to go out, I go out until the current stored parent link matches the current link's parent.

Remember along a column, all links share the same parent.

Code:
parent
    link
    link
    link
    link

All 4 of those links would have the same exact parent. If I went out of parent and into a whole different parent, it'd end up going to the very top (stack would be empty) and then would add on to the stack.

Seems good so far still right?

The problem is that my current method can't retrieve the parent until after** skipping occurs. This means that this can happen

get (go deeper)
skip (uh oh, no parents match, so ends up going to the very top)


The problem with get is that it could either end up going deeper or going out or w/e. Checking to see if the next node's parent matches with the current depth link does see if the current depth is the same, but if it isn't, you have no idea whether you went up or down because links will point to value nodes and value node parents are 0. For every node, there are only 2 possible connections (excluding pointers, which don't matter)

link.root = parent

So... I'm struggling with determining how to update the depth w/o access to the loop method : (.

Any ideas?

Code:
    get next node

    loop
        exitwhen not a link

        loop
            exitwhen not link or fits or 0
            skip link
            loop
                exitwhen depth parents match (this is where bug of 0 can happen)
            endloop
        endloop

        if link, add to depth stack
    endloop

That's what my loop structure looks like where get and skip are methods.

So... from what I see, the only way to fix the bug is update the depth stack upon the retrieval of the next node as well as skips.

Again, the problem is I don't know (when the depth is different) where I am : O. I've been straining over this problem for so long and really need help with it. The only possible thing I can think of is to code the get/skip looping stuff from scratch so that I can update the depths in there (inside of there, I'd def know, but it's a lot of code and it's really, really ugly, so I really don't want to do it).

Tx for your help ;D.



Bribe
Seems like you're missing a sound reverse-lookup method. I wrote a new List library which runs based off of Table that allows insertion in arbitrary points and iterate backwards if necessary, but essentially this would mean you can have an unlimited linked-list for your data structure to work with.

Resp
Bribe... there is a reason that there is no parent node.

Didn't you see the links ; P.

Let's say all of these are the exact same node
->val (points to 0)

And all of the Links are unique nodes.

A node can't have multiple parents >.>, hence why all val nodes point to 0 rather than the links.

So I'm guessing I'll have to code this loop from scratch : (.

Super Good
I am sorry but I do not understand what you are after. It may not even be the best structure to solve the problem you have for all we know.

Resp
It is the best ; ).

I just want to be able to go through it step by step and be able to know what the current link is (pointer parent) and the current node is.

Like I keep saying, my prob is that when I use the get method (for getting the next node in the tree), I don't know whether it's going deeper in or out, so I have no clue how to update the current link depth.

For storing the linnks, I'm using a stack. When I go deeper, I add to the stack. When I go out, I remove from the stack.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • 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
  • 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 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