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,67 +118,31 @@ func (sp *SpanPool) Insert(s *Span, pos, value int32) *Span {
|
|||||||
return head
|
return head
|
||||||
|
|
||||||
case pos > s.To: // after span
|
case pos > s.To: // after span
|
||||||
|
next := s.Next
|
||||||
if pos == s.To+1 && value == s.Value { // directly neighbored
|
if pos == s.To+1 && value == s.Value { // directly neighbored
|
||||||
s.To = pos
|
s.To = pos
|
||||||
// Check if a gap has to be closed
|
// Check if a gap has to be closed
|
||||||
next := s.Next
|
if next != nil && next.From == s.To+1 && value == next.Value {
|
||||||
if next != nil {
|
s.To = next.To
|
||||||
if next.From == s.To-1 && value == next.Value {
|
s.Next = next.Next
|
||||||
s.To = next.To
|
sp.Free(next)
|
||||||
s.Next = next.Next
|
|
||||||
sp.Free(next)
|
|
||||||
return head
|
|
||||||
}
|
|
||||||
// Extend next?
|
|
||||||
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
|
|
||||||
}
|
|
||||||
} 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
|
|
||||||
}
|
}
|
||||||
|
return head
|
||||||
|
}
|
||||||
|
// Extend next?
|
||||||
|
if next != nil && pos == next.From-1 && value == next.Value {
|
||||||
|
next.From = pos
|
||||||
|
return head
|
||||||
|
}
|
||||||
|
// Before next -> New between current and next
|
||||||
|
if next == nil || pos < next.From {
|
||||||
|
sn := sp.Alloc()
|
||||||
|
sn.From = pos
|
||||||
|
sn.To = pos
|
||||||
|
sn.Value = value
|
||||||
|
sn.Next = next
|
||||||
|
s.Next = sn
|
||||||
|
return head
|
||||||
}
|
}
|
||||||
|
|
||||||
default: // pos in span -> do not modify.
|
default: // pos in span -> do not modify.
|
||||||
|
Loading…
Reference in New Issue
Block a user