Giter VIP home page Giter VIP logo

Comments (4)

riquito avatar riquito commented on August 19, 2024

Hi, it's been a long time since I looked at Baobab, so forgive me for any imprecision.
The tree built in a nested set model is not a binary tree. Every node can have 1 to N children, so children are not really split between left and right.
Your red "left most" node is not left most at all, it's not left or right of its child (or left or right of its parent), so it's not special in any way.

Here's your tree using some labels (easier to talk about, using mermaid syntax in markdown)

graph TD;
    A-->B;
    A-->C;
    B-->D;;
    B-->E;
    D-->G;
    G-->L;
    C-->F;
    F-->H;
    F-->I;
    H-->M;
    I-->N;
    N-->O;

If I were to search for leftmost and rightmost, I'd say they are L and O.
You can find them using getLeaves(), then in the resulting array they will be the first one (L) and the last one O

from baobab.

beshoo avatar beshoo commented on August 19, 2024

Thank you for your kindly reply
I do understand that the nested set lft and rgt are not RIGHT LEFT of the node.
for that reason, am only add 2 children for the node, and to mark if this child is on the left or right side of the node to create binary tree, I created another field named a position which I will mark the node if it is On The LEFT or Right, and when I want to insert a new node I will give it this mark.

Noe let's assume the "L" has a new child on the RIGHT. So L will not be Leave but the "LEFT" as a binary is empty.
So how can i get if the node is Leave or it has one child?

from baobab.

riquito avatar riquito commented on August 19, 2024

Uh, that's quite special, let's see. In your tree, every parent of a single leaf have rgt - lft == 3, so you could search for them using a SQL query and then see if their only child is left or right. This is not fast but it's not terrible either (you have to investigate only children of single parents)

from baobab.

beshoo avatar beshoo commented on August 19, 2024

Thank you , problem solved

from baobab.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.