Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

The current encoding of TPriorityQueue requires the Ordering on 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 updates TPriorityQueue to correctly handle these situations.

Copying @phderome.

@adamgfraser adamgfraser requested a review from mijicd July 1, 2020 03:24
Copy link
Member

@mijicd mijicd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@mijicd mijicd merged commit f7b2849 into zio:master Jul 1, 2020
val genEvents: Gen[Random with Sized, Chunk[Event]] =
Gen.chunkOf(genEvent)

val genPredicate: Gen[Random, Event => Boolean] =
Copy link
Contributor

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, _))))
Copy link
Contributor

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
Copy link
Contributor

@phderome phderome Jul 1, 2020

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.

Copy link
Contributor

@phderome phderome left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it.

@adamgfraser adamgfraser deleted the tpriorityqueue branch July 1, 2020 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants