HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Efficient subtype testing

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
subtypeefficienttesting

Problem

Languages like Java, C#, Eiffel, and C++ have subtype hierarchies which are directed acyclic graphs, due to interfaces in Java and C# and multiple inheritance in Eiffel and C++. An obvious way to check whether type $A$ is a subtype of type $B$ is to traverse the graph of the subtype hierarchy starting at $A$ to see whether type $B$ appears 'above' it. This surely is not the most efficient way to implement subtype tests.


What techniques exist to efficiently implement subtype testing for modern OO languages?

I'm interested in efficiency both in terms of time and memory and any trade-offs between the two.

Solution

Yves Caseau gave a method for efficiently encoding type hierarchies as bit vectors. See Efficient handling of multiple inheritance hierarchies.

Context

StackExchange Computer Science Q#2198, answer score: 2

Revisions (0)

No revisions yet.