fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

compressedPostingList returns maxUInt32 at end of iteration

Added a test which picked up this corner case.

Change-Id: I776fb294b3aac5b812b9859da0d7b6c2485b732f

+61 -5
+4 -5
hititer.go
··· 209 209 return 210 210 } 211 211 212 - if i._first <= limit && len(i.blob) == 0 { 213 - i._first = maxUInt32 214 - return 215 - } 216 - 217 212 for i._first <= limit && len(i.blob) > 0 { 218 213 delta, sz := binary.Uvarint(i.blob) 219 214 i._first += uint32(delta) 220 215 i.blob = i.blob[sz:] 216 + } 217 + 218 + if i._first <= limit && len(i.blob) == 0 { 219 + i._first = maxUInt32 221 220 } 222 221 } 223 222
+57
hititer_test.go
··· 1 + // Copyright 2019 Google Inc. All rights reserved. 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package zoekt 16 + 17 + import ( 18 + "reflect" 19 + "sort" 20 + "testing" 21 + "testing/quick" 22 + 23 + "github.com/google/go-cmp/cmp" 24 + ) 25 + 26 + func TestCompressedPostingIterator_limit(t *testing.T) { 27 + f := func(nums, limits []uint32) bool { 28 + if len(nums) == 0 || len(limits) == 0 { 29 + return true 30 + } 31 + 32 + nums = sortedUnique(nums) 33 + sort.Slice(limits, func(i, j int) bool { return limits[i] < limits[j] }) 34 + 35 + want := doHitIterator(&inMemoryIterator{postings: nums}, limits) 36 + 37 + it := newCompressedPostingIterator(toDeltas(nums), stringToNGram("abc")) 38 + got := doHitIterator(it, limits) 39 + if !reflect.DeepEqual(want, got) { 40 + t.Log(cmp.Diff(want, got)) 41 + return false 42 + } 43 + return true 44 + } 45 + if err := quick.Check(f, nil); err != nil { 46 + t.Error(err) 47 + } 48 + } 49 + 50 + func doHitIterator(it hitIterator, limits []uint32) []uint32 { 51 + var nums []uint32 52 + for _, limit := range limits { 53 + it.next(limit) 54 + nums = append(nums, it.first()) 55 + } 56 + return nums 57 + }