Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/zoekt-sourcegraph-indexserver/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (o *indexArgs) BuildOptions() *index.Options {
// nothing needs to be done.
RepositoryDescription: zoekt.Repository{
TenantID: o.TenantID,
ID: uint32(o.IndexOptions.RepoID),
ID: o.IndexOptions.RepoID,
Name: o.Name,
Branches: o.Branches,
RawConfig: map[string]string{
Expand Down
8 changes: 4 additions & 4 deletions index/bits_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ package index
import (
"encoding/binary"
"log"
"math"
"math/rand"
"reflect"
"slices"
"strconv"
"testing"
"testing/quick"

"slices"

"github.com/google/go-cmp/cmp"
)

Expand Down Expand Up @@ -99,7 +99,7 @@ func TestNextFileIndex(t *testing.T) {
ends []uint32
want uint32
}{
{maxUInt32, 0, []uint32{34}, 1},
{math.MaxUint32, 0, []uint32{34}, 1},
{9, 0, []uint32{34}, 0},
{450, 0, []uint32{100, 200, 300, 400, 500, 600}, 4},
} {
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestCompressedPostingIterator(t *testing.T) {

var nums []uint32
i := newCompressedPostingIterator(data, stringToNGram("abc"))
for i.first() != maxUInt32 {
for i.first() != math.MaxUint32 {
nums = append(nums, i.first())
i.next(i.first())
}
Expand Down
25 changes: 13 additions & 12 deletions index/hititer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ package index
import (
"encoding/binary"
"fmt"
"math"

"github.com/sourcegraph/zoekt"
)

// hitIterator finds potential search matches, measured in offsets of
// the concatenation of all documents.
type hitIterator interface {
// Return the first hit, or maxUInt32 if none.
// Return the first hit, or math.MaxUint32 if none.
first() uint32

// Skip until past limit. The argument maxUInt32 should be
// Skip until past limit. The argument math.MaxUint32 should be
// treated specially.
next(limit uint32)

Expand All @@ -52,8 +53,8 @@ func (i *distanceHitIterator) findNext() {
var p1, p2 uint32
p1 = i.i1.first()
p2 = i.i2.first()
if p1 == maxUInt32 || p2 == maxUInt32 {
i.i1.next(maxUInt32)
if p1 == math.MaxUint32 || p2 == math.MaxUint32 {
i.i1.next(math.MaxUint32)
break
}

Expand Down Expand Up @@ -85,7 +86,7 @@ func (i *distanceHitIterator) next(limit uint32) {
l2 := limit + i.distance

if l2 < limit { // overflow.
l2 = maxUInt32
l2 = math.MaxUint32
}
i.i2.next(l2)
i.findNext()
Expand Down Expand Up @@ -158,14 +159,14 @@ func (i *inMemoryIterator) first() uint32 {
if len(i.postings) > 0 {
return i.postings[0]
}
return maxUInt32
return math.MaxUint32
}

func (i *inMemoryIterator) updateStats(s *zoekt.Stats) {
func (i *inMemoryIterator) updateStats(_ *zoekt.Stats) {
}

func (i *inMemoryIterator) next(limit uint32) {
if limit == maxUInt32 {
if limit == math.MaxUint32 {
i.postings = nil
}

Expand Down Expand Up @@ -203,9 +204,9 @@ func (i *compressedPostingIterator) first() uint32 {
}

func (i *compressedPostingIterator) next(limit uint32) {
if limit == maxUInt32 {
if limit == math.MaxUint32 {
i.blob = nil
i._first = maxUInt32
i._first = math.MaxUint32
return
}

Expand All @@ -217,7 +218,7 @@ func (i *compressedPostingIterator) next(limit uint32) {
}

if i._first <= limit && len(i.blob) == 0 {
i._first = maxUInt32
i._first = math.MaxUint32
}
}

Expand Down Expand Up @@ -248,7 +249,7 @@ func (i *mergingIterator) updateStats(s *zoekt.Stats) {
}

func (i *mergingIterator) first() uint32 {
r := uint32(maxUInt32)
r := uint32(math.MaxUint32)
for _, j := range i.iters {
f := j.first()
if f < r {
Expand Down
5 changes: 2 additions & 3 deletions index/indexdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"hash/crc64"
"log"
"math"
"math/bits"
"slices"
"unicode/utf8"
Expand Down Expand Up @@ -354,12 +355,10 @@ func findSelectiveNgrams(ngramOffs []runeNgramOff, indexMap []int, frequencies [
return
}

const maxUInt32 = 0xffffffff

func minFrequencyNgramOffsets(ngramOffs []runeNgramOff, frequencies []uint32) (first, last runeNgramOff) {
// Find the two lowest frequency ngrams.
idx0, idx1 := 0, 0
min0, min1 := uint32(maxUInt32), uint32(maxUInt32)
min0, min1 := uint32(math.MaxUint32), uint32(math.MaxUint32)
for i, x := range frequencies {
if x <= min0 {
idx0, idx1 = i, idx0
Expand Down
3 changes: 2 additions & 1 deletion index/indexfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package index
import (
"fmt"
"log"
"math"
"os"

"golang.org/x/sys/unix"
Expand Down Expand Up @@ -62,7 +63,7 @@ func NewIndexFile(f *os.File) (IndexFile, error) {
}

sz := fi.Size()
if sz >= maxUInt32 {
if sz >= math.MaxUint32 {
return nil, fmt.Errorf("file %s too large: %d", f.Name(), sz)
}
r := &mmapedIndexFile{
Expand Down
7 changes: 4 additions & 3 deletions index/matchiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package index
import (
"bytes"
"fmt"
"math"

"github.com/sourcegraph/zoekt"
)
Expand Down Expand Up @@ -95,7 +96,7 @@ func (t *noMatchTree) candidates() []*candidateMatch {
}

func (t *noMatchTree) nextDoc() uint32 {
return maxUInt32
return math.MaxUint32
}

func (t *noMatchTree) prepare(uint32) {}
Expand Down Expand Up @@ -148,7 +149,7 @@ func nextFileIndex(offset, f uint32, ends []uint32) uint32 {
func (i *ngramDocIterator) nextDoc() uint32 {
i.fileIdx = nextFileIndex(i.iter.first(), i.fileIdx, i.ends)
if i.fileIdx >= uint32(len(i.ends)) {
return maxUInt32
return math.MaxUint32
}
return i.fileIdx
}
Expand Down Expand Up @@ -190,7 +191,7 @@ func (i *ngramDocIterator) candidates() []*candidateMatch {
var candidates []*candidateMatch
for {
p1 := i.iter.first()
if p1 == maxUInt32 || p1 >= i.ends[i.fileIdx] {
if p1 == math.MaxUint32 || p1 >= i.ends[i.fileIdx] {
break
}
i.iter.next(p1)
Expand Down
13 changes: 7 additions & 6 deletions index/matchtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"bytes"
"fmt"
"log"
"math"
"regexp/syntax"
"strings"
"unicode/utf8"
Expand Down Expand Up @@ -442,7 +443,7 @@ func (t *docMatchTree) nextDoc() uint32 {
return i
}
}
return maxUInt32
return math.MaxUint32
}

func (t *bruteForceMatchTree) nextDoc() uint32 {
Expand All @@ -464,7 +465,7 @@ func (t *andMatchTree) nextDoc() uint32 {
}

func (t *orMatchTree) nextDoc() uint32 {
min := uint32(maxUInt32)
min := uint32(math.MaxUint32)
for _, c := range t.children {
m := c.nextDoc()
if m < min {
Expand Down Expand Up @@ -497,7 +498,7 @@ func (t *branchQueryMatchTree) nextDoc() uint32 {
return i
}
}
return maxUInt32
return math.MaxUint32
}

// all String methods
Expand Down Expand Up @@ -672,7 +673,7 @@ func (t *andLineMatchTree) matches(cp *contentProvider, cost int, known map[matc
// can return MatchesFound.

// find child with fewest candidates
min := maxUInt32
minCount := math.MaxInt
fewestChildren := 0
for ix, child := range t.children {
v, ok := child.(*substrMatchTree)
Expand All @@ -681,8 +682,8 @@ func (t *andLineMatchTree) matches(cp *contentProvider, cost int, known map[matc
if !ok || v.fileName {
return matchesFound
}
if len(v.current) < min {
min = len(v.current)
if len(v.current) < minCount {
minCount = len(v.current)
fewestChildren = ix
}
}
Expand Down
9 changes: 5 additions & 4 deletions index/matchtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package index

import (
"math"
"reflect"
"regexp/syntax"
"testing"
Expand Down Expand Up @@ -304,7 +305,7 @@ func TestRepoSet(t *testing.T) {
}
mt.prepare(nextDoc)
}
if mt.nextDoc() != maxUInt32 {
if mt.nextDoc() != math.MaxUint32 {
t.Fatalf("expected %d document, but got at least 1 more", len(want))
}
}
Expand All @@ -327,7 +328,7 @@ func TestRepo(t *testing.T) {
}
mt.prepare(nextDoc)
}
if mt.nextDoc() != maxUInt32 {
if mt.nextDoc() != math.MaxUint32 {
t.Fatalf("expect %d documents, but got at least 1 more", len(want))
}
}
Expand Down Expand Up @@ -360,7 +361,7 @@ func TestBranchesRepos(t *testing.T) {
mt.prepare(nextDoc)
}

if mt.nextDoc() != maxUInt32 {
if mt.nextDoc() != math.MaxUint32 {
t.Fatalf("expect %d documents, but got at least 1 more", len(want))
}
}
Expand All @@ -383,7 +384,7 @@ func TestRepoIDs(t *testing.T) {
}
mt.prepare(nextDoc)
}
if mt.nextDoc() != maxUInt32 {
if mt.nextDoc() != math.MaxUint32 {
t.Fatalf("expected %d document, but got at least 1 more", len(want))
}
}
Expand Down
Loading