implement pivoting in struct search
This commit is contained in:
parent
ee147c14f1
commit
7b16d5c92d
@ -712,10 +712,12 @@ export class ItemRef extends AbstractStructRef {
|
||||
*/
|
||||
this.parentSub = canCopyParentInfo && (info & binary.BIT6) === binary.BIT6 ? decoding.readVarString(decoder) : null
|
||||
const missing = this._missing
|
||||
if (this.left !== null) {
|
||||
// Only add items to missing if they don't preceed this item (indicating that it has already been added).
|
||||
// @todo Creating missing items could be done outside this constructor
|
||||
if (this.left !== null && this.left.client !== id.client) {
|
||||
missing.push(this.left)
|
||||
}
|
||||
if (this.right !== null) {
|
||||
if (this.right !== null && this.right.client !== id.client) {
|
||||
missing.push(this.right)
|
||||
}
|
||||
if (this.parent !== null) {
|
||||
|
@ -124,10 +124,15 @@ export const addStruct = (store, struct) => {
|
||||
export const findIndexSS = (structs, clock) => {
|
||||
let left = 0
|
||||
let right = structs.length - 1
|
||||
let mid = structs[right]
|
||||
let midclock = mid.id.clock
|
||||
if (mid.id.clock === clock) {
|
||||
return right
|
||||
}
|
||||
let midindex = math.floor((clock / (midclock + mid.length)) * right) // pivoting the search
|
||||
while (left <= right) {
|
||||
const midindex = math.floor((left + right) / 2)
|
||||
const mid = structs[midindex]
|
||||
const midclock = mid.id.clock
|
||||
mid = structs[midindex]
|
||||
midclock = mid.id.clock
|
||||
if (midclock <= clock) {
|
||||
if (clock < midclock + mid.length) {
|
||||
return midindex
|
||||
@ -136,6 +141,7 @@ export const findIndexSS = (structs, clock) => {
|
||||
} else {
|
||||
right = midindex - 1
|
||||
}
|
||||
midindex = math.floor((left + right) / 2)
|
||||
}
|
||||
// Always check state before looking for a struct in StructStore
|
||||
// Therefore the case of not finding a struct is unexpected
|
||||
|
Loading…
x
Reference in New Issue
Block a user