span buffer test now passes. Code ist still too complicated.

This commit is contained in:
Sascha L. Teichmann 2014-10-21 17:41:19 +02:00
parent e744390503
commit 269e63ea59

View File

@ -118,24 +118,24 @@ 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 {
if next.From == s.To-1 && value == next.Value {
s.To = next.To s.To = next.To
s.Next = next.Next s.Next = next.Next
sp.Free(next) sp.Free(next)
}
return head return head
} }
// Extend next? // Extend next?
if pos == next.From-1 && value == next.Value { if next != nil && pos == next.From-1 && value == next.Value {
next.From = pos next.From = pos
return head return head
} }
// Before next -> New between current and next // Before next -> New between current and next
if pos < next.From { if next == nil || pos < next.From {
sn := sp.Alloc() sn := sp.Alloc()
sn.From = pos sn.From = pos
sn.To = pos sn.To = pos
@ -144,42 +144,6 @@ func (sp *SpanPool) Insert(s *Span, pos, value int32) *Span {
s.Next = sn s.Next = sn
return head 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. default: // pos in span -> do not modify.
return head return head