github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/pkg/segment/structs/searchhelpers.go (about)

     1  /*
     2  Copyright 2023.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package structs
    18  
    19  import (
    20  	"github.com/siglens/siglens/pkg/segment/pqmr"
    21  )
    22  
    23  // a helper struct to keep track to the blocks search status.
    24  // This struct will be used to re-use slices of matched time stamps
    25  // it is important to know that the slice is re-used, so callers would need to copy the values if needed
    26  // else, will leak memory
    27  type BlockSearchHelper struct {
    28  	matchedRecs *pqmr.PQMatchResults
    29  }
    30  
    31  func InitBlockSearchHelper() *BlockSearchHelper {
    32  	return &BlockSearchHelper{
    33  		matchedRecs: pqmr.CreatePQMatchResults(uint(0)),
    34  	}
    35  }
    36  
    37  func InitAllBlockSearchHelpers(fileParallelism int64) []*BlockSearchHelper {
    38  	allHelpers := make([]*BlockSearchHelper, fileParallelism)
    39  
    40  	for i := int64(0); i < fileParallelism; i++ {
    41  		allHelpers[i] = InitBlockSearchHelper()
    42  	}
    43  	return allHelpers
    44  }
    45  
    46  // keep allocated slice
    47  func (h *BlockSearchHelper) ResetBlockHelper() {
    48  	h.matchedRecs.ResetAll()
    49  }
    50  
    51  func (h *BlockSearchHelper) GetAllMatchedRecords() *pqmr.PQMatchResults {
    52  	return h.matchedRecs
    53  }
    54  
    55  func (h *BlockSearchHelper) AddMatchedRecord(recNum uint) {
    56  	h.matchedRecs.AddMatchedRecord(recNum)
    57  }
    58  
    59  func (h *BlockSearchHelper) ClearBit(recNum uint) {
    60  	h.matchedRecs.ClearBit(recNum)
    61  }
    62  
    63  func (h *BlockSearchHelper) DoesRecordMatch(recNum uint) bool {
    64  	return h.matchedRecs.DoesRecordMatch(recNum)
    65  }