Skip to content

Commit

Permalink
ast/term: Swap custom key interface for termSlice.
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Conrad <[email protected]>
  • Loading branch information
philipaconrad committed Aug 15, 2022
1 parent 879f896 commit ba1c4a5
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions ast/term.go
Original file line number Diff line number Diff line change
Expand Up @@ -1368,16 +1368,9 @@ func SetTerm(t ...*Term) *Term {
}
}

// sort.Sort expects an interface type, so we provide one here.
type setKeySlice []*Term

func (s setKeySlice) Less(i, j int) bool { return Compare(s[i].Value, s[j].Value) < 0 }
func (s setKeySlice) Swap(i, j int) { x := s[i]; s[i] = s[j]; s[j] = x }
func (s setKeySlice) Len() int { return len(s) }

type set struct {
elems map[int]*Term
keys setKeySlice
keys []*Term
hash int
ground bool
numInserts int // number of inserts since last sorting.
Expand Down Expand Up @@ -1422,7 +1415,7 @@ func (s *set) String() string {

func (s *set) sortedKeys() []*Term {
if s.numInserts > 0 {
sort.Sort(s.keys)
sort.Sort(termSlice(s.keys))
s.numInserts = 0
}
return s.keys
Expand Down

0 comments on commit ba1c4a5

Please sign in to comment.