[Glass] Can't we use indexes for sorting too?

Mariano Martinez Peck via Glass glass at lists.gemtalksystems.com
Wed Aug 9 07:21:09 PDT 2017


On Mon, Aug 7, 2017 at 10:15 PM, Dale Henrichs via Glass <
glass at lists.gemtalksystems.com> wrote:

> Mariano,
>
> Here's a doit that illustrates 3 different ways to get at sorted dates
> from an indexed collection. For the query I happen to be using a date that
> predates al of the dates in the collection, but if you had a specific range
> in mind the #readStream or #do: methods allow you to access the elements in
> sorted order ... #sortAscending: produces an array with all of the elements
> sorted ...
>
>
>       | nsc random maxYear query ar1 ar3 stream ar2 |
>       nsc := IdentityBag new.
>       random := HostRandom new.
>       GsIndexSpec new
>         equalityIndex: '' lastElementClass: Date;
>         createIndexesOn: nsc.
>       1 to: 100 do: [ :index |
>         nsc
>           add:
>             (Date
>               newDay: (random integerBetween: 1 and: 365)
>               year: (random integerBetween: 2000 and: 2017)) ].
>       query := (GsQuery fromString: 'each > x' on: nsc)
>         bind: 'x'
>         to: (Date newDay: 1 year: 1999).
>       "traverse query results using stream ... allows for early return
> without evaluating all query results"
>       ar1 := {}.
>       stream := query readStream.
>       [ stream atEnd ] whileFalse: [ ar1 add: stream next ].
>      "traverse query results using do: ... allows for early return without
> evaluating all query results"
>       ar2 := {}.
>       query do: [ :date | ar2 add: date ].
>       "create a sorted Array on nsc using sortAscending:. no early return."
>       ar3 := nsc sortAscending: ''.
>       {ar1.
>       ar2.
>       ar3}
>
>

Thanks Dale, that snippet was of great help as I wasn't aware of any of
them.
This is very cool. Good job on improving all index support!!!





> On 8/4/17 12:07 PM, Mariano Martinez Peck via Glass wrote:
>
> Say I have an OrderedCollection with instances of XXX that has a field
> "date" and I create a a equality index on it. So... ok, I can do the
>
> select: { :entry | entry.date = aDate }
>
> But... I would love to take advantage of the index and also do this:
>
> sorted: {:a :b | a.date <= b.date }
>
> Is there a way to do that?
>
> Thanks in advance
>
>
>
> Mariano
> http://marianopeck.wordpress.com
>
>
> _______________________________________________
> Glass mailing listGlass at lists.gemtalksystems.comhttp://lists.gemtalksystems.com/mailman/listinfo/glass
>
>
>
> _______________________________________________
> Glass mailing list
> Glass at lists.gemtalksystems.com
> http://lists.gemtalksystems.com/mailman/listinfo/glass
>
>


-- 
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20170809/3ff60391/attachment-0001.html>


More information about the Glass mailing list