Dear Julia colleagues,
Earlier I asked whether there is a datatype similar to "map<K,D>" from C++,
and nobody answered, so I decided as my first nontrivial Julia program to
write such a type. This is an associative array (i.e., a dictionary), with
the added property that the keys have a sort-order, and it is possible to
loop over the items in the array in this order. I am using a 2-3 tree as
the implementation. My main data structure looks like this:
type Map{K,D}
...
function Map{K,D}()
....
end
end
But I am stuck right at the outset with two very basic Julia questions.
First, what is the syntax for a user of my datatype to declare a variable
to be an empty map of a certain type? In other words, suppose the user
wants a map from strings to strings:
function test1()
m1 = Map{ASCIIString, ASCIIString}()
m1["hello"] = "jello"
end
This gave the error: ERROR: no method Map{ASCIIString, ASCIIString}().
What is the right syntax to invoke the default constructor for an empty
map? I couldn't figure this out from the manual; in the manual, the
constructors either take arguments or else they are constructors for
built-ins (like arrays) that have a special syntax like a = Int[].
Second, at various points in the code, I need to use a default or blank
instance of either K (the key type) or D (the datatype). In other words, I
need to initialize an array element whose type is a composite type that has
some K or D fields; these need to be initialized to some arbitrary K or D
value that won't ever be used. What is the proper syntax to initialize a
field k to have a value of type K (where K is a parameter type in my code),
where the value doesn't matter (can be any default).
Thanks,
Steve Vavasis