func get_root_children works

This commit is contained in:
bjt-user 2024-05-06 00:58:57 +02:00
parent 21bb0bc95d
commit 1ef07c59c6

16
tree.go
View File

@ -32,6 +32,22 @@ func get_children(header_index int, headings []heading) []heading {
return children return children
} }
func get_root_children(headings []heading) []int {
var root_children []int
lowest_level := 0
for index, value := range headings {
cur_level := value.level
if index == 0 || cur_level <= lowest_level {
root_children = append(root_children, index)
lowest_level = cur_level
}
}
return root_children
}
// TODO: -1 for root -> get indices for headers lying directly under root
func get_child_indices(header_index int, headings []heading) []int { func get_child_indices(header_index int, headings []heading) []int {
var children []int var children []int