(Really) Tight bounds for dispatching binary methods
We consider binary dispatching problem originating from object oriented programming. We want to preprocess a hierarchy of classes and collection of methods so that given a function call in the run-time we are able to retrieve the most specialized implementation which can be invoked with the actual types of the arguments. For the binary dispatching, where the methods take exactly two arguments, logarithmic query time is possible, even if the structure is allowed to take linear space. Unfortunately, known solutions achieving such complexity require superlinear time for constructing the structure. Using a different idea we are able to construct in (deterministic) linear time and space a structure allowing dispatching binary methods in the same logarithmic time. Then we show how to improve the query time to slightly sublogarithmic, which is easily seen to be optimal as a consequence of some already known lower bounds if we want to keep the size of the resulting structure close to linear.
💡 Research Summary
The paper addresses the binary method dispatch problem that arises in object‑oriented programming when a method takes exactly two arguments. Given a class hierarchy (a rooted tree) and a set of binary methods, the task is to preprocess the data so that at run‑time, for any pair of actual argument types, the most specialized implementation—i.e., the method whose parameter types are the deepest descendants compatible with the arguments—can be retrieved quickly.
Previous approaches achieve logarithmic query time by building sophisticated indexing structures, but they require super‑linear preprocessing time (often O(n log n) or worse) and quadratic or near‑quadratic space because they enumerate all possible type pairs. This makes them impractical for large code bases where the number of classes n and the number of methods m can be in the tens of thousands.
The authors introduce a new deterministic construction that runs in linear time O(n + m) and uses linear (or almost linear) space while still supporting O(log n) query time. The key ideas are:
-
Euler‑tour labeling of the class tree. Each class node receives an entry time and an exit time from a depth‑first traversal. These timestamps allow constant‑time checks of ancestor‑descendant relationships.
-
Geometric representation of methods. A binary method with parameter types (A, B) is mapped to an axis‑aligned rectangle R =