From 113597e3c369b18fa4e73a0b9744398a0e9e0a79 Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Mon, 12 Sep 2005 18:45:52 +0000 Subject: [PATCH] Lectura de claves desde un nodo a memoria. La idea es que luego de cargar un bloque feo y molesto de trabajar se carga una std::list con todas las claves. Para agregar o borrar se lo hace en la lista y luego se llama a WriteKeys (todavia no se implemento) para volver a poner las claves en el bloque en modo "binario". --- src/btree.cpp | 27 +++++++++++++++++++++++++-- src/btree.h | 8 ++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/btree.cpp b/src/btree.cpp index a285392..d1fbab3 100644 --- a/src/btree.cpp +++ b/src/btree.cpp @@ -48,13 +48,18 @@ void BTree::write_block (uchar *block, uint num) fwrite (block, 1, header.block_size, fp); } -void BTree::AddKey (Clave &k) +void BTree::AddKey (const Clave &k) { + std::list node_keys; + /* Leo el nodo raiz para empezar a agregar */ uchar *root = ReadBlock (0); BTreeNodeHeader root_header; ReadNodoHeader (root, &root_header); + node_keys = ReadKeys (root, root_header); + std::cout << node_keys.size () << std::endl; + if (root_header.free_space >= k.Size ()) { std::cout << "Hay lugar para meter la clave" << std::endl; } else { @@ -64,7 +69,7 @@ void BTree::AddKey (Clave &k) delete [] root; } -void BTree::DelKey (Clave &k) {} +void BTree::DelKey (const Clave &k) {} void BTree::ReadNodoHeader (uchar *node, BTreeNodeHeader *header) { @@ -86,3 +91,21 @@ uchar *BTree::ReadBlock (uint num) return out; } +std::list BTree::ReadKeys (uchar *node, BTreeNodeHeader &node_header) +{ + std::list keys; + node += sizeof (BTreeNodeHeader); + + for (uint i=0; iSize (); + keys.push_back (k); + } + + return keys; +} + diff --git a/src/btree.h b/src/btree.h index 081c436..95180b0 100644 --- a/src/btree.h +++ b/src/btree.h @@ -46,8 +46,10 @@ #include #include +#include #include "common.h" #include "clave.h" +#include "clave_fija.h" /* alias para codear menos :) */ @@ -86,8 +88,8 @@ class BTree { BTree (const std::string &filename, unsigned int block_size, bool create_new_file = false); ~BTree (); - void AddKey (Clave &k); - void DelKey (Clave &k); + void AddKey (const Clave &k); + void DelKey (const Clave &k); private: void write_tree_header (); @@ -98,6 +100,8 @@ class BTree { void ReadNodoHeader (uchar *node, BTreeNodeHeader *header); void WriteNodoHeader (uchar *node, BTreeNodeHeader *header); + std::list ReadKeys (uchar *node, BTreeNodeHeader &node_header); + std::string filename; BTreeFileHeader header; -- 2.43.0