]> git.llucax.com Git - z.facultad/75.52/treemulator.git/commitdiff
Agrego algunas funciones iniciales
authorRicardo Markiewicz <rmarkie@fi.uba.ar>
Wed, 7 Sep 2005 01:23:32 +0000 (01:23 +0000)
committerRicardo Markiewicz <rmarkie@fi.uba.ar>
Wed, 7 Sep 2005 01:23:32 +0000 (01:23 +0000)
Son bosquejos e ideas plasmadas en codigo, no esperen que anden :)

src/btree.c [new file with mode: 0644]

diff --git a/src/btree.c b/src/btree.c
new file mode 100644 (file)
index 0000000..e6f09e1
--- /dev/null
@@ -0,0 +1,57 @@
+
+#include "btree.h"
+
+static void write_tree_header (BTree *tree);
+static void write_block (BTree *tree, uchar *block, uint num);
+
+BTree *btree_create (const char *filename, unsigned int block_size)
+{
+       BTree *tree;
+       uchar *node;
+
+       tree = malloc (sizeof(BTree));
+       if (!tree)
+               return NULL;
+
+       tree->fp = fopen (filename, "wb");
+       if (!tree->fp) {
+               free (tree);
+               return NULL;
+       }
+
+       /* Nombre de archivo */
+       tree->filename = malloc(sizeof(char)+1);
+       strcpy (tree->filename, filename);
+       
+       /* Inicializo el header */
+       tree->header.block_size = block_size;
+       write_tree_header (tree);
+
+       /* Creo el primer bloque vacio */
+       node = calloc (1, block_size);
+       write_block (tree, node, 0);
+
+       return tree;
+}
+
+int btree_close (BTree *tree)
+{
+       fclose (tree->fp);
+       free (tree->filename);
+       free (tree);
+
+       return 0;
+}
+
+static void write_tree_header (BTree *tree)
+{
+       fseek (tree->fp, 0L, SEEK_SET);
+       fwrite (&tree->header, 1, sizeof (BTreeHeader), tree->fp);
+}
+
+static void write_block (BTree *tree, uchar *block, uint num)
+{
+       fseek (tree->fp, num*tree->header.block_size + sizeof (BTreeHeader), SEEK_SET);
+       fwrite (block, 1, tree->header.block_size, tree->fp);
+}
+