1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
#include <iostream>
#include <ostream>
#include "bptree.h"
#include "bptree2.h"
using namespace std;
void bptree::newintcont()
{
/* i want to create new internalcontianer and make the head parameter point to it ,, the last head will be pointed by incont->keys[cur_key] ...........................
incont->keys[cur_key] = (long ) temp;
*/
cur_key=0;
cur_in_slot=0;
incont = new internal_container(max_key, max_slot);
long *temp;
temp=NULL;
cout<<endl<<"incont "<<(long)&incont <<" head "<<head<<" temp "<<temp<<endl;
temp= head; // save the last address of head
cout<<"head "<<head<<" temp "<<temp<<endl;
head=(long * )&incont; // give the head new address
incont->keys[cur_key] = (long ) temp; // save the temp value (which is the old address) in the key.
cout<<"head "<<head<<" temp "<<temp<<" incont->keys[cur_key] "<<incont->keys[cur_key]<<endl;
cur_key++;
};
void bptree::newleafcont()
{
leafcont= new leaf_container(max_slot);
cout<<"\n newleafcontainer at "<<(long )leafcont<<endl;
incont->keys[cur_key] = (long )leafcont;
cur_leaf_slot=0;
cur_key++;
};
void bptree::insert_internal(int st, int et)
{
incont->in_node[cur_in_slot].st=st;
incont->in_node[cur_in_slot].et=et;
cur_in_slot++;
};
void bptree::insert_leaf(string mob_id, int st, int et)
{cout<<endl<<" insert at "<<st<<" second ";
leafcont->leaf_node[cur_leaf_slot].st=st;
leafcont->leaf_node[cur_leaf_slot].et=et;
leafcont->leaf_node[cur_leaf_slot].mob_id=mob_id;
cur_leaf_slot++;
};
void bptree::insert(string mob_id, int st, int et)
{
if(head==NULL)
{
insert_internal(st, et);
insert_leaf(mob_id, st, et);
incont->keys[cur_key] = (long )&leafcont;
head=(long * )&incont;
cout<<"head "<<head<<endl;
cur_key++;
}//end if
else//head!=NULL
{
if(cur_leaf_slot<max_slot) // LEAF
{
insert_leaf(mob_id, st, et);
if (incont->in_node[cur_in_slot-1].et<et)
incont->in_node[cur_in_slot-1].et=et;
}//end if(cur_leaf_slot<max_slot)
else
if(cur_key<max_key)
{
//cout<<" new leaf container l69 ";
newleafcont();
insert_internal(st, et);
insert_leaf(mob_id, st, et);
}//end (cur_key<max_key)
else
{
cout<<"\n insert new internal container"<<endl;
newintcont();
newleafcont();
insert_internal(st, et);
insert_leaf(mob_id, st, et);
}//end last else
}//end head !=null
}; //end insert
void bptree::print()
{
cout<<"\n print"<<endl;
cout<<endl<<"incont->keys[o] "<<incont->keys[0]<<" (long )&leafcont "<< (long )&leafcont;
cout<<endl<<" incont->keys[1] "<<incont->keys[1]<<" (long )&leafcont"<< (long )&leafcont;
cout<<endl<<"incont->keys[2] "<<incont->keys[2]<<" (long )&leafcont "<< (long )&leafcont;
cout<<endl<<" incont->keys[3] "<<incont->keys[3]<<" (long )&leafcont"<< (long )&leafcont<<endl;
//for(int x=0; x<=cur_leaf_slot; x++)
// cout <<endl<<"x= "<<x<< " leafcont.leaf_node[x].st=st "<<leafcont.leaf_node[x].st<<" leafcont.leaf_node[x].et "<<leafcont.leaf_node[x].et<<" leafcont.leaf_node[x].mob_id "<<leafcont.leaf_node[x].mob_id<<endl;
}//end print
int main()
{
bptree tree(3,2);
tree.insert("m4", 1, 7);
tree.insert("m2", 2, 4);
tree.insert("m1", 3, 12);
tree.insert("m6", 4, 12);
tree.insert("m0", 5, 12);
tree.insert("m6", 6, 3);
tree.insert("m9", 7, 20);
tree.insert("m6", 8, 12);
tree.insert("m0", 9, 12);
tree.insert("m6", 10, 3);
/*tree.insert("m9",11, 20);
tree.insert("m6", 12, 12);
tree.insert("m0", 13, 12);
tree.insert("m6", 14, 3);
tree.insert("m9",15, 20);*/
//tree.print();
//delete *tree;
return 0;
}///end main
|