On Mon, 2007-03-26 at 09:21 +0200, Paolo Bonzini wrote: > Well, it's there because a hash table needs more room than it has > elements.
May I suggest instead smalltalk--backstage--2.2--patch-13:
* kernel/HashedColl.st: Treat new:'s argument as a requested
capacity.
This has the added benefit of meeting:
Refinement: <Dictionary factory>
The parameter count represents a hint for space allocation. The new
collection is to optimized to
contain count elements. The new collection initially contains no elements.
The reason I didn't notice this earlier was because for every size 1
bitShift: (size * 3 // 4) highBit => size. :)
HashedCollection>>withAll:'s definition might also want to change,
depending on what you think the probability of adding keys versus the
space savings of leaving off * 2 would be.
--
;;; Stephen Compall ** http://scompall.nocandysw.com/blog **
Failure to imagine vast possibilities usually stems from a lack of
imagination, not a lack of possibility.
2007-03-29 Stephen Compall <[EMAIL PROTECTED]>
* kernel/Dictionary.st: Use a smaller default size in new.
* kernel/HashedColl.st: Treat new:'s argument as a requested
capacity.
--- orig/kernel/Dictionary.st
+++ mod/kernel/Dictionary.st
@@ -55,7 +55,7 @@
to create dictionaries. Unfortunately, this #new method only creates
dictionaries, so subclasses when trying to use this method, lose big.
This fixes the problem."
- ^self new: 31
+ ^self new: 24
! !
--- orig/kernel/HashedColl.st
+++ mod/kernel/HashedColl.st
@@ -51,13 +51,13 @@
new
"Answer a new instance of the receiver with a default size"
- ^self new: 8
+ ^self new: 0
!
new: anInteger
- "Answer a new instance of the receiver with the given size"
+ "Answer a new instance of the receiver with the given capacity"
| realSize |
- realSize := 8 max: anInteger.
+ realSize := 8 max: (anInteger * 4 + 2) // 3.
(realSize bitAnd: (realSize - 1)) = 0 ifFalse: [
realSize := 1 bitShift: realSize highBit
].
signature.asc
Description: This is a digitally signed message part
_______________________________________________ help-smalltalk mailing list [email protected] http://lists.gnu.org/mailman/listinfo/help-smalltalk
