Skip to content

Commit

Permalink
compute pseudoheight tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
wcharczuk committed Feb 24, 2024
1 parent b92543a commit a1e1963
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions expert_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ func (en *expertNode) computePseudoHeightCached(cache map[Identifier]int, n INod
return height
}

if len(nn.parents) == 0 {
return 0
}

var maxParentHeight int
for _, p := range nn.parents {
parentHeight := en.computePseudoHeightCached(cache, p)
Expand Down
15 changes: 15 additions & 0 deletions expert_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,18 @@ func Test_ExpertNode_Value(t *testing.T) {
value := en.Value()
testutil.Equal(t, "hello", value)
}

func Test_ExpertNode_ComputePseudoheight(t *testing.T) {
g := New()

r00 := Return(g, "r")
m10 := Map(g, r00, ident)
m20 := Map(g, m10, ident)
m30 := Map(g, m20, ident)

_ = MustObserve(g, m30)

testutil.Equal(t, m10.Node().height, ExpertNode(m10).ComputePseudoHeight())
testutil.Equal(t, m20.Node().height, ExpertNode(m20).ComputePseudoHeight())
testutil.Equal(t, m30.Node().height, ExpertNode(m30).ComputePseudoHeight())
}

0 comments on commit a1e1963

Please sign in to comment.