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
|
this.parentSub = canCopyParentInfo && (info & binary.BIT6) === binary.BIT6 ? decoding.readVarString(decoder) : null
|
||||||
const missing = this._missing
|
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)
|
missing.push(this.left)
|
||||||
}
|
}
|
||||||
if (this.right !== null) {
|
if (this.right !== null && this.right.client !== id.client) {
|
||||||
missing.push(this.right)
|
missing.push(this.right)
|
||||||
}
|
}
|
||||||
if (this.parent !== null) {
|
if (this.parent !== null) {
|
||||||
|
@ -124,10 +124,15 @@ export const addStruct = (store, struct) => {
|
|||||||
export const findIndexSS = (structs, clock) => {
|
export const findIndexSS = (structs, clock) => {
|
||||||
let left = 0
|
let left = 0
|
||||||
let right = structs.length - 1
|
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) {
|
while (left <= right) {
|
||||||
const midindex = math.floor((left + right) / 2)
|
mid = structs[midindex]
|
||||||
const mid = structs[midindex]
|
midclock = mid.id.clock
|
||||||
const midclock = mid.id.clock
|
|
||||||
if (midclock <= clock) {
|
if (midclock <= clock) {
|
||||||
if (clock < midclock + mid.length) {
|
if (clock < midclock + mid.length) {
|
||||||
return midindex
|
return midindex
|
||||||
@ -136,6 +141,7 @@ export const findIndexSS = (structs, clock) => {
|
|||||||
} else {
|
} else {
|
||||||
right = midindex - 1
|
right = midindex - 1
|
||||||
}
|
}
|
||||||
|
midindex = math.floor((left + right) / 2)
|
||||||
}
|
}
|
||||||
// Always check state before looking for a struct in StructStore
|
// Always check state before looking for a struct in StructStore
|
||||||
// Therefore the case of not finding a struct is unexpected
|
// Therefore the case of not finding a struct is unexpected
|
||||||
|
Loading…
x
Reference in New Issue
Block a user