3 ms·
This sounds fairly doable. Rust pseudocode: ``` // Traits for the operations you want to perform... trait Map<K,V> { ... operations ... } trait List<K,V> { .
by eximius 5y ago
This sounds fairly doable. Rust pseudocode:
```
// Traits for the operations you want to perform...
trait Map<K,V> {
... operations ...
}
trait List<K,V> {
... operations ...
}
// Functions which dispatch for your data/operation distribution
fn gimme_map<K, V>(data: DataDistribution, op: OperationDistribution) -> impl Map<K, V> { .. }
enum DataDistribution {
...
}
enum OperationDistribution {
...
}
```
- zanecodes 5y agoIdeally the decision would occur at compile time rather than runtime, to eliminate the dispatch overhead, so I think it would be likely to require macros, constexprs, or whatever compile-time execution mechanism is available in your language of choice