class: IdentitySet
authorStefan Vogel <sv@exept.de>
Tue, 15 Jan 2013 17:33:59 +0100
changeset 14655 1d2b0650e086
parent 14654 32c189acecb6
child 14656 f5cab05e380f
class: IdentitySet added: #collisionsFor:
IdentitySet.st
--- a/IdentitySet.st	Tue Jan 15 17:33:48 2013 +0100
+++ b/IdentitySet.st	Tue Jan 15 17:33:59 2013 +0100
@@ -68,6 +68,31 @@
 
 !IdentitySet methodsFor:'private'!
 
+collisionsFor:key
+    "Return the number of searches - 1 required for key"
+
+    |index  "{ Class:SmallInteger }"
+     length "{ Class:SmallInteger }" startIndex probe count|
+
+    length := keyArray basicSize.
+    startIndex := index := self initialIndexForKey:key.
+
+    count := 0.
+    [true] whileTrue:[
+        probe := keyArray basicAt:index.
+        (probe notNil and:[key == probe]) ifTrue:[^ count].
+        (self slotIsEmpty:probe) ifTrue:[self error:'non existing key'].
+
+        index == length ifTrue:[
+            index := 1.
+        ] ifFalse:[
+            index := index + 1.
+        ].
+        count := count + 1.
+        index == startIndex ifTrue:[self error:'non existing key'].
+    ]
+!
+
 find:key ifAbsent:aBlock
     "Look for the key in the receiver.  If it is found, return
      the index of the slot containing the key, otherwise
@@ -217,5 +242,6 @@
 !IdentitySet class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/IdentitySet.st,v 1.33 2012-02-22 12:54:31 stefan Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/IdentitySet.st,v 1.34 2013-01-15 16:33:59 stefan Exp $'
 ! !
+