The Trunk: Collections-mt.600.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Trunk: Collections-mt.600.mcz

commits-2
Marcel Taeumel uploaded a new version of Collections to project The Trunk:
http://source.squeak.org/trunk/Collections-mt.600.mcz

==================== Summary ====================

Name: Collections-mt.600
Author: mt
Time: 19 January 2015, 10:14:01.368 am
UUID: 32764222-c0d1-9943-a0ae-ac6a5684f053
Ancestors: Collections-mt.599

Copy ranges of elements in OrderedDictionary.

=============== Diff against Collections-mt.599 ===============

Item was added:
+ ----- Method: OrderedDictionary>>copyFrom:to: (in category 'copying') -----
+ copyFrom: startIndex to: endIndex
+ "Answer a copy of the receiver that contains elements from position
+ startIndex to endIndex."
+
+ self fixEmptySlots.
+ ^ self shallowCopy postCopyFrom: startIndex to: endIndex!

Item was added:
+ ----- Method: OrderedDictionary>>first: (in category 'accessing') -----
+ first: n
+ "Answer the first n elements of the receiver.
+ Raise an error if there are not enough elements."
+
+ ^ self copyFrom: 1 to: n!

Item was changed:
  ----- Method: OrderedDictionary>>isSorted (in category 'sorting') -----
  isSorted
+ "Return true if the receiver's keys are sorted by #<=."
- "Return true if the receiver is sorted by #<=."
 
  self fixEmptySlots.
  ^ order
  isSortedBetween: 1
  and: lastIndex!

Item was added:
+ ----- Method: OrderedDictionary>>last: (in category 'accessing') -----
+ last: n
+ "Answer the last n elements of the receiver.  
+ Raise an error if there are not enough elements."
+
+ | size |
+ size := self size.
+ ^ self copyFrom: size - n + 1 to: size!

Item was added:
+ ----- Method: OrderedDictionary>>postCopyFrom:to: (in category 'copying') -----
+ postCopyFrom: startIndex to: endIndex
+ "Adapted from SequenceableCollection and OrderedCollection."
+
+ | oldOrder newArraySize newOrderSize |
+ newArraySize := self class goodPrimeAtLeast: ((endIndex - startIndex + 1) * (5/4) "add 25%") ceiling.
+ newOrderSize := (newArraySize * (3/4)) ceiling. "remove 25%"
+
+ oldOrder := order.
+ order := self class arrayType new: newOrderSize.
+ array := self class arrayType new: newArraySize.
+
+ startIndex to: endIndex do: [:index | | element |
+ element := (oldOrder at: index) copy.
+ order at: index - startIndex + 1 put: element.
+ array at: (self scanFor: element key) put: element].
+
+ lastIndex := endIndex - startIndex + 1.
+ tally := lastIndex.
+
+
+ !