mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2025-01-11 09:20:17 +01:00
span buffer test now passes. Code ist still too complicated.
This commit is contained in:
parent
e744390503
commit
269e63ea59
@ -118,24 +118,24 @@ func (sp *SpanPool) Insert(s *Span, pos, value int32) *Span {
|
||||
return head
|
||||
|
||||
case pos > s.To: // after span
|
||||
next := s.Next
|
||||
if pos == s.To+1 && value == s.Value { // directly neighbored
|
||||
s.To = pos
|
||||
// Check if a gap has to be closed
|
||||
next := s.Next
|
||||
if next != nil {
|
||||
if next.From == s.To-1 && value == next.Value {
|
||||
if next != nil && next.From == s.To+1 && value == next.Value {
|
||||
s.To = next.To
|
||||
s.Next = next.Next
|
||||
sp.Free(next)
|
||||
}
|
||||
return head
|
||||
}
|
||||
// Extend next?
|
||||
if pos == next.From-1 && value == next.Value {
|
||||
if next != nil && pos == next.From-1 && value == next.Value {
|
||||
next.From = pos
|
||||
return head
|
||||
}
|
||||
// Before next -> New between current and next
|
||||
if pos < next.From {
|
||||
if next == nil || pos < next.From {
|
||||
sn := sp.Alloc()
|
||||
sn.From = pos
|
||||
sn.To = pos
|
||||
@ -144,42 +144,6 @@ func (sp *SpanPool) Insert(s *Span, pos, value int32) *Span {
|
||||
s.Next = sn
|
||||
return head
|
||||
}
|
||||
} else { // No next -> new at tail
|
||||
sn := sp.Alloc()
|
||||
sn.From = pos
|
||||
sn.To = pos
|
||||
sn.Value = value
|
||||
sn.Next = nil
|
||||
s.Next = sn
|
||||
return head
|
||||
}
|
||||
} else { // Not directly connected and/or values do not match.
|
||||
next := s.Next
|
||||
if next != nil {
|
||||
if pos == next.From-1 && value == next.Value {
|
||||
next.From = pos
|
||||
return head
|
||||
}
|
||||
// Before next -> New between current and next
|
||||
if pos < next.From {
|
||||
sn := sp.Alloc()
|
||||
sn.From = pos
|
||||
sn.To = pos
|
||||
sn.Value = value
|
||||
sn.Next = next
|
||||
s.Next = sn
|
||||
return head
|
||||
}
|
||||
} else { // No next -> new at tail
|
||||
sn := sp.Alloc()
|
||||
sn.From = pos
|
||||
sn.To = pos
|
||||
sn.Value = value
|
||||
sn.Next = nil
|
||||
s.Next = sn
|
||||
return head
|
||||
}
|
||||
}
|
||||
|
||||
default: // pos in span -> do not modify.
|
||||
return head
|
||||
|
Loading…
Reference in New Issue
Block a user