SWIM Suspicion Round
SWIM Suspicion Round
You are simulating one SWIM failure-detection round. Each node has a current membership state and a suspicion count. Reports from other nodes can increase or reset suspicion.
Rules (processed in order):
alivereport: if the target is notdead, set state toalive, resetSuspectCountto 0, and clear any counted reporters for this round.suspectreport: if the target isaliveand the reporter has not already reported this target since the last reset, incrementSuspectCount.- If
SuspectCount >= K, mark the targetsuspect(if notdead). - Reports about
deadnodes are ignored.
Return the updated membership list in the same order as input.
Types
type Member struct {
ID int
State string // "alive", "suspect", "dead"
SuspectCount int
}
type Report struct {
Target int
Reporter int
Kind string // "alive" or "suspect"
}
Function signature
func SwimSuspectRound(members []Member, reports []Report, k int) []Member
Example
K = 2
members = [
{ID:1, State:"alive", SuspectCount:0},
{ID:2, State:"alive", SuspectCount:1},
]
reports = [
{Target:2, Reporter:9, Kind:"suspect"},
]
Result: member 2 becomes "suspect" with SuspectCount=2
Constraints
0 <= len(members), len(reports) <= 1000001 <= k <= 1000- IDs are unique in
members
Notes
- If the target is
dead, leave it unchanged. - Duplicate
suspectreports from the same reporter in the same round count once.
Run tests to see results
No issues detected