-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mergeUp): for SBFNode + getFillStatus + fix for root
Now root correctly hold data at starts in an identifiers array. Will make our test fails
- Loading branch information
1 parent
d34784d
commit 6072fa5
Showing
26 changed files
with
377 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,6 @@ | ||
async function removeDocument(identifier){ | ||
console.log(identifier) | ||
console.log(identifier) | ||
console.log(identifier) | ||
console.log(identifier) | ||
console.log(identifier) | ||
if(!this.documents[identifier]){ | ||
console.log(this.documents[identifier]) | ||
console.log(this.documents[identifier]) | ||
console.log(this.documents[identifier]) | ||
console.log(this.documents[identifier]) | ||
console.log(this.documents[identifier]) | ||
console.log(this.documents[identifier]) | ||
if(this.documents[identifier]){ | ||
delete this.documents[identifier] | ||
} | ||
} | ||
module.exports = removeDocument |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
module.exports = async function attachLeaf(index, leaf){ | ||
this.childrens.splice(index,0,leaf); | ||
|
||
leaf.setParent(this); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const getFillStatus = async function(){ | ||
const parent = this.getParent(); | ||
const adapter = parent.getAdapter(); | ||
const {fillFactor,order} = parent.getTreeOptions(); | ||
if(fillFactor<0.5){ | ||
throw new Error(`FillFactor cannot be less than 0.5. Received ${fillFactor}`) | ||
} | ||
try { | ||
const leaf = await adapter.openLeaf(this.id); | ||
|
||
return {fillFactor, order, leafSize:leaf.meta.size, fillFactorFilled: leaf.meta.size>=(order*fillFactor)}; | ||
}catch (e) { | ||
if(e.message === 'Leaf do not exist'){ | ||
await adapter.createLeaf(this.id); | ||
return this.getFillStatus() | ||
} | ||
else throw e | ||
}; | ||
}; | ||
module.exports = getFillStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Merge the node with it's parent (thus : up). | ||
* Used mostly from the results of a merge from leafs when it result in emptying parent node keys. | ||
* Parent node is then called for some mergeUp. | ||
* | ||
* @returns {Promise<void>} | ||
*/ | ||
const mergeUp = async function(){ | ||
const parent = this.getParent(); | ||
const {childrens, keys, id}= this; | ||
// const | ||
const selfPos = parent.childrens.findIndex((el)=> el.id === id); | ||
if(childrens.length!==1){ | ||
throw new Error('We did not tought about resolving this case. ');//todo | ||
} | ||
if(parent.childrens.length===2 && !await parent.getFillStatus().fillFactorFilled){ | ||
// We actually bring both leaf | ||
let siblingPos = (selfPos===1) ? 0 : 1; | ||
const sibling = parent.childrens[siblingPos]; | ||
|
||
parent.keys.splice(siblingPos, 0, ...sibling.keys); | ||
parent.childrens = [...sibling.childrens, ...childrens] | ||
}else{ | ||
// parent.childrens.splice(selfPos, 1, childrens[0]); | ||
// console.log(selfPos); | ||
// console.log(parent.keys); | ||
// console.log(parent) | ||
|
||
// console.log(this) | ||
// console.log(await parent.getFillStatus()) | ||
throw new Error('Not implemented : MergingUp'); | ||
} | ||
|
||
|
||
}; | ||
module.exports = mergeUp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
async function remove(value){ | ||
async function remove(remCmd){ | ||
const value = remCmd.query[this.fieldName]; | ||
|
||
let leafIndex = 0; | ||
this.keys.forEach((_key)=>{ | ||
if(value<=_key) return; | ||
if(value<_key) return; | ||
leafIndex++; | ||
}); | ||
|
||
const leaf = this.childrens[leafIndex]; | ||
await leaf.remove(value); | ||
await leaf.remove(remCmd); | ||
}; | ||
module.exports = remove; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const getFillStatus = async function(){ | ||
const adapter = this.getAdapter(); | ||
const {fillFactor,order} = this.getTreeOptions(); | ||
if(fillFactor<0.5){ | ||
throw new Error(`FillFactor cannot be less than 0.5. Received ${fillFactor}`) | ||
} | ||
return {fillFactor, order, leafSize:this.keys.length, fillFactorFilled: this.keys.length>=(order*fillFactor)}; | ||
|
||
}; | ||
module.exports = getFillStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Merge the node with it's parent (thus : up). | ||
* Used mostly from the results of a merge from leafs when it result in emptying parent node keys. | ||
* Parent node is then called for some mergeUp. | ||
* | ||
* @returns {Promise<void>} | ||
*/ | ||
const mergeDown = async function(){ | ||
const parent = this.getParent(); | ||
const {childrens, keys, id}= this; | ||
|
||
if(childrens.leng) | ||
|
||
|
||
|
||
// parent.childrens.splice(selfPos, 1, childrens[0]); | ||
// console.log(selfPos); | ||
// console.log(parent.keys); | ||
// console.log(parent) | ||
|
||
// console.log(this) | ||
// console.log(await parent.getFillStatus()) | ||
console.log('Mergeup') | ||
console.log('Mergeup') | ||
console.log('Mergeup') | ||
console.log('Mergeup') | ||
console.log('Mergeup') | ||
console.log('Mergeup') | ||
console.log('Mergeup') | ||
throw new Error() | ||
}; | ||
module.exports = mergeDown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
async function remove(remCmd){ | ||
const value = remCmd.query[this.fieldName]; | ||
|
||
async function remove(value){ | ||
let leafIndex = 0; | ||
this.keys.forEach((_key)=>{ | ||
if(value<=_key) return; | ||
if(value<_key) return; | ||
leafIndex++; | ||
}); | ||
|
||
const leaf = this.childrens[leafIndex]; | ||
await leaf.remove(value); | ||
await leaf.remove(remCmd); | ||
}; | ||
module.exports = remove; |
Oops, something went wrong.