help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] Re: OrderedSet (was Re: environment/shared pool search


From: Paolo Bonzini
Subject: [Help-smalltalk] Re: OrderedSet (was Re: environment/shared pool search order?)
Date: Mon, 16 Apr 2007 17:58:25 +0200
User-agent: Thunderbird 1.5.0.10 (Macintosh/20070221)


The difference is that the attached follows 1 and supports all of
OrderedCollection's operations (forgive the usingSet: nonsense that is
just there until I come up with something better).  After writing them,
I thought that maybe they should not be supported at all (except for the
index = collection size case).

No, I think that's correct if you want to subclass OrderedCollection. My simpler approach would have led to a subclass of Set without the special operations -- but your patch is the best thing to do.

I'm using your class with this tiny patch to remove the "usingSet: nonsense" (actually replacing with a "on: nonsense").

The end of this message also includes the tiny patch to use the OrderedSet. For now I'm including OrderedSet.st only in the Parser package, not in the core.

--- compiler/OrderedSet.sc.st    2007-04-16 17:49:11.000000000 +0200
+++ compiler/OrderedSet.st       2007-04-16 17:52:33.000000000 +0200
@@ -59,31 +59,23 @@


 !OrderedSet class methodsFor: 'instance creation'!

+identityNew: anInteger
+    "Answer an OrderedSet of size anInteger which uses #== to compare its
+     elements."
+    ^self on: (IdentitySet new: anInteger)!
+
 new: anInteger
     "Answer an OrderedSet of size anInteger."
-    ^(super new: anInteger)
-       unorderedSet: (self setFactory new: anInteger);
-       yourself
-!
-
-new: anInteger usingSet: anEmptySet
-    "Answer an OrderedSet of size anInteger, that uses anEmptySet as
-     an unordered set to maintain my set-property."
-    ^(super new: anInteger)
-       unorderedSet: anEmptySet;
-       yourself
-!
+    ^self on: (Set new: anInteger)!

-usingSet: anEmptySet
+on: anEmptySet
     "Answer an OrderedSet that uses anEmptySet as an unordered set to
      maintain my set-property."
-    ^self new unorderedSet: anEmptySet; yourself
-!
-
-setFactory
-    "Answer a class (<Set factory>) that can create a default
-     unordered Set for new instances."
-    ^Set
+    anEmptySet isEmpty
+       ifFalse: [ self error: 'expected empty collection' ].
+    ^(super new: anEmptySet basicSize)
+       unorderedSet: anEmptySet;
+       yourself
 ! !


 !OrderedSet methodsFor: 'accessing'!
@@ -114,9 +106,7 @@

 copyEmpty: newSize
     "Answer an empty copy of the receiver."
-    ^(self species basicNew: newSize)
-       unorderedSet: (unorderedSet copyEmpty: newSize);
-       yourself
+    ^self species on: (unorderedSet copyEmpty: newSize)
 ! !


 !OrderedSet methodsFor: 'searching for elements'!
--- compiler/STSymTable.sc.st
+++ compiler/STSymTable.st
@@ -364,7 +364,7 @@ init
     instVars := Dictionary new: 7.
     scopeVariables := OrderedCollection new: 5.
     scopes := OrderedCollection new: 5.
-    pools := IdentitySet new: 7.
+    pools := OrderedSet identityNew: 7.
     tempCount := 0.
 !




reply via email to

[Prev in Thread] Current Thread [Next in Thread]