Tutorial4 sample Nested Set Model solution:
Another way of representing trees is to show them as nested sets. i.e. Uses containment
represents subordination
. The drawing below shows the organisation chart tree structure represented as nested sets:
We can then model the org units chart with number pairs left
and right
value as shown below:
+---------+
| Albert |
| 1 18|
+----+----+
|
+------------------+--------------+
| |
+---+-----+ +----+----+
| Bert | | Chuck |
| 2 9 | | 10 17|
+----+----+ +----+----+
| |
+------+------+ +--------------------------+
| | | | |
+---+-----+ +----+----+ +---+-----+ +----+----+ +----+----+
| Jane | | Joe | | Donna | | Eddie | | Fred |
| 3 4 | | 5 8 | | 11 12| | 13 14| | 15 16|
+---------+ +----+----+ +---------+ +---------+ +---------+
|
+----+----+
| Max |
| 6 7 |
+---------+
The sample rego code can be found from policies/tutorials/t4