TreeSet.st
changeset 3712 7f02da6caef2
parent 3011 ff9d57003145
child 4122 d868c6e94d96
equal deleted inserted replaced
3711:2f73ab944d25 3712:7f02da6caef2
     1 "{ Package: 'stx:libbasic2' }"
     1 "{ Package: 'stx:libbasic2' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
     2 
     4 
     3 Collection subclass:#TreeSet
     5 Collection subclass:#TreeSet
     4 	instanceVariableNames:'tree sortKey'
     6 	instanceVariableNames:'tree sortKey'
     5 	classVariableNames:''
     7 	classVariableNames:''
     6 	poolDictionaries:''
     8 	poolDictionaries:''
   101 			[:key :left :right |
   103 			[:key :left :right |
   102 			s nextPutAll: (left intersection: right)]]
   104 			s nextPutAll: (left intersection: right)]]
   103 !
   105 !
   104 
   106 
   105 remove: anObject
   107 remove: anObject
   106 	| key bucket |
   108     "remove all occurrences of anObject
   107 	key _ self keyForValue: anObject.
   109      Warning:
   108 	bucket _ tree at: key ifAbsent: [^ self].
   110         This is inconsistent with the inherited collection>>remove:,
   109 	(self bucket: bucket includes: anObject) ifTrue:
   111         which only remove the first occurrence.
   110 		[bucket _ bucket reject: [:ea | self value: anObject matches: ea].
   112         Should this be fixed?"
   111 		bucket isEmpty
   113     
   112 			ifTrue: [tree removeKey: key]
   114     | key bucket |
   113 			ifFalse: [tree at: key put: bucket]]
   115     
       
   116     key := self keyForValue: anObject.
       
   117     bucket := tree at: key ifAbsent: [^ self].
       
   118     (self bucket: bucket includes: anObject) ifTrue:[
       
   119         "/ cg: wrong code here: removes all, not only the first match
       
   120         bucket := bucket reject: [:ea | self value: anObject matches: ea].
       
   121         bucket isEmpty
       
   122                 ifTrue: [tree removeKey: key]
       
   123                 ifFalse: [tree at: key put: bucket]
       
   124     ]
   114 !
   125 !
   115 
   126 
   116 sortSelector
   127 sortSelector
   117 	^ sortKey
   128 	^ sortKey
   118 ! !
   129 ! !
   126 ! !
   137 ! !
   127 
   138 
   128 !TreeSet class methodsFor:'documentation'!
   139 !TreeSet class methodsFor:'documentation'!
   129 
   140 
   130 version_CVS
   141 version_CVS
   131     ^ '$Header: /cvs/stx/stx/libbasic2/TreeSet.st,v 1.3 2013-06-25 11:22:55 cg Exp $'
   142     ^ '$Header$'
   132 ! !
   143 ! !
   133 
   144