Skip to content

Commit

Permalink
Refactor complement
Browse files Browse the repository at this point in the history
  • Loading branch information
pointlander committed May 8, 2024
1 parent da84c85 commit 6c23725
Showing 1 changed file with 26 additions and 38 deletions.
64 changes: 26 additions & 38 deletions set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,49 +180,38 @@ func (s *Set) Complement(endSymbol rune) *Set {
return set
}
a, b := &s.Head, &set.Head
if a.Forward.Begin == 0 && s.Tail.Backward.End == endSymbol {
pre := rune(0)
if pre == a.Forward.Begin {
a = a.Forward
pre := a.End + 1
a = a.Forward
for a.Forward != nil {
node := Node{
Backward: b,
Begin: pre,
End: a.Begin - 1,
}
pre = a.End + 1
b.Forward = &node
a = a.Forward
b = b.Forward
pre = a.End + 1
}
a = a.Forward
for a.Forward != nil {
node := Node{
Backward: b,
Begin: pre,
End: a.Begin - 1,
}
b.Forward = &set.Tail
set.Tail.Backward = b
} else {
pre := rune(0)
a = a.Forward
for a.Forward != nil {
node := Node{
Backward: b,
Begin: pre,
End: a.Begin - 1,
}
if a.End == endSymbol {
pre = endSymbol
} else {
pre = a.End + 1
b.Forward = &node
a = a.Forward
b = b.Forward
}
if pre < endSymbol {
node := Node{
Backward: b,
Begin: pre,
End: endSymbol,
}
b.Forward = &node
b = b.Forward
b.Forward = &node
a = a.Forward
b = b.Forward
}
if pre < endSymbol {
node := Node{
Backward: b,
Begin: pre,
End: endSymbol,
}
b.Forward = &set.Tail
set.Tail.Backward = b
b.Forward = &node
b = b.Forward
}
b.Forward = &set.Tail
set.Tail.Backward = b
return set
}

Expand Down Expand Up @@ -294,7 +283,6 @@ func (s *Set) Equal(a *Set) bool {
x, y := s.Head.Forward, a.Head.Forward
for {
if x.Begin != y.Begin || x.End != y.End {
fmt.Println(x.Begin, x.End, y.Begin, y.End)
return false
}
x, y = x.Forward, y.Forward
Expand Down

0 comments on commit 6c23725

Please sign in to comment.