5 changed files with 155 additions and 8 deletions
@ -0,0 +1,76 @@ |
|||
package cdr |
|||
|
|||
type SortableCalls struct { |
|||
Calls []Call |
|||
num int // shortcut for Len()
|
|||
} |
|||
|
|||
func NewSortableCalls(c []Call) *SortableCalls { |
|||
return &SortableCalls{ |
|||
Calls: append(c[:0:0], c...), |
|||
num: len(c), |
|||
} |
|||
} |
|||
|
|||
func (sc *SortableCalls) Len() int { |
|||
return sc.num |
|||
} |
|||
|
|||
func (sc *SortableCalls) Less(i, j int) bool { |
|||
// We assume i, j < len(sc.Calls)
|
|||
return sc.Calls[i].Time.Before(sc.Calls[j].Time) |
|||
} |
|||
|
|||
func (sc *SortableCalls) Swap(i, j int) { |
|||
sc.Calls[j], sc.Calls[i] = sc.Calls[i], sc.Calls[j] |
|||
} |
|||
|
|||
type SortableTexts struct { |
|||
Texts []Text |
|||
num int // shortcut for Len()
|
|||
} |
|||
|
|||
func NewSortableTexts(t []Text) *SortableTexts { |
|||
return &SortableTexts{ |
|||
Texts: append(t[:0:0], t...), |
|||
num: len(t), |
|||
} |
|||
} |
|||
|
|||
func (st *SortableTexts) Len() int { |
|||
return st.num |
|||
} |
|||
|
|||
func (st *SortableTexts) Less(i, j int) bool { |
|||
// We assume i, j < len(st.Texts)
|
|||
return st.Texts[i].PricedLine.Line.Time.Before(st.Texts[j].PricedLine.Line.Time) |
|||
} |
|||
|
|||
func (st *SortableTexts) Swap(i, j int) { |
|||
st.Texts[j], st.Texts[i] = st.Texts[i], st.Texts[j] |
|||
} |
|||
|
|||
type SortableData struct { |
|||
Data []Data |
|||
num int // shortcut for Len()
|
|||
} |
|||
|
|||
func NewSortableData(d []Data) *SortableData { |
|||
return &SortableData{ |
|||
Data: append(d[:0:0], d...), |
|||
num: len(d), |
|||
} |
|||
} |
|||
|
|||
func (sd *SortableData) Len() int { |
|||
return sd.num |
|||
} |
|||
|
|||
func (sd *SortableData) Less(i, j int) bool { |
|||
// We assume i, j < len(st.Data)
|
|||
return sd.Data[i].PricedLine.Line.Time.Before(sd.Data[j].PricedLine.Line.Time) |
|||
} |
|||
|
|||
func (sd *SortableData) Swap(i, j int) { |
|||
sd.Data[j], sd.Data[i] = sd.Data[i], sd.Data[j] |
|||
} |
|||
Loading…
Reference in new issue