NODO_B_PLUS *b_plus_crearnodo(INDEXSPECS *idx);
int b_plus_destruir_nodo(NODO_B_PLUS *nodo);
/*int b_plus_insertar_clave(INDEXSPECS *idx, INDEX_DAT *query);*/
-int b_plus_split_child(INDEXSPECS *idx, NODO_B_PLUS *parent, int ithchild, NODO_B_PLUS *fullnode);
+int b_plus_split_child(INDEXSPECS *idx, int numparent, NODO_B_PLUS *parent, int ithchild, NODO_B_PLUS *fullnode);
int b_plus_insert_nonfull(INDEXSPECS *idx, NODO_B_PLUS *nodo, int num_nodo, INDEX_DAT *query);
int b_plus_insertar(INDEXSPECS *idx, INDEX_DAT *query);
int b_plus_get_num_nodo(INDEXSPECS *idx);
int b_plus_insertar_clave(INDEXSPECS *idx, INDEX_DAT *query)
{
NODO_B_PLUS *curnode, *padre;
- int i,j, prox_nodo;
+ int i,j, prox_nodo = 0;
+
/* Comienzo leyendo la raiz, entry point de toda funcion */
curnode = b_plus_leer_nodo(idx,0);
if (curnode == NULL) return -1;
free(curnode->hijos);
curnode->claves = claves_aux;
curnode->hijos = hijos_aux;
+ printf ("Prox Nodo es: %i\n",prox_nodo);
b_plus_grabar_nodo(idx, curnode, prox_nodo);
b_plus_destruir_nodo(curnode);
}
fp = fopen(idx->filename, "r+");
if (fp == NULL) return -1;
- fseek(fp,num_node*sizeof(NODO_B_PLUS),SEEK_SET);
+ fseek(fp,num_node*(SIZE_B_PLUS_HEADER+idx->size_claves+idx->size_hijos),SEEK_SET);
fwrite(nodo,SIZE_B_PLUS_HEADER,1,fp);
fwrite(nodo->claves,idx->size_claves,1,fp);
fwrite(nodo->hijos,idx->size_hijos,1,fp);
return 0;
}
-int b_plus_split_child(INDEXSPECS *idx, NODO_B_PLUS *parent, int ithchild, NODO_B_PLUS *fullnode)
+int b_plus_split_child(INDEXSPECS *idx, int numparent, NODO_B_PLUS *parent, int ithchild, NODO_B_PLUS *fullnode)
{
/* locals */
int minclaves = ceil(idx->size_hijos/sizeof(int)/2)-1;
for (j = parent->cant_claves-1; j >= ithchild; --j)
parent->claves[j+1] = parent->claves[j];
parent->claves[ithchild] = fullnode->claves[minclaves];
+ parent->cant_claves++;
+
+ /* Grabo los nodos en disco */
+ b_plus_grabar_nodo(idx,fullnode,parent->hijos[ithchild]);
+ b_plus_grabar_nodo(idx,brother,numbrother);
+ b_plus_grabar_nodo(idx,parent,numparent);
return 0;
}
int i, num_nodo_hijo;
NODO_B_PLUS *hijo;
- i = nodo->cant_claves;
+ i = nodo->cant_claves-1;
if ( nodo->nivel == 0 ){
- while ( i >= 1 && query->clave.i_clave < nodo->claves[i] ){
+ while ( i >= 0 && query->clave.i_clave < nodo->claves[i] ){
nodo->claves[i+1] = nodo->claves[i];
+ nodo->hijos[i+1] = nodo->hijos[i];
i--;
}
nodo->claves[i+1] = query->clave.i_clave;
+ nodo->hijos[i+1] = query->num_bloque;
nodo->cant_claves++;
- b_plus_destruir_nodo(nodo);
b_plus_grabar_nodo(idx, nodo, num_nodo);
+ b_plus_destruir_nodo(nodo);
+ printf("Pero men yo grabee..\n");
} else {
- while ( i >= 1 && query->clave.i_clave < nodo->claves[i] )
+ while ( i >= 0 && query->clave.i_clave < nodo->claves[i] )
i--;
i++;
- num_nodo_hijo = nodo->hijos[i-1];
+ num_nodo_hijo = nodo->hijos[i];
hijo = b_plus_leer_nodo(idx, num_nodo_hijo);
if ( hijo->cant_claves == idx->size_claves/sizeof(int) ) {
- b_plus_split_child(idx, nodo, i, hijo);
+ b_plus_split_child(idx, num_nodo, nodo, i, hijo);
if ( query->clave.i_clave > nodo->claves[i] )
i++;
}
- b_plus_insert_nonfull(idx, hijo, num_nodo_hijo, query);
+ b_plus_destruir_nodo(hijo);
+ hijo = b_plus_leer_nodo(idx, nodo->hijos[i]);
+ b_plus_insert_nonfull(idx, hijo, nodo->hijos[i], query);
+ b_plus_destruir_nodo(hijo);
}
- b_plus_destruir_nodo(hijo);
- return 0;
+
+ return 0;
}
int b_plus_insertar(INDEXSPECS *idx, INDEX_DAT *query)
new_root->hijos[0] = b_plus_get_num_nodo(idx);
b_plus_grabar_nodo(idx, raiz, new_root->hijos[0]);
b_plus_grabar_nodo(idx, new_root, 0);
- b_plus_split_child(idx, new_root, 1, raiz);
+ b_plus_split_child(idx, 0, new_root, 0, raiz);
b_plus_insert_nonfull(idx, new_root, 0, query);
- } else b_plus_insert_nonfull(idx, raiz, 0, query);
+ } else
+ {
+ printf ("Entre maaaaaallll\n");
+ b_plus_insert_nonfull(idx, raiz, 0, query);
+ }
return 0;
}
FILE *fp;
int num;
- fp = fopen(idx->filename, "r+");
+ fp = fopen(idx->filename, "ab");
if (fp == NULL) return -1;
- num = ftell(fp)/sizeof(NODO_B_PLUS);
+ num = ftell(fp)/(SIZE_B_PLUS_HEADER+idx->size_claves+idx->size_hijos);
+ printf("Num Nodo Nuevo: %i\n",num);
fclose(fp);
return num;
}