JuliaLang/julia — pull request #1190 by HarlanH (2012-08-20 16:13:43+00:00)
Title: RFC: NamedIndex and NamedVector types

These are relatively simple data types that are useful for data structures that are worked with in the REPL. NamedIndex is a mapping from either names (strings) or integer indexes to integer indexes. NamedVector wraps that in a type that also includes an arbitrary vector. These structures also include grouped names, which refer to groups of other names, and can be used transparently. The majority of this code is by Tom Short @tshort. NamedIndex is used by JuliaData.

NamedVector is missing most functionality but the basics, but thought I'd get comments before writing that code.

Simple example of NamedVector (see also the test suite):

```julia
julia> nams = ["one", "two", "three", "four"]
4-element ASCIIString Array:
"one"
"two"
"three"
"four"

julia> vals = [11, 22, 33, 44]
4-element Int64 Array:
11
22
33
44

julia> t1 = NamedVector() # need constructors other than the default empty constructor!

julia> for i = 1:4
t1[nams[i]] = vals[i]
end

julia> print(t1)
1, one: 11
2, two: 22
3, three: 33
4, four: 44

julia> t1["one"]
11

julia> t1[2]
22

julia> t1[1:3]
3-element Any Array:
11
22
33

julia> t1[["four", "two"]]
2-element Any Array:
44
22
```