Skip to content

Commit

Permalink
Find Symbol binary search
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src committed Sep 18, 2024
1 parent 58cc58d commit efcbc62
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions bindings/go/scip/sort.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package scip

import (
"cmp"
"slices"
"sort"

"golang.org/x/exp/slices"
Expand All @@ -24,12 +26,7 @@ func FindSymbol(document *Document, symbolName string) *SymbolInformation {
// and SymbolInformation values must be merged. This guarantee is upheld by CanonicalizeDocument.
func FindSymbolBinarySearch(canonicalizedDocument *Document, symbolName string) *SymbolInformation {
i, found := slices.BinarySearchFunc(canonicalizedDocument.Symbols, symbolName, func(sym *SymbolInformation, lookup string) int {
if sym.Symbol < lookup {
return -1
} else if sym.Symbol == lookup {
return 0
}
return 1
return cmp.Compare(sym.Symbol, lookup)
})
if found {
return canonicalizedDocument.Symbols[i]
Expand Down
2 changes: 1 addition & 1 deletion bindings/go/scip/sort_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package scip

import (
"slices"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/stretchr/testify/require"
"golang.org/x/exp/slices"
"pgregory.net/rapid"
)

Expand Down

0 comments on commit efcbc62

Please sign in to comment.