From 938b53945d97f94184090e5bd6d46e0b38f5d3e1 Mon Sep 17 00:00:00 2001 From: Ivan Danyliuk Date: Tue, 23 Oct 2018 22:38:34 +0200 Subject: [PATCH] Implement sorting for plog --- propagation/plog.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/propagation/plog.go b/propagation/plog.go index a135d70..127afb3 100644 --- a/propagation/plog.go +++ b/propagation/plog.go @@ -25,3 +25,15 @@ func (l *Log) AddStep(ts int, nodes, links []int) { l.Nodes = append(l.Nodes, nodes) l.Indices = append(l.Indices, links) } + +func (l *Log) Less(i, j int) bool { + return l.Timestamps[i] < l.Timestamps[j] +} +func (l *Log) Swap(i, j int) { + l.Timestamps[i], l.Timestamps[j] = l.Timestamps[j], l.Timestamps[i] + l.Nodes[i], l.Nodes[j] = l.Nodes[j], l.Nodes[i] + l.Indices[j], l.Indices[j] = l.Indices[j], l.Indices[i] +} +func (l *Log) Len() int { + return len(l.Timestamps) +}