about summary refs log tree commit diff
path: root/src/engine/snapshot.h
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-07-13 13:40:04 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-07-13 13:40:04 +0000
commit125d04e51f4e444a38cf038d3ea095d92d3c6dbb (patch)
tree2288bbe4b923ab4d695e9f852c177a12f74ea799 /src/engine/snapshot.h
parent7be0ae1b2929a3c5dfedf542bce886deefa0f862 (diff)
downloadzcatch-125d04e51f4e444a38cf038d3ea095d92d3c6dbb.tar.gz
zcatch-125d04e51f4e444a38cf038d3ea095d92d3c6dbb.zip
large rewrite and code cleanup
Diffstat (limited to 'src/engine/snapshot.h')
-rw-r--r--src/engine/snapshot.h40
1 files changed, 34 insertions, 6 deletions
diff --git a/src/engine/snapshot.h b/src/engine/snapshot.h
index 9d803486..9af94a3b 100644
--- a/src/engine/snapshot.h
+++ b/src/engine/snapshot.h
@@ -1,19 +1,47 @@
+#ifndef FILE_SNAPSHOT_H
+#define FILE_SNAPSHOT_H
 
 struct snapshot
 {
+	int data_size;
 	int num_items;
-	int offsets[1];
-
+	
 	struct item
 	{
 		int type_and_id;
-		char data[1];
-		
+
+		int *data() { return (int *)(this+1); }		
 		int type() { return type_and_id>>16; }
 		int id() { return type_and_id&(0xffff); }
+		int key() { return type_and_id; }
 	};
+
+	int *offsets() { return (int *)(this+1); }		
+	char *data_start() { return (char *)(offsets() + num_items); }
+	item *get_item(int index) { return (item *)(data_start() + offsets()[index]); };
 	
-	char *data_start() { return (char *)&offsets[num_items]; }
-	item *get_item(int index) { return (item *)(data_start() + offsets[index]); };
+	// returns the number of ints in the item data
+	int get_item_datasize(int index)
+	{
+		if(index == num_items-1)
+			return (data_size - offsets()[index]) - sizeof(item);
+		return (offsets()[index+1] - offsets()[index]) - sizeof(item);
+	}
+	
+	int get_item_index(int key)
+	{
+		// TODO: this should not be a linear search. very bad
+		for(int i = 0; i < num_items; i++)
+		{
+			if(get_item(i)->key() == key)
+				return i;
+		}
+		return -1;
+	}
 };
 
+void *snapshot_empty_delta();
+int snapshot_create_delta(snapshot *from, snapshot *to, void *data);
+int snapshot_unpack_delta(snapshot *from, snapshot *to, void *data, int data_size);
+
+#endif // FILE_SNAPSHOT_H