Hi Steve, I saw your original post, too, and started to respond, but got distracted and it fell off my radar. Sorry about that.
Mayor gave good answers to your questions. To clarify one point, I'm in the process of adding functions for sorting OrderedDicts, which are normally in insertion order, as you surmised. The sorting will happen after the fact--any additional items added to the dictionary will be added to the end. Julia does not currently have a dictionary which maintains sort order. One based on red-black trees was started and submitted as a PR to DataStructures.jl, but needs more review and more work. As an aside, DataStructures.jl does contain a DefaultDict and DefaultOrderedDict, which give (and set) default values for keys not in the dictionary whenever they are accessed. You seemed to be interested in having this as well. If you come up with a good RB tree dictionary implementation, please consider contributing it! It might take a little work to wrangle it into the Julia dictionary interface if you don't do so up front, but it shouldn't be too bad. (I should probably go back and review the RB-tree dictionary PR that's there now.) Feel free to ask any more questions here. Cheers, Kevin On Wednesday, June 18, 2014, <[email protected]> wrote: > Mauro, > > Thanks for taking the time to respond. First, with regard to the existing > Dict in Julia, just to be sure I understand, the order of the keys is not > the order given by the '<' operation acting on the keys but is rather the > order in which they were inserted, is that correct? > > With regard to the inner and outer constructor both needed, can you give > me a reference? I have read the manual section you mentioned; the > constructor for the Point example in the manual takes arguments and so it > doesn't seem to cover my case. > > With regard to default key values, I'm still not getting it, so let me ask > the question in more detail. A data node in my structure looks like this: > > immutable TreeLeaf{K,D} > k::K > d::D > parent::Int > end > > To initialize a map, I need to create an Array{TreeLeaf{K,D},2). The two > initial entries are markers for the start and end of the data. The k and d > fields of these two nodes don't matter, but the parent values do matter. > So apparently I need something like this: > > data = Array{TreeLeaf{K,D}, 2} > data[1] = TreeLeaf(undefinedK, undefinedD, 1) > data[2] = TreeLeaf(undefinedK, undefinedD, 1) > > What should I put for 'undefinedK' and 'undefinedD' here? After seeing > your post, I tried this: u = Array{K,1}, and then I used u[1] for > undefinedK, but this gave an error ("access to undefined reference"). > There are some other places in my code where I have a similar problem. > > With regard to Kevin's work on a sorted dict, maybe I should wait for him > to finish? Is there an estimated completion time? > > Thanks, > Steve Vavasis > >
