Sorted dict 1

Pull request for SortedDict and BalancedTree23 taking into account Kevin Squire's feedback from the past 12 days.
Kevin,

Just to make sure I understand this suggestion: there are currently five 
iterations in SortedDict, three of which iterate over (k,v,t) (and hence 
over (k,v) if the user so desires.)  Is your suggestion that each one 
should have a 'tokens' version (for a total of 10 iterations)?  In other 
words, if m is a sorted dict, the ten iterations would be:

for (k,v) in m
for (k,v) in starttoken:endtoken
for (k,v) in excludelast(starttoken:endtoken)
for k in keys(m)
for v in values(m)
for (k,v,t) in tokens(m)
for (k,v,t) in tokens(starttoken:endtoken)
for (k,v,t) in tokens(excludelast(starttoken:endtoken))
for (k,t) in tokens(keys(m))
for (k,t) in tokens(values(m))

Actually, to be parallel with 'enumerate', the 'tokens' iterations should 
return tuples like this: (t,(k,v)), (t,k) and (t,v).

Thanks,
Steve







On Tue, 23 Sep 2014, Kevin Squire wrote:

> 
> In src/sortedDict.jl:
> 
> > +IncludeLast{K, D, Ord <: Ordering}(m1::SortedDict{K, D, Ord}, first1::Int, last1::Int) = 
> > +            IncludeLast{K,D,Ord}(m1, first1, last1)
> > +
> > +typealias SDIterableTypes Union(SortedDict,ExcludeLast,IncludeLast)
> > +
> > +done(::SDIterableTypes, state::SDIterationState) = state.next == state.final
> > +
> > +function next(::SDIterableTypes, state::SDIterationState)
> > +    m = state.m
> > +    sn = state.next
> > +    if sn < 3 || !in(sn, m.bt.useddatacells)
> > +        throw(BoundsError())
> > +    end
> > +    return (m.bt.data[sn].k, m.bt.data[sn].d, SDToken(sn, m)),
> > +           SDIterationState(m, nextloc0(m.bt, sn), state.final)
> > +end
> 
> While I appreciate the effort you've gone through to make one iterator do multiple things, I
> think I'd like to see this broken up into two different iterators.
> 
> The default iterator would simply return (key, value) tuples, and not tokens at all.
> 
> For tokens, I would create an iterator that could be used something like
> 
> for token in tokens(sorted_dict)
>    # ... do something with the token
> end
> 
> or
> 
> for (k,v,token) in tokens(sorted_dict)
>    # ... do something with k, v, and token
> end
> 
> This would also allow tokens to be more easily generalized and used for other associative types.
> 
> (I like tokens, but it could be token_iter or some such.)
> 
> —
> Reply to this email directly or view it onGitHub.[7881863__eyJzY29wZSI6Ik5ld3NpZXM6QmVhY29uIiwiZXhwaXJlcyI6MTcyNzA5MzgwMSwiZGF0YSI6eyJpZCI
> 6NDE3MzQ5Mjl9fQ==--7545819e52f4d907c86558ece5ea73ac927422a9.gif]
> 
> 
>