SortedSet.st
changeset 2789 03a6b4291b77
child 2790 216dece3910c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SortedSet.st	Mon Aug 06 12:40:33 2012 +0200
@@ -0,0 +1,163 @@
+"
+ COPYRIGHT (c) 2012 by eXept Software AG
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+"{ Package: 'stx:libbasic2' }"
+
+OrderedSet subclass:#SortedSet
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Collections-Sequenceable'
+!
+
+!SortedSet class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 2012 by eXept Software AG
+              All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+!
+
+documentation
+"
+    I am a subclass of Set whose elements are ordered in a
+    similar fashion to SortedCollection.
+    That is, I have both Set behavior (only keeping a single instance of
+    an element) but I also remember the sort order.
+
+    I have one additional instance variable:
+
+    order <SortedCollection>        Sorted collection of values reflecting the order 
+                                    in the set. 
+
+    [author:]
+        Claus Gittinger
+
+    [see also:]
+        OrderedCollection 
+        Dictionary OrderedDictionary
+        Set Bag
+"
+!
+
+examples
+"
+                                                                    [exBegin]
+        |s|
+
+        s := SortedSet new.
+        s add:'one'.
+        s add:'two'.
+        s add:'one'.
+        s add:'two'.
+        s add:'three'.
+        s size.         
+        s do:[:each | Transcript showCR:each].         
+                                                                    [exEnd]
+
+
+                                                                    [exBegin]
+        |s|
+
+        s := SortedSet new.
+        s add:'one'.
+        s add:'two'.
+        s add:'one'.
+        s add:'two'.
+        s add:'three'.
+        s remove:'one'.
+        s size.         
+        s do:[:each | Transcript showCR:each].         
+                                                                    [exEnd]
+
+                                                                    [exBegin]
+        |s|
+
+        s := SortedSet new.
+        s add:'one'.
+        s add:'two'.
+        s add:'three'.
+        s add:'one'.
+        s add:'two'.
+        s add:'three'.
+        s size.         
+        Transcript showCR:s.         
+        s removeFirst.
+        Transcript showCR:s.         
+        s removeFirst.
+        Transcript showCR:s.         
+        s removeFirst.
+        Transcript showCR:s.         
+                                                                    [exEnd]
+"
+! !
+
+!SortedSet class methodsFor:'instance creation'!
+
+sortBlock:aBlock
+    "return a new sortedSet, whe the sort order is defined by aBlock.
+     This must be a two-argument block which returns true if its arg1 has to come before
+     its arg2 in the collection."
+
+    ^ self new setSortBlock:aBlock
+
+    "Created: / 06-08-2012 / 12:34:29 / cg"
+! !
+
+!SortedSet methodsFor:'adding & removing'!
+
+addFirst:anObject 
+    "blocked; only the sort order determines the order"
+
+    self shouldNotImplement
+
+    "Modified: / 06-08-2012 / 12:37:23 / cg"
+!
+
+addLast:anObject 
+    "blocked; only the sort order determines the order"
+
+    self shouldNotImplement
+
+    "Modified: / 06-08-2012 / 12:37:30 / cg"
+! !
+
+!SortedSet methodsFor:'initialization'!
+
+initializeOrder
+    order := SortedCollection new
+
+    "Created: / 06-08-2012 / 12:33:31 / cg"
+!
+
+setSortBlock:aBlock
+    order sortBlock:aBlock
+
+    "Created: / 06-08-2012 / 12:35:07 / cg"
+! !
+
+!SortedSet class methodsFor:'documentation'!
+
+version
+    ^ '$Header: /cvs/stx/stx/libbasic2/SortedSet.st,v 1.1 2012-08-06 10:40:33 cg Exp $'
+!
+
+version_CVS
+    ^ '$Header: /cvs/stx/stx/libbasic2/SortedSet.st,v 1.1 2012-08-06 10:40:33 cg Exp $'
+! !