Hey,
I want to have a collection that's sortable but not always sorted. I've been using (essentially): mySortedCollection := myOrderedCollection asSortedCollection. myOrderedCollection := mySortedCollection asOrderedCollection. Or just: s := (s asSortedCollection) asOrderedCollection. OK? (It seems fine to me, but part of my mind still sticks thinks "Gee, that's a lot of overhead.") I really just want to write: s sort. I see the tools are there for SortedCollection but they're not meant to be used, I think. ===Blake=== _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hi Blake,
I'm not sure it is really less overhead, but it is possible for you to change a sort block on a sortedCollection. Any time you change the sort block it resorts the collection. So you could just turn off the sort. Try this: SortedCollection with: 1 with: 2 with: 3. Then inspect it. On the inspector change the sort block. self sortBlock: [:a :b | true]. This basically says that each item in order between a and b, a always is inserted before b. So now you can do self add: 5. self add: 4. And notice that the collection now holds: 1 2 3 5 4 To sort the collection again just put back an appropriate sortblock like self sortBlock: [:a :b | a < b]. (a goes before b if a is less then b) Once you add this sortBlock back you have a sorted collection: 1 2 3 4 5. Or just use asOrderedCollection which I think is a very nice way to solve your problem. If you are try to filter results there are other ways to make this work. You could build a filter object that applies filters as you add them to your original collection and then outputs the results. This way your original unsorted collection stays in one collection and your output changes as you add filters. Filter ------------ input -> OrderedCollection of data output -> Output collection for dispay filters -> OrderedCollection of FilterObjects ------------ >>applyFilters "run through collection of filters to set the output collection" So now you can see that if there are no filters you just get your original unsorted collection back. Otherwise you get your data changed as you need it, by way of sorting, selecting, or whatever. Does that help? Ron Teitelbaum > -----Original Message----- > From: Blake > > > Hey, > > I want to have a collection that's sortable but not always sorted. > I've > been using (essentially): > > mySortedCollection := myOrderedCollection asSortedCollection. > myOrderedCollection := mySortedCollection asOrderedCollection. > > Or just: > > s := (s asSortedCollection) asOrderedCollection. > > OK? (It seems fine to me, but part of my mind still sticks thinks > "Gee, > that's a lot of overhead.") I really just want to write: > > s sort. > > I see the tools are there for SortedCollection but they're not meant > to > be used, I think. > > ===Blake=== > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
> Does that help?
Yep. Thanks. And thanks for the tangential comments as well. (It all goes into the hopper.) _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Free forum by Nabble | Edit this page |