>From 0a03265376b7ded2e1c47cb43ad7f44a2c6f9987 Mon Sep 17 00:00:00 2001
From: Gwenael Casaccio
Date: Mon, 27 Jun 2011 16:32:56 +0200
Subject: [PATCH 2/3] move beConsistent
---
kernel/OrderColl.st | 10 ---------
kernel/SortCollect.st | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 10 deletions(-)
diff --git a/kernel/OrderColl.st b/kernel/OrderColl.st
index 0adfddc..63154dc 100644
--- a/kernel/OrderColl.st
+++ b/kernel/OrderColl.st
@@ -61,7 +61,6 @@ on content (such as add:after:)'>
| index |
- self beConsistent.
index := firstIndex.
[ index <= lastIndex ] whileTrue: [
aBlock value: (self basicAt: index).
@@ -72,7 +71,6 @@ on content (such as add:after:)'>
"Answer the first item of the receiver"
- self beConsistent.
^lastIndex >= firstIndex
ifTrue: [self basicAt: firstIndex]
ifFalse: [SystemExceptions.IndexOutOfRange signalOn: self withIndex: 1]
@@ -82,7 +80,6 @@ on content (such as add:after:)'>
"Answer the last item of the receiver"
- self beConsistent.
^lastIndex >= firstIndex
ifTrue: [self basicAt: lastIndex]
ifFalse: [SystemExceptions.IndexOutOfRange signalOn: self withIndex: 0]
@@ -93,7 +90,6 @@ on content (such as add:after:)'>
| index |
- self beConsistent.
index := anIndex + firstIndex - 1.
^(index >= firstIndex and: [index <= lastIndex])
ifTrue: [self basicAt: index]
@@ -105,7 +101,6 @@ on content (such as add:after:)'>
| index |
- self beConsistent.
index := anIndex + firstIndex - 1.
(index >= firstIndex and: [index <= lastIndex])
ifTrue: [^self basicAt: index put: anObject]
@@ -292,7 +287,6 @@ on content (such as add:after:)'>
| answer |
- self beConsistent.
lastIndex < firstIndex
ifTrue: [^SystemExceptions.EmptyCollection signalOn: self].
answer := self basicAt: firstIndex. "Get the element"
@@ -300,7 +294,6 @@ on content (such as add:after:)'>
lastIndex = firstIndex
ifTrue: [self initIndices]
ifFalse: [firstIndex := firstIndex + 1].
- self size < self shrinkSize ifTrue: [self shrink].
^answer
]
@@ -310,7 +303,6 @@ on content (such as add:after:)'>
| answer |
- self beConsistent.
lastIndex < firstIndex
ifTrue: [^SystemExceptions.EmptyCollection signalOn: self].
answer := self basicAt: lastIndex. "Get the element"
@@ -318,7 +310,6 @@ on content (such as add:after:)'>
lastIndex = firstIndex
ifTrue: [self initIndices]
ifFalse: [lastIndex := lastIndex - 1].
- self size < self shrinkSize ifTrue: [self shrink].
^answer
]
@@ -370,7 +361,6 @@ on content (such as add:after:)'>
| answer |
- self beConsistent.
lastIndex < firstIndex
ifTrue: [^SystemExceptions.EmptyCollection signalOn: self].
(anIndex < 1 or: [anIndex > self size])
diff --git a/kernel/SortCollect.st b/kernel/SortCollect.st
index fb5c13e..5e33599 100644
--- a/kernel/SortCollect.st
+++ b/kernel/SortCollect.st
@@ -113,6 +113,56 @@ above criteria -- actually any object which responds to #value:value:.'>
self shouldNotImplement
]
+ first [
+ "Answer the first item of the receiver"
+
+
+ self beConsistent.
+ ^ super first
+ ]
+
+ last [
+ "Answer the last item of the receiver"
+
+
+ self beConsistent.
+ ^ super last
+ ]
+
+ at: anIndex [
+ "Answer the anIndex-th item of the receiver"
+
+
+ self beConsistent.
+ ^ super at: anIndex
+ ]
+
+ do: aBlock [
+ "Evaluate aBlock for all the elements in the collection"
+
+
+ self beConsistent.
+ super do: aBlock
+ ]
+
+ removeFirst [
+ "Remove an object from the start of the receiver. Fail if the receiver
+ is empty"
+
+
+ self beConsistent.
+ ^ super removeFirst
+ ]
+
+ removeLast [
+ "Remove an object from the end of the receiver. Fail if the receiver
+ is empty"
+
+
+ self beConsistent.
+ ^ super removeLast
+ ]
+
last [
"Answer the last item of the receiver"
@@ -282,6 +332,7 @@ above criteria -- actually any object which responds to #value:value:.'>
| answer |
+ self beConsistent.
answer := super basicRemoveAtIndex: anIndex.
"Ensure the invariant that lastOrdered <= lastIndex, otherwise
--
1.7.4.1