-
Couldn't load subscription status.
- Fork 1.4k
Handle Partial Ordering in TPriorityQueue #3923
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
Conversation
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.
Good catch!
| val genEvents: Gen[Random with Sized, Chunk[Event]] = | ||
| Gen.chunkOf(genEvent) | ||
|
|
||
| val genPredicate: Gen[Random, Event => Boolean] = |
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.
❤️
| */ | ||
| def offer(a: A): USTM[Unit] = | ||
| ref.update(map => map + (a -> map.get(a).fold(1)(_ + 1))) | ||
| ref.update(map => map + (a -> map.get(a).fold(::(a, Nil))(::(a, _)))) |
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.
we specify all the values at same partial ordering in a non-empty list ( a cons), as opposed to counting how many elements of same partial ordering we have.
| builder ++= l | ||
| r match { | ||
| case h :: t => updated += (a -> ::(h, t)) | ||
| case Nil => updated -= a |
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.
this is where we make use of the a: A on left side of SortedMap in TRef[SortedMap[A, ::[A]] by removing the elements at same priority/partial ordering when there is no more.
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 like it.
The current encoding of
TPriorityQueuerequires theOrderingon elements to be a total ordering. While potentially desirable, sometimes intentionally or unintentionally users can define a partial ordering (e.g. ordering events by timestamp but not defining a further way of ordering events with the same timestamp). This PR updatesTPriorityQueueto correctly handle these situations.Copying @phderome.