Let's assume a function foo()
with the following four overloads:
foo(a, b)
foo(a, b, d)
foo(a, c)
foo(a, c, d)
I want to generate a concise string that represents all overloads at once. In this case, the result should be foo(a, (b|c), [d])
.
Edit: There is usually more than one concise representation. My goal is to get a representation that is as short as possible, counting only parameters. So foo(a, (b|c), [d])
has length 4 and is thus better than foo(a, ((b, [d])|(c, [d])))
, which has length 5.
Is there an existing algorithm to solve this (or a similar) problem?
If not, can anyone sketch an approach?
I'm not picky about the programming language (I'm using C#, though).
The rules are:
- Parameters with the same name represent the same thing for all overloads.
a
isa
,b
isb
... - When collecting all distinct parameters over all overloads (in this case,
a, b, c, d
), every overload will adhere to this parameter order. [...]
means that the enclosed sub-expression can be omitted as a whole.(...|...|...)
means a choice of one of the sub-expressions. For readability's sake, such a sub-expression must not be empty.
To illustrate further: The (rather contrived) function bar()
bar(a, b, f, g, h, i)
bar(a, b, f, g, h)
bar(a, b, f, g)
bar(a, c, g, h, i)
bar(a, c, g, h)
bar(a, c, g)
bar(a, d, f, g, h, i)
bar(a, d, f, g, h)
bar(a, d, f, g)
bar(a, e, f, g, h, i)
bar(a, e, f, g, h)
bar(a, e, f, g)
should be represented as bar(a, (((b|d|e), f)|c), g, [h, [i]])
.