dpar icon indicating copy to clipboard operation
dpar copied to clipboard

Replace various lookups by one data structure

Open danieldk opened this issue 6 years ago • 2 comments

There is a lot of overlap between the transition-specific lookup and feature table lookup. This can be factored out to one class that replaces Numberer.

Maybe this should be a separate crate, because it is generally useful.

danieldk avatar Oct 31 '18 14:10 danieldk

This turns out to be difficult to do elegantly generically. The problem is that in lookup methods, you want to take e.g. &str rather than &String (since it doesn't require the construction of a String). However, one then needs type parameters on lookup methods, such as:

fn lookup<Q: ?Sized>(&self, q: &Q) -> usize where T: Borrow<Q>

However, generic methods are not object safe. Since I use both boxed transition lookups and boxed feature lookups, this does not compile. And I am not sure whether I want to give up dynamic polymorphism for lookups and transitions.

An alternative that I am now thinking of is specifying both the owned and borrowed types as type parameters (note that we cannot use Borrow directly, since some times can be borrowed as multiple types) to avoid generic methods.

@sebpuetz

danieldk avatar Nov 08 '18 10:11 danieldk

I have found a more elegant solution, more later ;).

danieldk avatar Nov 08 '18 12:11 danieldk