Commits

Serge Zaitsev  committed 2547d48

using delta compression to store postings (fileids)

  • Participants
  • Parent commits bb568e6

Comments (0)

Files changed (1)

 
 		size_t k;
 		int offset = index->entries[j].offset;
+		maxint_t previd = 0;
 		for (k = 0; k < index->entries[j].count; k++) {
-			maxint_t fileid;
+			maxint_t fileid = 0;
 			int n = varint_decode((index->fileids + offset), 5, &fileid);
 			if (n < 0) {
 				//
 			}
+			fileid += previd;
 			offset += n;
 			found[fileid] = 1;
+			previd = fileid;
 		}
 		for (k = 0; k < index->files_count; k++) {
 			if (found[k] == 0) {
 	} else if (p1->trigram < p2->trigram) {
 		return -1;
 	} else {
-		/* TODO: check filno */
-		return 0;
+		if (p1->fileno > p2->fileno) {
+			return 1;
+		} else if (p1->fileno < p2->fileno) {
+			return -1;
+		} else {
+			return 0;
+		}
 	}
 }
 
 	entry.trigram = (writer->postings[0].trigram);
 	entry.count = entry.offset = 0;
 
+	int prev_id = 0;
 	for (i = 0; i < writer->postings_count; i++) {
 		int id = writer->postings[i].fileno;
 		uint32_t t = writer->postings[i].trigram;
 
-		/* save file id (compressed), increase size */
-		int n;
-		uint8_t buf[5];
-		n = varint_encode(buf, 5, id);
-		fwrite(buf, n, 1, f);
-
 		if (t != entry.trigram) {
 			unsigned int j = entries_count;
 
 			entry.trigram = t;
 			entry.count = 0;
 			entry.offset = fileids_size;
+			prev_id = 0; /* reset previous id on new trigram */
 		}
+		/* save file id (compressed), increase size */
+		int n;
+		uint8_t buf[5];
+		n = varint_encode(buf, 5, id - prev_id);
+		fwrite(buf, n, 1, f);
+		prev_id = id;
 		fileids_size += n;
 		entry.count++;
 	}