diff src/lib-index/mail-index.c @ 8146:70b53e9b232e HEAD

Rewrote thread indexing code. It's a lot simpler and takes less disk space. We no longer try to keep a hash table and the entire thread tree stored on disk. Instead we keep a simple Message-ID string (actually just "uid, ref#" pointer) -> unique index number mapping on disk, read it to memory and use it to build the thread tree. After the initial build the thread tree is still updated incrementally.
author Timo Sirainen <tss@iki.fi>
date Mon, 01 Sep 2008 15:17:00 +0300
parents 8e206e25a142
children 545cb188f7ab
line wrap: on
line diff
--- a/src/lib-index/mail-index.c	Mon Sep 01 15:11:54 2008 +0300
+++ b/src/lib-index/mail-index.c	Mon Sep 01 15:17:00 2008 +0300
@@ -690,3 +690,50 @@
 		 ((offset & 0x7f000000) >> 24)) << 2;
 }
 #endif
+
+void mail_index_pack_num(uint8_t **p, uint32_t num)
+{
+	/* number continues as long as the highest bit is set */
+	while (num >= 0x80) {
+		**p = (num & 0x7f) | 0x80;
+		*p += 1;
+		num >>= 7;
+	}
+
+	**p = num;
+	*p += 1;
+}
+
+int mail_index_unpack_num(const uint8_t **p, const uint8_t *end,
+			  uint32_t *num_r)
+{
+	const uint8_t *c = *p;
+	uint32_t value = 0;
+	unsigned int bits = 0;
+
+	for (;;) {
+		if (unlikely(c == end)) {
+			/* we should never see EOF */
+			*num_r = 0;
+			return -1;
+		}
+
+		value |= (*c & 0x7f) << bits;
+		if (*c < 0x80)
+			break;
+
+		bits += 7;
+		c++;
+	}
+
+	if (unlikely(bits >= 32)) {
+		/* broken input */
+		*p = end;
+		*num_r = 0;
+		return -1;
+	}
+
+	*p = c + 1;
+	*num_r = value;
+	return 0;
+}