From efcbc626f9134eeabaa1a6b3c55ade8bdb9e5d53 Mon Sep 17 00:00:00 2001 From: Varun Gandhi Date: Fri, 2 Aug 2024 16:17:02 +0800 Subject: [PATCH] Find Symbol binary search --- bindings/go/scip/sort.go | 9 +++------ bindings/go/scip/sort_test.go | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/bindings/go/scip/sort.go b/bindings/go/scip/sort.go index 3e76ad2b..eb17f271 100644 --- a/bindings/go/scip/sort.go +++ b/bindings/go/scip/sort.go @@ -1,6 +1,8 @@ package scip import ( + "cmp" + "slices" "sort" "golang.org/x/exp/slices" @@ -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] diff --git a/bindings/go/scip/sort_test.go b/bindings/go/scip/sort_test.go index e0b2c6e9..f441d333 100644 --- a/bindings/go/scip/sort_test.go +++ b/bindings/go/scip/sort_test.go @@ -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" )