Skip to content

Instantly share code, notes, and snippets.

@makersm
Last active January 13, 2018 23:28
Show Gist options
  • Save makersm/4cf4fd9fff71ec3ec12126fda619db75 to your computer and use it in GitHub Desktop.
Save makersm/4cf4fd9fff71ec3ec12126fda619db75 to your computer and use it in GitHub Desktop.
234tree
class TtFTree {
constructor() {
this._children = []
this._key = []
}
insert(node, prenode, key) {
if(_key.length == 3) {
_middleUp(node, prenode)
}
index = node._compareAndGetIndex(key)
if(node._key.length < 3)
node._insert(key, index)
else
selectedChild = children[index]
insert(selectedChild, this, key)
}
delete(key) {
// http://www.mathcs.emory.edu/~cheung/Courses/323/Syllabus/Trees/2,4-delete.html
// https://m.blog.naver.com/PostView.nhn?blogId=zkd1750&logNo=90186082994&proxyReferer=https%3A%2F%2Fwww.google.co.kr%2F
// http://egloos.zum.com/itsmywar/v/837217
// 지우기
}
this._insert(key, index){
//insert
}
this._compareAndGetIndex(key) {
for(let e in _key) {
if(key < _key[e])
return e
}
return 3
}
this._middleUp(node, prenode) {
if(prenode === null)
prenode = new TtFTree()
index = node._findMyIndex(prenode)
prenode._children[index] = node._key[2]
node._key[2] = null
prenode._insert(node._key[1], prenode._compareAndGetIndex(key))
}
this._findMyIndex(prenode) {
for(e in prenode._children)
if(prenode._children[e] == this)
return e
return 3
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment