def_mem(Leaf)
{
- int value;
+ int seq;
array(Leaf);
};
{
Leaf leaf,root=NULL;
int newkey;
+ int seq=0;
+ int odd=1;
- for_ints(newkey, 8,1,-2,745,-32,-64,27,4 ) printf(" [%d]",i)
+ for_ints(newkey, 8,1,-2,745,-32,-64,27,4 )
{
+ printf("%d. [%d]\n",seq,newkey);
+
leaf=get_mem(Leaf);
+ leaf->seq=seq++;
//init
leaf->__next=NULL;
//grow tree
{
- void *prev=NULL, *newleaf=leaf;
- //find where to store
- for(leaf=root; leaf && leaf->__key<=newkey ; leaf=leaf->__next)
+ void *prev=NULL, *newleaf=leaf;
+ //find where to store
+ for(leaf=root;leaf && leaf->__key<=newkey;leaf=leaf->__next)
+ {
+ prev=leaf;
+ if(leaf->__seek && leaf->__seek->key<=newkey)
{
- prev=leaf;
- if(leaf->__seek && leaf->__seek->key<=newkey) leaf=leaf->__seek;
- }
- //store new node
- leaf=newleaf;
- if(prev)
- {
- leaf->__next=prev->__next->__next;
- prev->__next=leaf;
- }
- else
- leaf->__next=root;
+ leaf=leaf->__seek;
+
+ }
+ //store new node
+ leaf=newleaf;
+ if(prev)
+ {
+ leaf->__next=prev->__next->__next;
+ prev->__next=leaf;
+ }
+ else
+ leaf->__next=root;
+
+ //reindex B+ tree
+ for(leaf=root;leaf->__next;leaf=leaf->__next)
+ {
//auto seek
- if(leaf->__next->__next;)
+ if(!leaf->__seek)
leaf->__seek=leaf->__next->__next;
-
- //reindex B+ tree
- for(leaf=root; leaf->__next ; leaf=leaf->__next)
+
+ if(leaf->__key<=newkey)
{
- if (leaf->__seek)
+ if(leaf->__seek && leaf->__seek->__key>newkey)
+ leaf->__seek=leaf->__seek->__next;
+ }
+ else
+ {
+ if(odd && leaf->__seek)
+ {
+ leaf->__seek==leaf->__seek->__next;
+ odd=1-odd;
+ }
+ else
{
- if (leaf->__key <= newkey)
- leaf->__seek=leaf->__seek->__next;
+ leaf->__seek=leaf->__next->__seek;
+ leaf->__next->__seek=NULL;
}
- else
- leaf->__seek=leaf->__next->__seek;
- }
+ }
+ }
}
- }
+ }
+
+ for_each(leaf,root)
+ {
+ printf("%d. [%d]\n",leaf->seq,leaf->__key);
+ }
}