-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Some improvements to util.HashSet and HashMap #9865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e5b1ecc
Instrument collection sizes
odersky 1c09b53
Fix hashcodes of inner case classes in NameKinds
odersky ef59339
Fix growTable function for HashMap
odersky 3ad578e
Fix HashMap and HashSet remove criterion
odersky daf6db7
Process hashcode bits in util.HashMap and HashSet
odersky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
trait Generator[+T]: | ||
self => | ||
def generate: T | ||
def map[S](f: T => S) = new Generator[S]: | ||
def generate: S = f(self.generate) | ||
def flatMap[S](f: T => Generator[S]) = new Generator[S]: | ||
def generate: S = f(self.generate).generate | ||
|
||
object Generator: | ||
val NumLimit = 300 | ||
val Iterations = 10000 | ||
|
||
given integers as Generator[Int]: | ||
val rand = new java.util.Random | ||
def generate = rand.nextInt() | ||
|
||
given booleans as Generator[Boolean] = | ||
integers.map(x => x > 0) | ||
|
||
def range(end: Int): Generator[Int] = | ||
integers.map(x => (x % end).abs) | ||
|
||
enum Op: | ||
case Lookup, Update, Remove | ||
export Op._ | ||
|
||
given ops as Generator[Op] = | ||
range(10).map { | ||
case 0 | 1 | 2 | 3 => Lookup | ||
case 4 | 5 | 6 | 7 => Update | ||
case 8 | 9 => Remove | ||
} | ||
|
||
val nums: Generator[Integer] = range(NumLimit).map(Integer(_)) | ||
|
||
@main def Test = | ||
import Generator._ | ||
|
||
val set1 = dotty.tools.dotc.util.HashSet[Int]() | ||
val set2 = scala.collection.mutable.HashSet[Int]() | ||
|
||
def checkSame() = | ||
assert(set1.size == set2.size) | ||
for e <- set1.iterator do | ||
assert(set2.contains(e)) | ||
for e <- set2.iterator do | ||
assert(set1.contains(e)) | ||
|
||
def lookupTest(num: Integer) = | ||
val res1 = set1.contains(num) | ||
val res2 = set2.contains(num) | ||
assert(res1 == res2) | ||
|
||
def updateTest(num: Integer) = | ||
lookupTest(num) | ||
set1 += num | ||
set2 += num | ||
checkSame() | ||
|
||
def removeTest(num: Integer) = | ||
//println(s"test remove $num") | ||
set1 -= num | ||
set2 -= num | ||
checkSame() | ||
|
||
for i <- 0 until Iterations do | ||
val num = nums.generate | ||
Generator.ops.generate match | ||
case Lookup => lookupTest(num) | ||
case Update => updateTest(num) | ||
case Remove => removeTest(num) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand why we need the
if
here, instead of simply growing the table, since all calls togrowTable
is guarded byif used > limit
. Is it to just create a larger array at the sizeDenseLimit * 2
(instead of simply doubling the size)?Meanwhile, if we change the code here, do we need similar changes inHashSet.growTable
?