Created
October 1, 2022 06:14
-
-
Save meysampg/30be5369e24c5e881904fda92e9b6e84 to your computer and use it in GitHub Desktop.
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
import scala.language.postfixOps | |
class LamportClock(private var count: Int = 0) { | |
// increment | |
def ++ = LamportClock(count + 1) | |
// merge | |
def +(other: LamportClock) = new LamportClock(math.max(count, other.count) + 1) | |
override def toString: String = s"LamportClock($count)" | |
} | |
object LamportClock { | |
def apply(count: Int = 0): LamportClock = new LamportClock(count) | |
} | |
val a = LamportClock(1) | |
val b = LamportClock(4) | |
println(a) | |
println(b) | |
println(a++) | |
println(a + b) |
Author
meysampg
commented
Oct 1, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment