language: added CompactIndex

This function provides an alternative to complex indexes as used in
package display, for example. Many of the upcoming packages will need
to use something like this, so this will be useful and simplify
implementations.

The upcoming localization code will also likely need to do a lot of
table lookups based on tags. CompactIndex allows implementations to
easily associate data based on a simple table lookup. Standardizing
on the index among the packages also allows caching it.

Maybe this should have been internal, but as the code and data are
very interwoven with the types in the language package, I don't see
a trivial way of doing this. The construct may be useful to users
that want to implement their own formatters.

Change-Id: I0c62e825be09d19b85e684fa114aa2cb6bec5003
Reviewed-on: https://go-review.googlesource.com/14438
Reviewed-by: Nigel Tao <nigeltao@golang.org>
4 files changed