Update of /cvsroot/simplemail/simplemail
In directory sfp-cvs-1.v30.ch3.sourceforge.com:/tmp/cvs-serv24932
Modified Files:
index_external.c
Log Message:
Added an offset file that will keep track of the offsets and dids.
Index: index_external.c
===================================================================
RCS file: /cvsroot/simplemail/simplemail/index_external.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- index_external.c 19 Jan 2014 18:56:09 -0000 1.52
+++ index_external.c 21 Feb 2014 06:31:22 -0000 1.53
@@ -86,6 +86,7 @@
int number_of_blocks;
FILE *string_file;
+ FILE *offset_file;
FILE *index_file;
/** Identifies the block for the root node. TODO: Make this persistent */
@@ -795,6 +796,7 @@
idx = (struct index_external*)index;
+ if (idx->offset_file) fclose(idx->offset_file);
if (idx->string_file) fclose(idx->string_file);
if (idx->index_file) fclose(idx->index_file);
if (idx->tmp3) bnode_free(idx, idx->tmp3);
@@ -833,6 +835,10 @@
if (!(idx->string_file = fopen(buf, "w+b")))
goto bailout;
+ sm_snprintf(buf, sizeof(buf), "%s.offsets", filename);
+ if (!(idx->offset_file = fopen(buf, "w+b")))
+ goto bailout;
+
idx->tmp->leaf = 1;
idx->root_node = bnode_add_block(idx, idx->tmp);
idx->max_substring_len = 32;
@@ -868,6 +874,33 @@
return 1;
}
+/**
+ * Structure representing an offset/did pair.
+ */
+struct offset_entry
+{
+ int offset;
+ int did;
+};
+
+/**
+ * Appends the given offset did pair to the offsets file.
+ */
+static int index_external_append_offset_did_pair(struct index_external *idx, int offset, int did)
+{
+ struct offset_entry entry;
+
+ if (fseek(idx->offset_file, 0, SEEK_END) != 0)
+ return 0;
+
+ entry.offset = offset;
+ entry.did = did;
+
+ if (fwrite(&entry, 1, sizeof(entry), idx->offset_file) != sizeof(entry))
+ return 0;
+ return 1;
+}
+
int index_external_put_document(struct index *index, int did, const char *text)
{
struct index_external *idx;
@@ -880,6 +913,9 @@
if (!index_external_append_string(idx, text, &offset))
return 0;
+ if (!index_external_append_offset_did_pair(idx, offset, did))
+ return 0;
+
for (i=0; i < l; i++)
{
if (!(bnode_insert_string((struct index_external*)index, did, offset + i, text + i)))
|