Variadic Function Library Matches
Problem statement
A function library registers functions in order. Function i has name names[i], declared parameter types parameterTypes[i], and flag isVariadic[i].
A non-variadic function matches a query only when its declared types equal the query exactly. A variadic declaration must be non-empty: every declared type before the last is a fixed prefix, and the final declared type accepts zero or more query arguments. Type tokens compare by exact case-sensitive equality.
Return the names of every matching function in registration order.
Function
findFunctionMatches(names: String[], parameterTypes: String[][], isVariadic: boolean[], queryTypes: String[]) → String[]Examples
Example 1
names = ["foo","bar","baz"]parameterTypes = [["String"],["String","Integer"],["String","Integer"]]isVariadic = [false,true,false]queryTypes = ["String"]return = ["foo","bar"]The variadic final Integer consumes zero arguments, while the fixed two-parameter function does not match.
Example 2
names = ["join","pair"]parameterTypes = [["String","String"],["String","String"]]isVariadic = [true,false]queryTypes = ["String","String","String"]return = ["join"]The final type of join repeats to consume both trailing arguments.
Example 3
names = ["sum"]parameterTypes = [["Integer"]]isVariadic = [true]queryTypes = []return = ["sum"]A declaration consisting only of its variadic type accepts an empty query.
Constraints
names.length == parameterTypes.length == isVariadic.length.0 <= names.length <= 100000.- The total number of declared and query type tokens is at most
300000. - Names and type tokens are non-empty ASCII strings of length at most
100. - Every variadic declaration contains at least one type.