855 "/ ]. |
856 "/ ]. |
856 |
857 |
857 startIndex := index := self initialIndexForKey:key. |
858 startIndex := index := self initialIndexForKey:key. |
858 |
859 |
859 [ |
860 [ |
860 probe := (keyArray basicAt:index). |
861 probe := keyArray basicAt:index. |
861 (probe notNil and:[probe ~~ DeletedEntry and:[key = probe]]) ifTrue:[^ index]. |
862 probe isNil ifTrue:[^ aBlock value]. |
862 (self slotIsEmpty:probe) ifTrue:[^ aBlock value]. |
863 (probe ~~ DeletedEntry and:[key = probe]) ifTrue:[^ index]. |
863 |
864 |
864 index == length ifTrue:[ |
865 index == length ifTrue:[ |
865 index := 1 |
866 index := 1 |
866 ] ifFalse:[ |
867 ] ifFalse:[ |
867 index := index + 1 |
868 index := index + 1 |
881 ! |
882 ! |
882 |
883 |
883 findKeyOrNil:key |
884 findKeyOrNil:key |
884 "Look for the key in the receiver. |
885 "Look for the key in the receiver. |
885 If it is found, return the index of the first unused slot. |
886 If it is found, return the index of the first unused slot. |
886 Grow the receiver, if key was not found, and no unused slots were present" |
887 Grow the receiver, if key was not found, and no unused slots were present |
|
888 |
|
889 Warning: an empty slot MUST be filled by the sender - it is only to be sent |
|
890 by at:put: / add: - like methods." |
887 |
891 |
888 |index "{ Class:SmallInteger }" |
892 |index "{ Class:SmallInteger }" |
889 length "{ Class:SmallInteger }" |
893 length "{ Class:SmallInteger }" |
890 startIndex probe |
894 startIndex probe |
891 delIndex| |
895 delIndex "{ Class:SmallInteger }"| |
|
896 |
|
897 delIndex := 0. |
892 |
898 |
893 length := keyArray basicSize. |
899 length := keyArray basicSize. |
894 startIndex := index := self initialIndexForKey:key. |
900 startIndex := index := self initialIndexForKey:key. |
895 |
901 |
896 [ |
902 [ |
897 probe := keyArray basicAt:index. |
903 probe := keyArray basicAt:index. |
898 (probe notNil and:[probe ~~ DeletedEntry and:[key = probe]]) ifTrue:[^ index]. |
904 probe isNil ifTrue:[ |
899 (self slotIsEmpty:probe) ifTrue:[ |
905 delIndex == 0 ifTrue:[^ index]. |
900 delIndex isNil ifTrue:[^ index]. |
|
901 keyArray basicAt:delIndex put:nil. |
906 keyArray basicAt:delIndex put:nil. |
902 ^ delIndex |
907 ^ delIndex |
903 ]. |
908 ]. |
904 |
|
905 probe == DeletedEntry ifTrue:[ |
909 probe == DeletedEntry ifTrue:[ |
906 delIndex isNil ifTrue:[ |
910 delIndex == 0 ifTrue:[ |
907 delIndex := index |
911 delIndex := index |
908 ] |
912 ] |
|
913 ] ifFalse:[ |
|
914 key = probe ifTrue:[^ index] |
909 ]. |
915 ]. |
910 |
916 |
911 index == length ifTrue:[ |
917 index == length ifTrue:[ |
912 index := 1 |
918 index := 1 |
913 ] ifFalse:[ |
919 ] ifFalse:[ |
914 index := index + 1 |
920 index := index + 1 |
915 ]. |
921 ]. |
916 index == startIndex ifTrue:[ |
922 index == startIndex ifTrue:[ |
917 delIndex notNil ifTrue:[ |
923 delIndex ~~ 0 ifTrue:[ |
918 keyArray basicAt:delIndex put:nil. |
924 keyArray basicAt:delIndex put:nil. |
919 ^ delIndex |
925 ^ delIndex |
920 ]. |
926 ]. |
921 ^ self grow findKeyOrNil:key |
927 ^ self grow findKeyOrNil:key |
922 ]. |
928 ]. |
1238 "return the number of set elements" |
1237 "return the number of set elements" |
1239 |
1238 |
1240 ^ tally |
1239 ^ tally |
1241 ! ! |
1240 ! ! |
1242 |
1241 |
|
1242 |
1243 !Set methodsFor:'searching'! |
1243 !Set methodsFor:'searching'! |
1244 |
1244 |
1245 findFirst:aBlock ifNone:exceptionValue |
1245 findFirst:aBlock ifNone:exceptionValue |
1246 "find the index of the first element, for which evaluation of the argument, aBlock returns true; |
1246 "find the index of the first element, for which evaluation of the argument, aBlock returns true; |
1247 return its index or the value from exceptionValue if none detected. |
1247 return its index or the value from exceptionValue if none detected. |