0

I am new to tcl/Itcl programming.
Is there any data structure in tcl or Itcl or any packages provided for those two that can help me implement the next structure (see the picture below).

Explanation of the data structure:
This data structure is very similar to B-Tree data structure.
But , Every level of the data structure is different class meaning class A can have only child of type class B.
Every "class type" in any level (Node) has another data that is unique to this class in addition to the "pointers" to parent and children of this "Node".

I saw there is the struct::tree data structure but I don't really know if I can use this data structure to implement my data structure with those exceptions.
Is there any way to implement it except creating a "node base class" and 3 more class that inherits from this "node base class" with unique list in each one?

enter image description here

ms_stud
  • 361
  • 4
  • 18

1 Answers1

1

It can be implemented as a nested dictionary.
The key names can of course be whatever you want.

For this example, the C nodes simply have a list of data items. This could be another dictionary instead.

set nodes {
   nodea1 {
      nodeb1 { 
        nodec1 { data1 data2 data3 }
        nodec2  { data1 data2 data3 }
        }
      nodeb2 {
        }
      nodeb3 {
        nodec1 { data1 data2 data3 }
        nodec2  { data1 data2 data3 }
        nodec3  { data1 data2 data3 }
        }
     }
}

puts [dict get $nodes nodea1 nodeb3 nodec2]
Brad Lanam
  • 5,192
  • 2
  • 19
  • 29