[Glass] There is really no way to have an ordered/sorted collection together with indexes?

Paul DeBruicker via Glass glass at lists.gemtalksystems.com
Mon Aug 7 16:25:18 PDT 2017


I think your use case is what 

http://smalltalkhub.com/#!/~emaringolo/History


is designed for.  I haven't implemented "binary search for nearest earlier
than X date/time" in it yet though





GLASS mailing list wrote
> On Mon, Aug 7, 2017 at 5:04 PM, Richard Sargent via Glass <

> glass at .gemtalksystems

>> wrote:
> 
>> GLASS mailing list wrote
>> > Hi guys,
>> >
>> > I am storing huge lists of "prices". For this, it really helps me to
>> store
>> > things ordered (by date)...either in an SequenceableCollection or a
>> > SortedCollection. On the other hand, I do want to use indexes to
>> speedup
>> > my
>> > query to find price for a given date (equality index).
>> >
>> > But I have found no way to have them both. The only workaround I found
>> is
>> > to keep 2 collections for each of these collections, one
>> sorted/ordered,
>> > and the other one an unordered one for querying via index. But this is
>> a
>> > pain from "developing" point of view, as well as for unnecessary
>> > repository
>> > growth.
>> >
>> > Am I missing something?
>>
>> Mariano, have you read chapter 7 in the GemStone/S 64 Programming Guide?
>> It's all about indexing.
>>
>> It looks like you could define a "range" query over the unordered
>> collection
>> to get the sorted sequence needed to traverse all the prices in date
>> order.
>> The index would be on the date and the range query would be from some
>> "least
>> date" through some "greatest date". You would then use the streaming
>> results
>> or the #do: message I think) to iterate over the query result in date
>> order.
>> There is a section in chapter 7.2 discussing result order.
>>
>>
>>
> Hi Richard,
> 
> Thanks for such a pointer. And no, I wasn't aware of that kind of range
> query. I will read it as soon as I am back or tomorrow first thing in the
> morning. In the meanwhile, I will quickly answer your below question.
> 
> 
>> It might be helpful to discuss the use cases for the two collections.
>> When
>> would you iterate over all the dates versus when would you search for
>> specific dates or ranges of dates?
>>
>>
> I need to support 2 kinds of getting a price from a security:
> 
> 1) Get the price for given date X and if not found, answer nil.
> 2) Get the price for a given date X but it it wasn't found, find the
> closest (but older) one. Kind of "please gave me the latest price you can
> for this date"
> 
> 1) can simply call 2) and check if the date answer is the same as the
> original. However, I want 1) to be as fastest as possible, meaning I may
> not want to use 2) directly.  So far, I was trying this kind of code which
> obviously doesn't work because I cannot have collection both sorted and
> with index, but this was the idea anyway:
> 
> prices := self storageDict at: securityUniqueId ifAbsent: [ nil ].
> (prices notNil and: [ prices notEmpty ]) ifTrue: [
> onOrBeforeMatching
> ifTrue: [
> | exactPrice closest |
> exactPrice := prices detect: (DpDatabaseQueryClosureBuilder current
> selectClosurePriceRecordByDate: dateToCompare) ifNone: [ nil ].
> exactPrice
> ifNil: [
> closest := prices first.
>                                                 "we know prices are
> sorted.."
> prices do: [ :each |
> (each date > dateToCompare) ifTrue: [
> ^ (closest date <= dateToCompare) ifTrue: [ closest ] ifFalse: [ nil ]
> ].
> closest := each.
> ].
> ^ (closest date <= dateToCompare) ifTrue: [ closest ] ifFalse: [ nil ].
> ]
> ifNotNil: [ ^ exactPrice ]
> ]
> ifFalse: [
> ^ prices detect: (DpDatabaseQueryClosureBuilder current
> selectClosurePriceRecordByDate: dateToCompare) ifNone: [ nil ].
> ]
> ].
> ^ nil
> 
> 
> 
> DpDatabaseQueryClosureBuilder  answers those magic search block for the
> indexes....
> The boolean onOrBeforeMatching is the one that defines either behavior 1)
> or 2).
> My idea was simple. For 1) use the query for the date index. For 2) use
> also same query and only if it answers nothing, then iterate collection.
> Sure, I can replace that iteration with a binary search too. But again,
> all
> this doesn't work ...
> 
> 
> Hope this helps clarifying my questions...
> 
> Thanks a lot in advance,
> 
> 
> 
>>
>> > Thanks in advance,
>> >
>> > --
>> > Mariano
>> > http://marianopeck.wordpress.com
>> >
>> > _______________________________________________
>> > Glass mailing list
>>
>> > Glass at .gemtalksystems
>>
>> > http://lists.gemtalksystems.com/mailman/listinfo/glass
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://forum.world.st/There-
>> is-really-no-way-to-have-an-ordered-sorted-collection-
>> together-with-indexes-tp4959121p4959135.html
>> Sent from the GLASS mailing list archive at Nabble.com.
>> _______________________________________________
>> Glass mailing list
>> 

> Glass at .gemtalksystems

>> http://lists.gemtalksystems.com/mailman/listinfo/glass
>>
> 
> 
> 
> -- 
> Mariano
> http://marianopeck.wordpress.com
> 
> _______________________________________________
> Glass mailing list

> Glass at .gemtalksystems

> http://lists.gemtalksystems.com/mailman/listinfo/glass





--
View this message in context: http://forum.world.st/There-is-really-no-way-to-have-an-ordered-sorted-collection-together-with-indexes-tp4959121p4959152.html
Sent from the GLASS mailing list archive at Nabble.com.


More information about the Glass mailing list